package dspl.intermediate.variable.primitive;

/**
 * Complex is the primitive object wrapper for Complex #'s 
 * In DSPL, all other primitive atomic objects (float, int, byte, etc) already have 
 * equivalent java classes that can be substitued in the Variable's valueOf field.
 * The one exception is the complex type, thus the raison-d'etre for the Complex class. 
 * @author David
 *
 */
public class Complex {
	/**
	 * The real part of the complex number
	 */
	public float real;
	
	/**
	 * The imaginary part of the complex number
	 */
	public float imag; 
	
	/**
	 * Returns a string representation of the complex number in the form of 
	 * "a + bi" or "a - bi" depending on the sign of imag
	 */
	public String toString() { 
		String sign;
		sign = (imag<0) ? " " : "+"; //if negative, don't show sign as it will appear when printing the float 
		return new String("{" + real + " " + sign + " " + imag +"i"); 
	}
	
	/**
	 * 
	 * @param real Real part of the complex #
	 * @param imag Imag part of the complex #
	 */
	public Complex(float real, float imag) { 
		this.real = real;
		this.imag = imag; 
	}
	
	/**
	 * Constructor used to create based on string representationso of
	 * the imaginary and real parts of the complex number. 
	 * @param real
	 * @param imag
	 */
	public Complex(String real, String imag) { 
		this.real = Float.parseFloat(real); 
		this.imag = Float.parseFloat(imag); 
	}
}
