nxu/test-fix32.tal

99 lines
5.4 KiB
Tal

( test-fix32.tal )
( )
( methods for testing math32 and emitting output )
( TODO: consider rounding modes. currently we always round toward zero )
( program )
|0100
#00 x32-from-u8 x32-emit #0a18 DEO ( 0.0 )
#01 x32-from-u8 x32-emit #0a18 DEO ( 1.0 )
#0a x32-from-u8 x32-emit #0a18 DEO ( 10.0 )
#ff x32-from-u8 x32-emit #0a18 DEO ( 255.0 )
#0100 x32-from-u16 x32-emit #0a18 DEO ( 256.0 )
#1000 x32-from-u16 x32-emit #0a18 DEO ( 4096.0 )
#7fff x32-from-u16 x32-emit #0a18 DEO ( 32767.0 )
#8000 x32-from-u16 x32-emit #0a18 DEO ( 32768.0 )
#ffff x32-from-u16 x32-emit #0a18 DEO ( 65535.0 )
#01 x32-from-s8 x32-emit #0a18 DEO ( 10.0 )
#0a x32-from-s8 x32-emit #0a18 DEO ( 10.0 )
#80 x32-from-s8 x32-emit #0a18 DEO ( -128.0 )
#ff x32-from-s8 x32-emit #0a18 DEO ( -1.0 )
#0a18 DEO
#0000 #03e8 #0000 #07d0 LIT "+ ;x32-add #0000 #0bb8 test-binop ( 1 + 2 = 3 )
#ffff #fc18 #ffff #fc18 LIT "+ ;x32-add #ffff #f830 test-binop ( -1 + -1 = -2 )
#7fff #ffff #7fff #ffff LIT "+ ;x32-add #7fff #ffff test-binop ( inf + inf = inf )
#8000 #0001 #8000 #0001 LIT "+ ;x32-add #8000 #0001 test-binop ( -inf + -inf = -inf )
#0001 #e078 #ffff #a628 LIT "+ ;x32-add #0001 #86a0 test-binop ( 123.0 + -23.0 = 100.0 )
#0a18 DEO
#0000 #03e8 #0000 #03e8 LIT "* ;x32-mul #0000 #03e8 test-binop ( 1 * 1 = 1 )
#0000 #07d0 #0000 #0bb8 LIT "* ;x32-mul #0000 #1770 test-binop ( 2 * 3 = 6 )
#0000 #4a38 #0000 #6978 LIT "* ;x32-mul #0007 #d3d8 test-binop ( 19 * 27 = 513 )
#0000 #0064 #0000 #0064 LIT "* ;x32-mul #0000 #000a test-binop ( 0.1 * 0.1 = 0.01 )
#0000 #01f4 #0000 #0001 LIT "* ;x32-mul #0000 #0000 test-binop ( 0.5 * 0.001 = 0.0 )
#0000 #01f4 #0000 #0003 LIT "* ;x32-mul #0000 #0002 test-binop ( 0.5 * 0.003 = 0.002 )
#0000 #01f4 #0000 #0005 LIT "* ;x32-mul #0000 #0002 test-binop ( 0.5 * 0.005 = 0.002 )
#0000 #01f4 #0000 #0007 LIT "* ;x32-mul #0000 #0004 test-binop ( 0.5 * 0.007 = 0.004 )
#0000 #01f4 #0000 #0009 LIT "* ;x32-mul #0000 #0004 test-binop ( 0.5 * 0.009 = 0.004 )
#0000 #0bb8 #ffff #f830 LIT "* ;x32-mul #ffff #e890 test-binop ( 3 * -2 = -6 )
#ffff #fc18 #ffff #fc18 LIT "* ;x32-mul #0000 #03e8 test-binop ( -1 * -1 = 1 )
#0a18 DEO
#0000 #1d4c #0000 #05dc LIT "/ ;x32-div #0000 #1388 test-binop ( 7.5 / 1.5 = 5.0 )
#0000 #03e8 #0000 #0001 LIT "/ ;x32-div #000f #4240 test-binop ( 1.0 / 0.001 = 1000.0 )
#0000 #03e8 #0000 #0bb8 LIT "/ ;x32-div #0000 #014d test-binop ( 1.0 / 3.0 = 0.333 )
#0000 #07d0 #0000 #0bb8 LIT "/ ;x32-div #0000 #029b test-binop ( 2.0 / 3.0 = 0.667 )
#ffff #adf8 #0000 #1b58 LIT "/ ;x32-div #ffff #f448 test-binop ( -21.0 / 7.0 = -3.0 )
#0000 #0003 #0000 #07d0 LIT "/ ;x32-div #0000 #0002 test-binop ( 0.003 / 2 = 0.002 )
#0000 #0005 #0000 #07d0 LIT "/ ;x32-div #0000 #0002 test-binop ( 0.005 / 2 = 0.002 )
#0000 #0007 #0000 #07d0 LIT "/ ;x32-div #0000 #0004 test-binop ( 0.007 / 2 = 0.004 )
#0000 #0009 #0000 #07d0 LIT "/ ;x32-div #0000 #0004 test-binop ( 0.009 / 2 = 0.004 )
#ffff #fffd #0000 #07d0 LIT "/ ;x32-div #ffff #fffe test-binop ( -0.003 / 2 = -0.002 )
#ffff #fffb #0000 #07d0 LIT "/ ;x32-div #ffff #fffe test-binop ( -0.005 / 2 = -0.002 )
#ffff #fff9 #0000 #07d0 LIT "/ ;x32-div #ffff #fffc test-binop ( -0.007 / 2 = -0.004 )
#ffff #fff7 #0000 #07d0 LIT "/ ;x32-div #ffff #fffc test-binop ( -0.009 / 2 = -0.004 )
#0a18 DEO
#0000 #0001 x32-emit #0a18 DEO ( 0.001 )
#0000 #03e8 x32-emit #0a18 DEO ( 1.000 )
#0000 #0586 x32-emit #0a18 DEO ( 1.414 )
#0000 #0623 x32-emit #0a18 DEO ( 1.571 )
#0000 #06c4 x32-emit #0a18 DEO ( 1.732 )
#0000 #0a9e x32-emit #0a18 DEO ( 2.718 )
#0000 #0c46 x32-emit #0a18 DEO ( 3.142 )
#0000 #1268 x32-emit #0a18 DEO ( 4.712 )
#0000 #188b x32-emit #0a18 DEO ( 6.283 )
#0001 #0000 x32-emit #0a18 DEO ( 65.536 )
#0001 #e078 x32-emit #0a18 DEO ( 123.000 )
#0123 #4567 x32-emit #0a18 DEO ( 19088.743 )
#7fff #ffff x32-emit #0a18 DEO ( 2147483.647 )
#8000 #0001 x32-emit #0a18 DEO ( -2147483.647 )
#ffff #fc18 x32-emit #0a18 DEO ( -1.000 )
#ffff #ffff x32-emit #0a18 DEO ( -0.001 )
#800f DEO BRK
~fix32.tal
@test-binop ( x** y** op^ f* z** -> x** y** )
STH2 STH2 ,&f STR2 ,&op STR ( x** y** [z1* z0*] )
STH2 STH2 OVR2 OVR2 emit/long ( x** [z1* z0* y1* z0*] ; emit x )
#2018 DEO ( x** [z1* z0* y1* y0*] ; emit space )
LIT [ &op $1 ] #18 DEO ( x** [z1* z0* y1* y0*] ; emit operator symbol )
#2018 DEO ( x** [z1* z0* y1* y0*] ; emit space )
STH2r STH2r OVR2 OVR2 emit/long ( x** y** [z1* z0*] ; emit y )
#2018 DEO ( x** y** [z1* z0*] ; emit space )
LIT "= #18 DEO ( x** y** [z1* z0*] ; emit = )
#2018 DEO ( x** y** [z1* z0*] ; emit space )
LIT2 [ &f $2 ] JSR2 ( f[x,y]** [z1* z0*] )
emit/long ( [z1* z0*] ; emit f[x,y] )
STH2r STH2r #2018 DEO ( z** ; emit space )
LIT "[ #18 DEO ( z** ; emit [ )
emit/long ( ; emit z )
LIT "] #18 DEO ( ; emit ] )
#0a18 DEO JMP2r ( ; emit newline )
@emit
&long SWP2 /short
&short SWP ,&byte JSR
&byte DUP #04 SFT ,&char JSR
&char #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO
JMP2r