Floating point comparisons
-
Float storage is problematic because values are not always precisely correct. Equality comparisons are particularly problematic.
I reasoned the advantage of 3D printing is we have a good idea of how much precision distances are meaningful for. I've never had to consider anything below a micron (0.001 mm), so it seems like one could avoid floating point troubles by taking a float value and forcing a conversion to 10ths of microns, then rounding and converting back:
set var.x = floor(var.x*10000 + 0.5) / 10000
It seems like this would convert a distance stored as a float to an integer, preserving any meaningful precision, while removing any floating point error, but ...
The problem is that no integer division is available, as far as I know, nor is any shift-right operation. So I know of no way to get back to mm without going back to float.
I'm not sure if there's a rationale to simply ignore the problem - maybe that numbers in the range we normally deal with don't trigger this issue? I'm not sure how one could be sure of that. Under the right conditions, the resulting error could be a true vs. false difference.
I'd be interested in any thoughts on this classic computer problem as applied to Duet variables.