java - Double cast for Double smaller than zero -
double out = othertypes.somemethod(c, c2); assertequals((double)-1.0d, out);
i error "double cannot resolved" (the double in assertequals), there way hack around except extracting variable?
is bug in java or usefull feature wont fix?
one important note: because of way floating point numbers work, should never compare 2 doubles (or floating point numbers spoken) equality directly, compare if difference within specified delta: abs(double1 - double2) < delta
.
junit has assertequals(double expected, double actual, double delta)
method that. said, should use
assertequals(-1.0d, (double) out, 0.000001d)
in code.
you can find more on tricks , traps of floating point number in example in 1 of brian goetz's articles: "where's point?"
Comments
Post a Comment