Fix two bugs with RGBASM fixed-point math (#1388)

- Fixed-point formulas are implemented using IEEE-754 floating-point
  internally, which could give infinity or NaN values whose conversion
  to fixed-point integer was platform-dependent.
- Formatting fixed-point $8000_0000 (INT32_MIN, -2147483648) was
  not putting the negative sign in front.
This commit is contained in:
Sylvie
2024-03-31 12:53:20 -04:00
committed by GitHub
parent 6b5248f15b
commit 9ab3446d1a
5 changed files with 36 additions and 12 deletions

View File

@@ -0,0 +1,8 @@
MACRO test
def v = \1
println "{#09x:v} = {#012o:v} = {#033b:v} = {u:v}U = {+d:v} = {+.16f:v}"
ENDM
test $7fff_ffff ; INT32_MAX
test $8000_0000 ; INT32_MIN
test $0000_0000 ; UINT32_MIN
test $ffff_ffff ; UINT32_MAX

View File

@@ -0,0 +1,4 @@
$7fffffff = &17777777777 = %01111111111111111111111111111111 = 2147483647U = +2147483647 = +32767.9999847412109375
$80000000 = &20000000000 = %10000000000000000000000000000000 = 2147483648U = -2147483648 = -32768.0000000000000000
$00000000 = &00000000000 = %00000000000000000000000000000000 = 0U = +0 = +0.0000000000000000
$ffffffff = &37777777777 = %11111111111111111111111111111111 = 4294967295U = -1 = -0.0000152587890625

View File

@@ -19,14 +19,18 @@ ENDM
assert DIV(5.0, 2.0) == 2.5
assert DIV(-5.0, 2.0) == -2.5
assert DIV(-5.0, 0.0) == $8000_0000
assert DIV(5.0, 0.0) == $7fff_ffff ; +inf => INT32_MAX
assert DIV(-5.0, 0.0) == $8000_0000 ; -inf => INT32_MIN
assert DIV(0.0, 0.0) == $0000_0000 ; nan => 0
assert MUL(10.0, 0.5) == 5.0
assert MUL(10.0, 0.0) == 0.0
assert FMOD(5.0, 2.0) == 1.0
assert FMOD(-5.0, 2.0) == -1.0
assert FMOD(-5.0, 0.0) == $8000_0000
assert FMOD(5.0, 0.0) == 0 ; nan
assert FMOD(-5.0, 0.0) == 0 ; nan
assert FMOD(0.0, 0.0) == 0 ; nan
assert POW(10.0, 2.0) == 100.0
assert POW(100.0, 0.5) == 10.0