# Long integer addition math error in expression tag

**URL:** <https://forum.inductiveautomation.com/t/long-integer-addition-math-error-in-expression-tag/40236>\
**Category:** Ignition\
**Tags:** scripting, ignition79\
**Created:** [November 3, 2020, 2:58pm UTC](https://forum.inductiveautomation.com/t/long-integer-addition-math-error-in-expression-tag/40236 "2020-11-03T14:58:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlindstrom](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mlindstrom/32/30000_2.png) [@mlindstrom](https://forum.inductiveautomation.com/u/mlindstrom)\
**Post date:** [November 3, 2020, 2:58pm UTC](https://forum.inductiveautomation.com/t/long-integer-addition-math-error-in-expression-tag/40236/1 "2020-11-03T14:58:55Z")

</div>

I’m making an expression tag with type `Long` and have either found a bug or am I missing something obvious. I’m running 7.9.13.

The strangeness is with the expression  
`toLong(255) + toLong(2)^toLong(8*6) * toLong(255)`  
produces the decimal integer  
`71776119061217536`  
which in binary is  
`11111111_00000000_00000000_00000000_00000000_00000001_00000000`

**… But shouldn’t it be the decimal integer `71776119061217535`, which in binary is**  
**`11111111_00000000_00000000_00000000_00000000_00000000_11111111`**

Doing the first part and second part separately do produce the expected result, but something is throwing it off by one when they go together. First, the expression  
`toLong(255)`  
produces the decimal integer  
`255`  
which in binary is  
`1111_1111`

Second, the expression  
`toLong(2)^toLong(8*6) * toLong(255)`  
produces the decimal integer  
`71776119061217280`  
which in binary is  
`11111111_00000000_00000000_00000000_00000000_00000000_00000000`

(Above is an example for clarity – this is the actual expression binding I am attempting to use, where FaultWordDevice is 8 unsigned bytes which I’m trying to map into a single tag of type Long)

```auto
(({[.]../FaultWordDevice/0} + 256) % 256)
+ 2^(8*1) * (({[.]../FaultWordDevice/1} + 256) % 256)
+ 2^(8*1) * (({[.]../FaultWordDevice/1} + 256) % 256)
+ 2^(8*2) * (({[.]../FaultWordDevice/2} + 256) % 256)
+ 2^(8*3) * (({[.]../FaultWordDevice/3} + 256) % 256)
+ 2^(8*4) * (({[.]../FaultWordDevice/4} + 256) % 256)
+ 2^(8*5) * (({[.]../FaultWordDevice/5} + 256) % 256)
+ 2^(8*5) * (({[.]../FaultWordDevice/5} + 256) % 256)
+ 2^(8*6) * (({[.]../FaultWordDevice/7} + 256) % 256)

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 3, 2020, 3:05pm UTC](https://forum.inductiveautomation.com/t/long-integer-addition-math-error-in-expression-tag/40236/2 "2020-11-03T15:05:46Z")

</div>

`toLong(255) + toLong(2)^toLong(8*6) * toLong(255)` ends up being converted to Double due to the exponent.

This would get the expected result:  
`toLong(255) + toLong(2^(8*6)) * toLong(255)`
