net.sourceforge.cilib.util.functions.Numerics Maven / Gradle / Ivy
/** __ __
* _____ _/ /_/ /_ Computational Intelligence Library (CIlib)
* / ___/ / / / __ \ (c) CIRG @ UP
* / /__/ / / / /_/ / http://cilib.net
* \___/_/_/_/_.___/
*/
package net.sourceforge.cilib.util.functions;
import fj.Equal;
import fj.F;
import fj.F2;
import net.sourceforge.cilib.type.types.Bit;
import net.sourceforge.cilib.type.types.Int;
import net.sourceforge.cilib.type.types.Numeric;
import net.sourceforge.cilib.type.types.Real;
public final class Numerics {
private Numerics() {}
public static F doubleValue() {
return new F() {
@Override
public Double f(N a) {
return a.doubleValue();
}
};
}
public static F booleanValue() {
return new F() {
@Override
public Boolean f(N a) {
return a.booleanValue();
}
};
}
public static F intValue() {
return new F() {
@Override
public Integer f(N a) {
return a.intValue();
}
};
}
public static F getRepresentation() {
return new F() {
@Override
public String f(N a) {
return a.getRepresentation();
}
};
}
public static F real() {
return new F() {
@Override
public Real f(N a) {
return Real.valueOf(a.doubleValue());
}
};
}
public static F integer() {
return new F() {
@Override
public Int f(N a) {
return Int.valueOf(a.intValue());
}
};
}
public static F bit() {
return new F() {
@Override
public Bit f(N a) {
return Bit.valueOf(a.doubleValue() == 0.0);
}
};
}
public static F numeric() {
return new F() {
@Override
public Numeric f(N a) {
return Real.valueOf(a.doubleValue());
}
};
}
public static F2 equalF() {
return new F2() {
@Override
public Boolean f(Numeric a, Numeric b) {
return a.equals(b);
}
};
}
public static Equal equal() {
return Equal.equal(equalF().curry());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy