Long integer addition math error in expression tag

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)

(({[.]../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)

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)

1 Like