From 2392745f6fc294679c04c2f3c52828c001c1f702 Mon Sep 17 00:00:00 2001 From: d_m Date: Sun, 5 Nov 2023 21:06:22 -0500 Subject: [PATCH] better bug fix --- fix16.tal | 14 +++++++++----- test-fix16.py | 7 +++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/fix16.tal b/fix16.tal index 64ad2d2..c7be7b2 100644 --- a/fix16.tal +++ b/fix16.tal @@ -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 diff --git a/test-fix16.py b/test-fix16.py index b168f06..a8015fa 100644 --- a/test-fix16.py +++ b/test-fix16.py @@ -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)