Integer math using floats

Blitz3D Forums/Blitz3D Programming/Integer math using floats

Using floats for integers will give exact results if the integers are small enough.

There are 24 bits available in a float, so the biggest integer is %111111111111111111111111, which is 16777215.
The sign is stored separately, so -16777215 is also available.

Addition, subtraction and multiplication are also exact, provided the results fit into 24 bits.

Division will work if the division of integers is exact. For example 6.0/3.0 will be the exact value 2.0.