java - Comparing two fixed doubles with . Is there really an issue? -



java - Comparing two fixed doubles with <, =, >. Is there really an issue? -

i'd check if double smaller, equal to, or bigger double. though read lot floats , doubles not beingness exactly comparable because of how computer calculates @ binary level, using simple binary operators works charm far. tested dozens of different numbers , hasn't failed me 1 time far.

so there problem comparing them in case? , if there - why can't locate , how prepare it?

edit: i'm aware 0.1 + 0.2 != 0.3 if decide compare them. thing - want compare 2 fixed doubles. won't have compare 0.1 + 0.2 , 0.3. i'd have compare 0.3 , 0.3 @ best. or 0.4 , 0.3. that. need utilize bigdecimal, or epsilon, or whatever that?

doubles discrete representation of decimal numbers. means not numbers can represented double.

for illustration double can't represent big numbers accurately, in case "rounded" closest available double. see example:

public static void main(string[] args) { double d1 = 1e50; double d2 = d1 + 1; system.out.println(d2 > d1); //false system.out.println(d2 == d1); //true }

java numbers compare theory point

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -