"less/greater or equal" comparison between a number and itself returns false

artydent shared this problem 6 months ago
New

Comparing a high number (2^27 seems to be the threshold) with itself in Algebra mode has weird results. "==" comparison returns true as expected, but "<=" and ">=" comparison return false.

My guess is that the "<=" implementation simply compares the difference with 0, but due to floating point issues, the difference is slightly above 0, thus the comparison returns false. (And the ">=" comparison just calls the "<=" comparison with swapped arguments.)

Regardless of general floating point issues, it's inconsistent for "==" to be true but "<=" and ">=" to be false.


Does Geogebra even has its own implementation of this at this level? I would have assumed that such comparisons are handled as they are by the Java engine, but as far as I am aware Java (and any other established programming or scripting language) has a more careful implementation where "<="and ">=" can't return false if "==" returns true.

Comments (2)

photo
1

I tried 2^27+5, it seems no problem.

photo
1

Interesting. I tried with my installed Geogebra 5 and also in the web browser, and the problem occurs for numbers >= 2^27 (all the ones I tried). So maybe it's system-dependent.

photo
© 2021 International GeoGebra Institute