package ec.app.complexregression;

import org.apache.commons.math3.complex.Complex;

import ec.gp.GPData;

public class ComplexData extends GPData {
	public Complex x;

	@Override
	public void copyTo(GPData gpd) {
		((ComplexData) gpd).x = this.x;
	}

	public final static Complex fixInfinity(Complex x) {
		if (Double.isNaN(x.getReal()))
			x = new Complex(0, x.getImaginary());
		if (Double.isNaN(x.getImaginary()))
			x = new Complex(x.getReal(), 0);

		if (x.getReal() < -1E300 || x.getReal() > 1E308)
			x = new Complex(Math.signum(x.getReal()) * 1E300, x.getImaginary());
		if (x.getImaginary() < -1E300 || x.getImaginary() > 1E300)
			x = new Complex(x.getReal(), Math.signum(x.getImaginary()) * 1E300);

		return x;
	}
}
