# Equal node not working with decimal

**URL:** https://forum.xod.io/t/equal-node-not-working-with-decimal/870
**Category:** Uncategorized
**Created:** [June 19, 2018, 6:23am UTC](https://forum.xod.io/t/equal-node-not-working-with-decimal/870 "2018-06-19T06:23:00Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![enteropositivo](https://avatars.discourse-cdn.com/v4/letter/e/ad7895/32.png) [@enteropositivo](https://forum.xod.io/u/enteropositivo)
#### Post date: [June 19, 2018, 6:23am UTC](https://forum.xod.io/t/equal-node-not-working-with-decimal/870/1 "2018-06-19T06:23:00Z")

</div>

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 ?

![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/1X/8df0077fd44fcc21ba7037ce0751dbe987c82746.png)

---

<div class="post-metadata">

### Author: ![nkrkv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/nkrkv/32/8_2.png) [@nkrkv](https://forum.xod.io/u/nkrkv)
#### Post date: [June 19, 2018, 8:30am UTC](https://forum.xod.io/t/equal-node-not-working-with-decimal/870/2 "2018-06-19T08:30:53Z")

</div>

Huh, I believe these are [IEEE754 glitches](https://stackoverflow.com/questions/8503157/ieee-754-floating-point-arithmetic-rounding-error-in-c-sharp-and-javascript) 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 `equal`.

---

<div class="post-metadata">

### Author: ![enteropositivo](https://avatars.discourse-cdn.com/v4/letter/e/ad7895/32.png) [@enteropositivo](https://forum.xod.io/u/enteropositivo)
#### Post date: [June 19, 2018, 8:45am UTC](https://forum.xod.io/t/equal-node-not-working-with-decimal/870/3 "2018-06-19T08:45:13Z")

</div>

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

---

<div class="post-metadata">

### Author: ![nkrkv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/nkrkv/32/8_2.png) [@nkrkv](https://forum.xod.io/u/nkrkv)
#### Post date: [June 19, 2018, 8:49am UTC](https://forum.xod.io/t/equal-node-not-working-with-decimal/870/4 "2018-06-19T08:49:03Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![enteropositivo](https://avatars.discourse-cdn.com/v4/letter/e/ad7895/32.png) [@enteropositivo](https://forum.xod.io/u/enteropositivo)
#### Post date: [June 19, 2018, 9:11am UTC](https://forum.xod.io/t/equal-node-not-working-with-decimal/870/5 "2018-06-19T09:11:29Z")

</div>

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 😉

---

<div class="post-metadata">

### Author: ![nkrkv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/nkrkv/32/8_2.png) [@nkrkv](https://forum.xod.io/u/nkrkv)
#### Post date: [June 19, 2018, 9:44am UTC](https://forum.xod.io/t/equal-node-not-working-with-decimal/870/6 "2018-06-19T09:44:47Z")

</div>

> [@enteropositivo](#):
>
> 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

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.
