7294
This commit is contained in:
parent
ba8ee517b7
commit
8766aa12cd
|
@ -10,77 +10,77 @@
|
|||
# = 0 | 000000000000000000000000 | 01111110
|
||||
# zero-pad mantissa exponent
|
||||
# = +1.000000 P -01
|
||||
fn test-print-float-normal {
|
||||
fn test-print-float-hex-normal {
|
||||
var screen-on-stack: screen
|
||||
var screen/esi: (addr screen) <- address screen-on-stack
|
||||
initialize-screen screen, 5, 0x20 # 32 columns should be more than enough
|
||||
# 0.5
|
||||
var half/xmm0: float <- rational 1, 2
|
||||
print-float screen, half
|
||||
check-screen-row screen, 1, "1.000000P-01 ", "F - test-print-float-normal 0.5"
|
||||
print-float-hex screen, half
|
||||
check-screen-row screen, 1, "1.000000P-01 ", "F - test-print-float-hex-normal 0.5"
|
||||
# 0.25
|
||||
clear-screen screen
|
||||
var quarter/xmm0: float <- rational 1, 4
|
||||
print-float screen, quarter
|
||||
check-screen-row screen, 1, "1.000000P-02 ", "F - test-print-float-normal 0.25"
|
||||
print-float-hex screen, quarter
|
||||
check-screen-row screen, 1, "1.000000P-02 ", "F - test-print-float-hex-normal 0.25"
|
||||
# 0.75
|
||||
clear-screen screen
|
||||
var three-quarters/xmm0: float <- rational 3, 4
|
||||
print-float screen, three-quarters
|
||||
check-screen-row screen, 1, "1.800000P-01 ", "F - test-print-float-normal 0.75"
|
||||
print-float-hex screen, three-quarters
|
||||
check-screen-row screen, 1, "1.800000P-01 ", "F - test-print-float-hex-normal 0.75"
|
||||
# 0.1
|
||||
clear-screen screen
|
||||
var tenth/xmm0: float <- rational 1, 0xa
|
||||
print-float screen, tenth
|
||||
check-screen-row screen, 1, "1.99999aP-04 ", "F - test-print-float-normal 0.1"
|
||||
print-float-hex screen, tenth
|
||||
check-screen-row screen, 1, "1.99999aP-04 ", "F - test-print-float-hex-normal 0.1"
|
||||
}
|
||||
|
||||
fn test-print-float-integer {
|
||||
fn test-print-float-hex-integer {
|
||||
var screen-on-stack: screen
|
||||
var screen/esi: (addr screen) <- address screen-on-stack
|
||||
initialize-screen screen, 5, 0x20 # 32 columns should be more than enough
|
||||
# 1
|
||||
var one-f/xmm0: float <- rational 1, 1
|
||||
print-float screen, one-f
|
||||
check-screen-row screen, 1, "1.000000P00 ", "F - test-print-float-integer 1"
|
||||
print-float-hex screen, one-f
|
||||
check-screen-row screen, 1, "1.000000P00 ", "F - test-print-float-hex-integer 1"
|
||||
# 2
|
||||
clear-screen screen
|
||||
var two-f/xmm0: float <- rational 2, 1
|
||||
print-float screen, two-f
|
||||
check-screen-row screen, 1, "1.000000P01 ", "F - test-print-float-integer 2"
|
||||
print-float-hex screen, two-f
|
||||
check-screen-row screen, 1, "1.000000P01 ", "F - test-print-float-hex-integer 2"
|
||||
# 10
|
||||
clear-screen screen
|
||||
var ten-f/xmm0: float <- rational 0xa, 1
|
||||
print-float screen, ten-f
|
||||
check-screen-row screen, 1, "1.400000P03 ", "F - test-print-float-integer 10"
|
||||
print-float-hex screen, ten-f
|
||||
check-screen-row screen, 1, "1.400000P03 ", "F - test-print-float-hex-integer 10"
|
||||
# -10
|
||||
clear-screen screen
|
||||
var minus-ten-f/xmm0: float <- rational -0xa, 1
|
||||
print-float screen, minus-ten-f
|
||||
check-screen-row screen, 1, "-1.400000P03 ", "F - test-print-float-integer -10"
|
||||
print-float-hex screen, minus-ten-f
|
||||
check-screen-row screen, 1, "-1.400000P03 ", "F - test-print-float-hex-integer -10"
|
||||
}
|
||||
|
||||
fn test-print-float-zero {
|
||||
fn test-print-float-hex-zero {
|
||||
var screen-on-stack: screen
|
||||
var screen/esi: (addr screen) <- address screen-on-stack
|
||||
initialize-screen screen, 5, 0x20 # 32 columns should be more than enough
|
||||
var zero: float
|
||||
print-float screen, zero
|
||||
check-screen-row screen, 1, "0 ", "F - test-print-float-zero"
|
||||
print-float-hex screen, zero
|
||||
check-screen-row screen, 1, "0 ", "F - test-print-float-hex-zero"
|
||||
}
|
||||
|
||||
fn test-print-float-negative-zero {
|
||||
fn test-print-float-hex-negative-zero {
|
||||
var screen-on-stack: screen
|
||||
var screen/esi: (addr screen) <- address screen-on-stack
|
||||
initialize-screen screen, 5, 0x20 # 32 columns should be more than enough
|
||||
var n: int
|
||||
copy-to n, 0x80000000
|
||||
var negative-zero/xmm0: float <- reinterpret n
|
||||
print-float screen, negative-zero
|
||||
check-screen-row screen, 1, "-0 ", "F - test-print-float-negative-zero"
|
||||
print-float-hex screen, negative-zero
|
||||
check-screen-row screen, 1, "-0 ", "F - test-print-float-hex-negative-zero"
|
||||
}
|
||||
|
||||
fn test-print-float-infinity {
|
||||
fn test-print-float-hex-infinity {
|
||||
var screen-on-stack: screen
|
||||
var screen/esi: (addr screen) <- address screen-on-stack
|
||||
initialize-screen screen, 5, 0x20 # 32 columns should be more than enough
|
||||
|
@ -89,33 +89,33 @@ fn test-print-float-infinity {
|
|||
# 0111|1111|1000|0000|0000|0000|0000|0000
|
||||
copy-to n, 0x7f800000
|
||||
var infinity/xmm0: float <- reinterpret n
|
||||
print-float screen, infinity
|
||||
check-screen-row screen, 1, "Inf ", "F - test-print-float-infinity"
|
||||
print-float-hex screen, infinity
|
||||
check-screen-row screen, 1, "Inf ", "F - test-print-float-hex-infinity"
|
||||
}
|
||||
|
||||
fn test-print-float-negative-infinity {
|
||||
fn test-print-float-hex-negative-infinity {
|
||||
var screen-on-stack: screen
|
||||
var screen/esi: (addr screen) <- address screen-on-stack
|
||||
initialize-screen screen, 5, 0x20 # 32 columns should be more than enough
|
||||
var n: int
|
||||
copy-to n, 0xff800000
|
||||
var negative-infinity/xmm0: float <- reinterpret n
|
||||
print-float screen, negative-infinity
|
||||
check-screen-row screen, 1, "-Inf ", "F - test-print-float-negative-infinity"
|
||||
print-float-hex screen, negative-infinity
|
||||
check-screen-row screen, 1, "-Inf ", "F - test-print-float-hex-negative-infinity"
|
||||
}
|
||||
|
||||
fn test-print-float-not-a-number {
|
||||
fn test-print-float-hex-not-a-number {
|
||||
var screen-on-stack: screen
|
||||
var screen/esi: (addr screen) <- address screen-on-stack
|
||||
initialize-screen screen, 5, 0x20 # 32 columns should be more than enough
|
||||
var n: int
|
||||
copy-to n, 0xffffffff # exponent must be all 1's, and mantissa must be non-zero
|
||||
var negative-infinity/xmm0: float <- reinterpret n
|
||||
print-float screen, negative-infinity
|
||||
check-screen-row screen, 1, "NaN ", "F - test-print-float-not-a-number"
|
||||
print-float-hex screen, negative-infinity
|
||||
check-screen-row screen, 1, "NaN ", "F - test-print-float-hex-not-a-number"
|
||||
}
|
||||
|
||||
fn print-float screen: (addr screen), n: float {
|
||||
fn print-float-hex screen: (addr screen), n: float {
|
||||
# - special names
|
||||
var bits/eax: int <- reinterpret n
|
||||
compare bits, 0
|
||||
|
@ -160,14 +160,14 @@ fn print-float screen: (addr screen), n: float {
|
|||
break-if-!=
|
||||
print-string screen, "-"
|
||||
}
|
||||
$print-float:leading-digit: {
|
||||
$print-float-hex:leading-digit: {
|
||||
# check for subnormal numbers
|
||||
compare exponent, -0x7f
|
||||
{
|
||||
break-if-!=
|
||||
print-string screen, "0."
|
||||
exponent <- increment
|
||||
break $print-float:leading-digit
|
||||
break $print-float-hex:leading-digit
|
||||
}
|
||||
# normal numbers
|
||||
print-string screen, "1."
|
||||
|
@ -189,8 +189,8 @@ fn print-float screen: (addr screen), n: float {
|
|||
|
||||
#? fn main -> _/ebx: int {
|
||||
#? run-tests
|
||||
#? #? test-print-float-negative-zero
|
||||
#? #? test-print-float-hex-negative-zero
|
||||
#? #? print-int32-hex 0, 0
|
||||
#? #? test-print-float-normal
|
||||
#? #? test-print-float-hex-normal
|
||||
#? return 0
|
||||
#? }
|
|
@ -29,7 +29,7 @@ fn ray-color _in: (addr ray), _out: (addr rgb) {
|
|||
var two-f/xmm2: float <- convert two
|
||||
t <- divide two-f
|
||||
#? print-string 0, "t: "
|
||||
#? print-float 0, t
|
||||
#? print-float-hex 0, t
|
||||
#? print-string 0, "\n"
|
||||
# whitening = (1.0 - t) * white
|
||||
var whitening-storage: rgb
|
||||
|
@ -68,7 +68,7 @@ fn main -> _/ebx: int {
|
|||
var aspect-addr/eax: (addr float) <- address aspect
|
||||
fill-in-rational aspect-addr, 0x10, 9 # 16/9
|
||||
#? print-string 0, "aspect ratio: "
|
||||
#? print-float 0, aspect
|
||||
#? print-float-hex 0, aspect
|
||||
#? print-string 0, " "
|
||||
#? {
|
||||
#? var foo2/ebx: int <- reinterpret aspect
|
||||
|
@ -83,7 +83,7 @@ fn main -> _/ebx: int {
|
|||
var two-f/xmm4: float <- convert tmp
|
||||
var viewport-height/xmm7: float <- copy two-f
|
||||
#? print-string 0, "viewport height: "
|
||||
#? print-float 0, viewport-height
|
||||
#? print-float-hex 0, viewport-height
|
||||
#? print-string 0, " "
|
||||
#? {
|
||||
#? var foo: float
|
||||
|
@ -96,7 +96,7 @@ fn main -> _/ebx: int {
|
|||
var viewport-width/xmm6: float <- convert tmp
|
||||
viewport-width <- multiply aspect
|
||||
#? print-string 0, "viewport width: "
|
||||
#? print-float 0, viewport-width
|
||||
#? print-float-hex 0, viewport-width
|
||||
#? print-string 0, " "
|
||||
#? {
|
||||
#? var foo: float
|
||||
|
@ -170,7 +170,7 @@ fn main -> _/ebx: int {
|
|||
var u/xmm0: float <- convert i
|
||||
u <- divide image-width-1
|
||||
#? print-string 0, "u: "
|
||||
#? print-float 0, u
|
||||
#? print-float-hex 0, u
|
||||
#? print-string 0, "\n"
|
||||
# v = j / (image-height - 1)
|
||||
var v/xmm1: float <- convert j
|
||||
|
@ -289,13 +289,13 @@ fn print-rgb-raw screen: (addr screen), _v: (addr rgb) {
|
|||
var v/esi: (addr rgb) <- copy _v
|
||||
print-string screen, "("
|
||||
var tmp/eax: (addr float) <- get v, r
|
||||
print-float screen, *tmp
|
||||
print-float-hex screen, *tmp
|
||||
print-string screen, ", "
|
||||
tmp <- get v, g
|
||||
print-float screen, *tmp
|
||||
print-float-hex screen, *tmp
|
||||
print-string screen, ", "
|
||||
tmp <- get v, b
|
||||
print-float screen, *tmp
|
||||
print-float-hex screen, *tmp
|
||||
print-string screen, ")"
|
||||
}
|
||||
|
||||
|
@ -363,13 +363,13 @@ fn print-vec3 screen: (addr screen), _v: (addr vec3) {
|
|||
var v/esi: (addr vec3) <- copy _v
|
||||
print-string screen, "("
|
||||
var tmp/eax: (addr float) <- get v, x
|
||||
print-float screen, *tmp
|
||||
print-float-hex screen, *tmp
|
||||
print-string screen, ", "
|
||||
tmp <- get v, y
|
||||
print-float screen, *tmp
|
||||
print-float-hex screen, *tmp
|
||||
print-string screen, ", "
|
||||
tmp <- get v, z
|
||||
print-float screen, *tmp
|
||||
print-float-hex screen, *tmp
|
||||
print-string screen, ")"
|
||||
}
|
||||
|
||||
|
@ -451,7 +451,7 @@ fn vec3-scale-down _v: (addr vec3), f: float {
|
|||
fn vec3-unit in: (addr vec3), out: (addr vec3) {
|
||||
var len/xmm0: float <- vec3-length in
|
||||
#? print-string 0, "len: "
|
||||
#? print-float 0, len
|
||||
#? print-float-hex 0, len
|
||||
#? print-string 0, "\n"
|
||||
copy-object in, out
|
||||
vec3-scale-down out, len
|
||||
|
|
|
@ -8,13 +8,13 @@ fn print-vec3 screen: (addr screen), _v: (addr vec3) {
|
|||
var v/esi: (addr vec3) <- copy _v
|
||||
print-string screen, "("
|
||||
var tmp/eax: (addr float) <- get v, x
|
||||
print-float screen, *tmp
|
||||
print-float-hex screen, *tmp
|
||||
print-string screen, ", "
|
||||
tmp <- get v, y
|
||||
print-float screen, *tmp
|
||||
print-float-hex screen, *tmp
|
||||
print-string screen, ", "
|
||||
tmp <- get v, z
|
||||
print-float screen, *tmp
|
||||
print-float-hex screen, *tmp
|
||||
print-string screen, ")"
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ fn vec3-scale-down _v: (addr vec3), f: float {
|
|||
fn vec3-unit in: (addr vec3), out: (addr vec3) {
|
||||
var len/xmm0: float <- vec3-length in
|
||||
#? print-string 0, "len: "
|
||||
#? print-float 0, len
|
||||
#? print-float-hex 0, len
|
||||
#? print-string 0, "\n"
|
||||
copy-object in, out
|
||||
vec3-scale-down out, len
|
||||
|
|
Loading…
Reference in New Issue