3 ms·
I'm not familiar with all the floating-point number gotchas, but would like to ask why an obvious solution is not used (or maybe it is?): convert both numbers t
by andreygrehov 4y ago
I'm not familiar with all the floating-point number gotchas, but would like to ask why an obvious solution is not used (or maybe it is?): convert both numbers to a string and compare the result? This might be a naive question, but still.
- Someone 4y agoConverting a IEEE float to a string is tricky, too, IMO more tricky. It would be a lot slower, too, and wouldn’t work. How do you define “compare the result”? The strings “0.0” and “-0.0” would have to be equal to each other, and the string “NaN” not equal to itself, “1000” larger than “0.999E3”, etc.
- constantcrying 4y agoIt is slow and doesn't really solve the problem. Representing the numbers in base 10 does not make it any clearer whether the numbers are equal.