From 751e1cbb73d2de2863af8853d2ec3c2be9c3d3c2 Mon Sep 17 00:00:00 2001 From: d6 Date: Thu, 6 Apr 2023 22:11:07 -0400 Subject: [PATCH] clean up, improve docs. --- fix16.tal | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/fix16.tal b/fix16.tal index c7d7e4b..d9d2af8 100644 --- a/fix16.tal +++ b/fix16.tal @@ -152,15 +152,12 @@ ( - 00: x = y ) ( - 01: x > y ) @x16-cmp ( x* y* -> c^ ) -( STH2k x16-is-neg ?&yn ( x* [y*] ; ? ) ) - STH2k x16-maximum GTH2 ?&yn ( x* [y*] ; ? ) -( DUP2 x16-is-non-neg ?&same ( x* [y*] ; y>=0 ) ) + STH2k x16-maximum GTH2 ?&yn ( x* [y*] ; ? ) DUP2 x16-minimum LTH2 ?&same ( x* [y*] ; y>=0 ) - POP2 POP2r #ff JMP2r ( -1 ; x<0 y>=0 ) -( &yn DUP2 x16-is-neg ?&same ( x* [y*] ; y<0 ) ) - &yn DUP2 x16-maximum GTH2 ?&same ( x* [y*] ; y<0 ) - POP2 POP2r #01 JMP2r ( 1 ; x>=0 y<0 ) - &same STH2r ( fall-thru ) ( res ; x<0 y<0 b ) + POP2 POP2r #ff JMP2r ( -1 ; x<0 y>=0 ) + &yn DUP2 x16-maximum GTH2 ?&same ( x* [y*] ; y<0 ) + POP2 POP2r #01 JMP2r ( 1 ; x>=0 y<0 ) + &same STH2r ( fall-thru ) ( res ; x<0 y<0 b ) ( unsigned comparison between x and y. ) ( - ff: x < y ) @@ -262,6 +259,10 @@ &rest ADD2 DUP EOR JMP2r ( use up to 256 iterations of heron's algorithm ) +( ) +( NOTE: there are some inaccuracies here, currently ) +( the algorithm doesn't always converge perfectly. ) +( it should be "good enough" for many use cases. ) @x16-sqrt ( x* -> sqrt[x]* ) LIT2r ff00 LIT2r 0200 ( [c* 2*] )