sfall-team/sfall

Interpreter: Subtracting negative int value from a float value produces unexpected result

phobos2077 opened this issue · 2 comments

display_msg(""+(0.2000 - (-1)));

This code prints "-4294967296.00000" but expected "-0.80000"

Seems like vanilla issue, error must be somewhere here:

0046A2C0 loc_46A2C0:                                  ; op_sub_+DC�j
0046A2C0            mov     eax, [esp+34h+var_20]
0046A2C4            xor     ebp, ebp
0046A2C6            mov     dword ptr [esp+34h+var_34], eax
0046A2C9            mov     dword ptr [esp+34h+var_34+4], ebp
0046A2CD            fild    [esp+34h+var_34]
0046A2D0            fsubr   [esp+34h+var_24]
0046A2D4
0046A2D4 loc_46A2D4:                                  ; op_sub_+E6�j
0046A2D4            fstp    [esp+34h+var_28]
0046A2D8            mov     ebx, [esp+34h+var_28]
0046A2DC            lea     edx, [ecx+24h]
0046A2DF            mov     eax, [ecx+1Ch]

var_20 is the second (integer) operand. Seems like it should convert integer to float but it does something like reinterpret_cast<float> instead.

Turns out on September 11, 2014 I fixed the same issue in op_div and op_mult (on SVN repo), but apparently missed op_sub. Surprising this had to wait 9 years to get fixed.