Skip to content

Commit b9997eb

Browse files
IgnacioFDMArkshine
authored andcommitted
Fix a floatround bug (#376)
* Fix floatround overflow floatround would overflow for floats greater than 2^30 because internally it would double the number (therefore anything greater than 2^30 results in something greater than 2^31 which would cause overflow of course) floatround behaviour is left exactly identical otherwise (although I find it very weird and wrong to deliberately avoid banker's rounding, it would be a bad idea to change this behaviour due to compatibility) Remember to reassemble amxexecn and amxjitsn * Update the compiled object files
1 parent a53e790 commit b9997eb

File tree

8 files changed

+17
-21
lines changed

8 files changed

+17
-21
lines changed

amxmodx/JIT/amxexecn-darwin.o

-4.29 KB
Binary file not shown.

amxmodx/JIT/amxexecn.o

96 Bytes
Binary file not shown.

amxmodx/JIT/amxexecn.obj

-39 Bytes
Binary file not shown.

amxmodx/JIT/amxjitsn-darwin.o

-12.1 KB
Binary file not shown.

amxmodx/JIT/amxjitsn.o

176 Bytes
Binary file not shown.

amxmodx/JIT/amxjitsn.obj

50 Bytes
Binary file not shown.

amxmodx/amxexecn.asm

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,7 @@ OP_FLOAT_ROUND:
14801480
push 0
14811481
mov ebp,esp
14821482
fstcw [ebp]
1483-
mov eax,[ebp]
1483+
mov eax,[ebp]
14841484
push eax
14851485
;clear the top bits
14861486
xor ah,ah
@@ -1492,22 +1492,20 @@ OP_FLOAT_ROUND:
14921492
;set the bits
14931493
or ah,dl ;set bits 15,14 of FCW to rounding method
14941494
or ah,3 ;set precision to 64bit
1495-
mov [ebp], eax
1496-
fldcw [ebp]
1495+
14971496
;calculate
14981497
sub esp,4
14991498
fld dword [edi+ecx+4]
15001499
test edx,edx
1501-
jz .correct
1502-
jmp .skip_correct
1503-
.correct:
1504-
fadd st0
1500+
jnz .skip_correct
1501+
;nearest mode
1502+
;correct so as to AVOID bankers rounding
1503+
or ah, 4 ;set rounding mode to floor
15051504
fadd dword [g_round_nearest]
1506-
fistp dword [esp]
1507-
pop eax
1508-
sar eax,1
1509-
jmp .done
1505+
15101506
.skip_correct:
1507+
mov [ebp], eax
1508+
fldcw [ebp]
15111509
frndint
15121510
fistp dword [esp]
15131511
pop eax

amxmodx/amxjitsn.asm

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,22 +1979,20 @@ OP_FLOAT_ROUND:
19791979
;set the bits
19801980
or ah,dl ;set bits 15,14 of FCW to rounding method
19811981
or ah,3 ;set precision to 64bit
1982-
mov [ebp], eax
1983-
fldcw [ebp]
1982+
19841983
;calculate
19851984
sub esp,4
19861985
fld dword [esi+4]
19871986
test edx,edx
1988-
jz .correct
1989-
jmp .skip_correct
1990-
.correct:
1991-
fadd st0
1987+
jnz .skip_correct
1988+
;nearest mode
1989+
;correct so as to AVOID bankers rounding
1990+
or ah, 4 ;set rounding mode to floor
19921991
fadd dword [g_round_nearest]
1993-
fistp dword [esp]
1994-
pop eax
1995-
sar eax,1
1996-
jmp .done
1992+
19971993
.skip_correct:
1994+
mov [ebp], eax
1995+
fldcw [ebp]
19981996
frndint
19991997
fistp dword [esp]
20001998
pop eax

0 commit comments

Comments
 (0)