better bug fix

This commit is contained in:
~d6 2023-11-05 21:06:22 -05:00
parent 3993dbc80a
commit 2392745f6f
2 changed files with 14 additions and 7 deletions

View File

@ -342,17 +342,21 @@
&done ( x* s1* [c* 2*] )
POP2r POP2r NIP2 JMP2r ( s1* )
@x16-unit-circle ( x* -> x'* )
x16-pi*2 STH2 ( x [2pi] )
DUP2 STH2kr x16-quotient ( x x/2pi [2pi] )
DUP2 #1400 DIV2 STH2 SWP2r ( x x/2pi [adj* 2pi*] )
STH2r x16-mul STH2r ADD2 SUB2 ( x' ; 0 <= x' < 2pi )
JMP2r
@x16-cos ( x* -> cos[x]* )
x16-pi/2 ADD2
x16-unit-circle x16-pi/2 ADD2 ( fall-through )
@x16-sin ( x* -> sin[x]* )
DUP2 #8000 LTH2 ?&non-negative
x16-negate x16-sin/non-negative !x16-negate
&non-negative
x16-pi*2 STH2 ( x [2pi] )
DUP2 STH2kr x16-quotient ( x x/2pi [2pi] )
DUP2 #1400 DIV2 STH2 SWP2r ( x x/2pi [adj* 2pi*] )
STH2r x16-mul STH2r ADD2 SUB2 ( x' ; 0 <= x' < 2pi )
x16-unit-circle
DUP2 x16-3pi/2 LTH2 ?&c1
( -sin(2pi - x) ) x16-pi*2 SWP2 SUB2 x16-sin-q !x16-negate
&c1 DUP2 x16-pi LTH2 ?&c2

View File

@ -4,7 +4,7 @@ from math import ceil, copysign, cos, floor, log, sin, sqrt, tan
from os import environ
from random import randint
from subprocess import Popen, PIPE, run
from sys import argv
from sys import argv, exit
def tosigned(x):
return x if x < 32768 else x - 65536
@ -173,7 +173,10 @@ def x16_trunc8(x):
def main():
trials = int(argv[1]) if argv[1:] else 100
run(['uxnasm', 'test-fix16.tal', 'run.rom'])
e = run(['uxnasm', 'test-fix16.tal', 'run.rom'])
if e.returncode != 0:
print('the command `uxnasm test-fix16.tal run.rom` failed!')
exit(e.returncode)
p = pipe()
test(p, trials, b'+', [('x', u16), ('y', u16)], u16, x16_add)
test(p, trials, b'-', [('x', u16), ('y', u16)], u16, x16_sub)