I need to make a simple counter to increase a led light with every button click and then restart counter to 0.
The led works ok but when the counter node reaches 1, the equal node never returns TRUE
count node parameters:
STEP = 0.1
On equal node i’ve tested with 1, 1.0 and with 1.00 and never returns TRUE, if a change equal node for a greater node with value = 0.9 it works
How equal node works with decimal number ?
Huh, I believe these are IEEE754 glitches when 0.1 + 0.2 ≠ 0.3. It can happen you actually get 0.9999999999 and not 1.0.
In such scenarios as yours better use
greater instead of
Yes i supose that. But will be any kind of solution in future ? Basically if XOD will be used to teach students to program their robots, boards … this could be a problem.
They will see a watch node showing 1.00, and the equal not working with 1.00 too
Shouldn’t the students learn that the computer math is not perfect?
It will be quite hard to do anything with
equal which will not lead to ambiguities in other scenarios. I’m thinking about a node like
almost-equal which will take a tolerance (with a sane default) as its input. Will it solve the problem, what do you think?
haha yes, but they could think. " If a computer math is not perfect … "
I don’t see almost-equal node so friendly
Other solution, would be create a equal (decimal) node, and compare inputs once converted to string
Or in the same actual equal node, detect if second input is a decimal ( example: 1.00 ) to convert de first input to string like Wath node does
Then a counter doing 0.1 + 0.1 + 0.1 could be compared to 0.3
Every XOD pulse uses numbers in range 0.00 to 1.00 but the XOD developer has the last words of course
That’s a very dangerous assumption. The system can’t be sure where the arguments came from and what tolerance is acceptable. Such algorithm will work in trivial cases but it will break many other cases.
Trying to find a balance between the reality of floating point and accessibility for a student’s mind… Perhaps, dropping the current
equal for numbers in favor of one with tolerance = 1% (0.01) is not the worst idea.