int.fun 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. #import std
  2. #import nat
  3. #comment -[
  4. This module defines operations on signed integers. The virtual machine
  5. representation of a non-negative integer is the same as that of the
  6. corresponding natural number. Negative integers are represented as
  7. the natural number equal to their absolute value with a zero bit
  8. appended. The bit operations double, half, and odd defined in the
  9. nat module will also work on integers in this representation.
  10. Copyright (C) 2009,2010 Dennis Furey]-
  11. #optimize+
  12. gams = ~&l?/~&r @r ~&i&& --<0>
  13. smag = ~&bbI+ ~~ ~&?\&! ~&z?/~&NNXiX ~&NyX
  14. smad = gams+ ==?l/^|(~&l,nat-sum) ^|(~&l,nat-difference)+ nleq?r\~& ~&brlX
  15. #library+
  16. abs = ~&i&& ~&xhitQx
  17. difference = smad@llrZXPrX+ smag
  18. division = smag; gams~~^|G/== nat-division
  19. negation = ~&i&& ~&z?\~&y --<0>
  20. predecessor = ~&?\<&,0>! ~&z?/nat-predecessor --<0>+ nat-successor@y
  21. product = smag; gams^|/== nat-product
  22. quotient = ~&l+ division
  23. remainder = ~&r+ division
  24. sgn = ~&i&& ~&z?/1! <&,0>!
  25. sum = smad+ smag
  26. successor = ~=<&,0>&& ~&?\1! ~&z?/nat-successor --<0>+ nat-predecessor@y
  27. zleq = smag; ~&l==(0,&)!| ~&l~=(&,0)&& ^|E/~&l nleq
  28. zrange = zleq?(~&NiX,~&NNXrlXX); ^|lrrxPQ/~& @lNCrX ~&lhPrEZ->l ^|\~& ^C/successor@h ~&