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
This commit is contained in:
IgnacioFDM 2016-06-27 07:23:08 -03:00 committed by Vincent Herbet
parent a53e7905db
commit b9997eb628
8 changed files with 17 additions and 21 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1480,7 +1480,7 @@ OP_FLOAT_ROUND:
push 0
mov ebp,esp
fstcw [ebp]
mov eax,[ebp]
mov eax,[ebp]
push eax
;clear the top bits
xor ah,ah
@ -1492,22 +1492,20 @@ OP_FLOAT_ROUND:
;set the bits
or ah,dl ;set bits 15,14 of FCW to rounding method
or ah,3 ;set precision to 64bit
mov [ebp], eax
fldcw [ebp]
;calculate
sub esp,4
fld dword [edi+ecx+4]
test edx,edx
jz .correct
jmp .skip_correct
.correct:
fadd st0
jnz .skip_correct
;nearest mode
;correct so as to AVOID bankers rounding
or ah, 4 ;set rounding mode to floor
fadd dword [g_round_nearest]
fistp dword [esp]
pop eax
sar eax,1
jmp .done
.skip_correct:
mov [ebp], eax
fldcw [ebp]
frndint
fistp dword [esp]
pop eax

View File

@ -1979,22 +1979,20 @@ OP_FLOAT_ROUND:
;set the bits
or ah,dl ;set bits 15,14 of FCW to rounding method
or ah,3 ;set precision to 64bit
mov [ebp], eax
fldcw [ebp]
;calculate
sub esp,4
fld dword [esi+4]
test edx,edx
jz .correct
jmp .skip_correct
.correct:
fadd st0
jnz .skip_correct
;nearest mode
;correct so as to AVOID bankers rounding
or ah, 4 ;set rounding mode to floor
fadd dword [g_round_nearest]
fistp dword [esp]
pop eax
sar eax,1
jmp .done
.skip_correct:
mov [ebp], eax
fldcw [ebp]
frndint
fistp dword [esp]
pop eax