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

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -