Tuesday, December 20, 2005

New math functions in JDK6

I've been watching the releases of JDK6 closely and have noticed that the math facilities continue to mature. Following in the footsteps of java.lang.StrictMath in JDK5, I see that JDK6 adds more useful static methods (for each method, there are similar methods for floats):

double copySign(double magnitude, double sign)
Returns the first floating-point argument with the sign of the second floating-point argument.
int getExponent(double d)
Returns the unbiased exponent used in the representation of a double.
double nextAfter(double start, double direction)
Returns the floating-point number adjacent to the first argument in the direction of the second argument.
public static double nextUp(double d)
Returns the floating-point value adjacent to d in the direction of positive infinity.
double scalb(double d, int scaleFactor)
Return d × 2scaleFactor rounded as if performed by a single correctly rounded floating-point multiply to a member of the double value set.

The only drawback is that several common operations are still missing. I wish the JDK would provide the comprehensiveness of C's libm.

Post a Comment