add example of unsigned number vocabulary
FossilOrigin-Name: 94de33e961466ffd42bb28a81dfb974b2f8034555de7e99fd2295641316cb36e
This commit is contained in:
parent
b2e807278e
commit
0cb7f0ad99
1 changed files with 21 additions and 0 deletions
21
example/unsigned.retro
Normal file
21
example/unsigned.retro
Normal file
|
@ -0,0 +1,21 @@
|
|||
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? ;
|
||||
~~~
|
Loading…
Reference in a new issue