From d18c563187558c649fd51f628e14ead3bcee1518 Mon Sep 17 00:00:00 2001 From: d_m Date: Fri, 29 Dec 2023 15:41:13 -0500 Subject: [PATCH] fix signed division example --- math-notes.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/math-notes.txt b/math-notes.txt index 18d4949..3f25a25 100644 --- a/math-notes.txt +++ b/math-notes.txt @@ -66,8 +66,11 @@ Other instructions will not handle "negative" integers correctly: way to handle this is to make both values non-negative, do unsigned division (i.e. DIV) and then set the correct sign at the end. + @abs ( x^ -- abs-x^ sign^ ) + DUP #7f GTH #fe MUL INC STHk MUL STHr JMP2r + @signed-div ( x^ y^ -- x/y^ ) - DUP2 #8080 AND2 EQU STH DIV STHr ?&same #ff MUL &same JMP2r + abs STH SWP abs STH SWP DIV MULr STHr MUL JMP2r Be careful! The smallest negative value (-128 for bytes, -32768 for shorts) has no corresponding positive value. This means that some operations will