java - If double a=0.0, can I compare a*b==0 directly? -


i know double should not compared == operator directly, how if define initial value 0.0?eg:

double a=0.0; double b= . . . 

if not modified, a*b==0 true?

i know double should not compared == operator direct

that true if don't know how representation or rounding error have. classic example of not is

0.1 + 0.2 == 0.3 // false :( 

however, if use rounding

if (round4(0.1 + 0.2) == 0.3) // true 

from chronicle core's maths

public static double round4(double d) {     final double factor = 1e4;     return d > whole_number / factor || d < -whole_number / factor ? d :             (long) (d < 0 ? d * factor - 0.5 : d * factor + 0.5) / factor; } 

if not modified, a*b==0 true?

it finite numbers. infinity , nan nan , not equal anything.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -