0cb7f0ad99
FossilOrigin-Name: 94de33e961466ffd42bb28a81dfb974b2f8034555de7e99fd2295641316cb36e
21 lines
563 B
Forth
21 lines
563 B
Forth
This is a vocabulary for doing some basic operations on unsigned
|
|
numbers.
|
|
|
|
~~~
|
|
:u:patch (n-n)
|
|
dup n:negative?
|
|
[ #2147483647 n:add n:inc swap #-2147483648 n:sub n:add ] if ;
|
|
|
|
:u:add (nn-n) n:add u:patch ;
|
|
:u:sub (nn-n) n:sub u:patch ;
|
|
:u:mul (nn-n) n:mul u:patch ;
|
|
:u:div (nn-n)
|
|
dup n:zero? [ drop-pair n:MAX ] [ n:div u:patch ] choose ;
|
|
:u:mod (nn-n)
|
|
dup n:zero? [ drop-pair n:MAX ] [ n:mod u:patch ] choose ;
|
|
|
|
:u:eq? (nn-f) or not ;
|
|
:u:-eq? (nn-f) u:eq? not ;
|
|
:u:lt? (nn-f) over or and n:negative? ;
|
|
:u:gt? (nn-f) tuck or and n:negative? ;
|
|
~~~
|