3 ms·
I remember when I ran into this the first time with my C++ code. It took me quite a while to understand what's going on but it was a good learning experience.
by maxxxxx 11y ago
I remember when I ran into this the first time with my C++ code. It took me quite a while to understand what's going on but it was a good learning experience.
I don't do graphics anymore so not much floating point needed but I am still not sure how to do floating point comparisons in a stable and efficient way.
- deleted 11y ago[deleted]
- noobermin 11y agoThis[0] is an example of how it's usually done. It might not be "efficient," as a == comparison perhaps, but it's more correct regardless. With FPs in computational stuff, there is usually an associated scale with a calculation, so you use that scale (rtol=0, atol=scale). Other times, it makes sense for something like abs(a-b)/(avg(abs(a),abs(b)). [0] http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.isclose.html http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/n...
- maxxxxx 11y agoAre there any built-in functions that do floating point comparisons with rounding? Calling abs many times seems incredibly inefficient.
- dbcurtis 11y agoif (abs(a-b) < FUZZ) { }