Signed Math Library

SignedMathLibrary.dg (3.3 KB) Version 0.1.

For a project I want to work on I need (small in magnitude) negative numbers. Because there aren’t negative numbers built in to Dialog, I am emulating them with lists. Specifically, a positive number is represented as [+ $N], and a negative number as [- $N], where $N is a standard dialog number. This probably isn’t the most efficient approach processing wise, but I didn’t want to try figuring out two’s complement math for this.

I currently support comparison, negation, addition, subtraction, multiplication and division; I didn’t add modulo because signed modulo doesn’t have a universal definition.

I want to make it so standard numbers are promoted to signed positives when passed as input parameters of signed functions, I think that should be possible. I might also see about handling vector math by generalizing signed numbers to vectors of signed numbers: [{±} $N1 {±} $N2 {±} $N3 …], but for now I’m going to just leave that as a thought.

3 Likes

SignedMathLibrary.dg (5.9 KB) Version 0.2.

This update renames some predicates but the main change is that you can now mix signed and unsigned numbers, with unsigned numbers being promoted to signed numbers.

1 Like