FLOAT - seems like Squirrel does not conform to the IEEE-754 standard


#1

I came here from the Attract Mode website. AM is a multiplatform frontend for arcade/console emulators.
Themes in AM are constructed using Squirrel API.

The problem I’m having is that the following function does not produce a correct result:

print( 1080.0 * 0.025 + “\n” )
print( floor( 1080.0 * 0.025 ) + “\n” )
print( floor( 1080.0 / 40.0 ) + “\n” )

result:
27
26
27

expected result:
27
27
27

I went to the root of the problem and I found out that Squirrel do not store floats in a way IEEE-754 standard specifies.

print( format( “%.30f”, 0.025) )
yields:
0.024999998509883881
instead of:
0.02500000037252902984619140625

Could anyone confirm if it’s a widespread issue or problem with Squirrel implementation in Attract Mode.

The issue is described in more detail here:


#2

The imp is single-precision FP, not double-precision.

Squirrel can be compiled with either single precision or double precision FP. Possibly, “Attract mode” uses the same setup, and may have some bugs…

Doing this on the imp:

server.log(format("%.30f", 0.025));

Gives this output:

0.02500000037252902912