home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / progrmng / cmlmcmpw.sit / Caml Light / Lib / int.mli < prev    next >
Encoding:
Text File  |  1991-05-13  |  2.7 KB  |  66 lines  |  [TEXT/MPS ]

  1. (* Operations on integers *)
  2.  
  3. (* Integers are 31-bit wide. All operations are taken modulo 2^31.
  4.    They do not fail on overflow. *)
  5.  
  6. exception Division_by_zero;;
  7.  
  8. value minus : int -> int = 1 "~int"
  9.   and minus_int : int -> int = 1 "~int"
  10.         (* Unary negation. Also written "-e". *)
  11.   and succ : int -> int = 1 "succ"
  12.         (* succ x = x+1 *)
  13.   and pred : int -> int = 1 "pred"
  14.         (* pred x = x+1 *)
  15.   and prefix + : int -> int -> int = 2 "+int"
  16.   and add_int : int -> int -> int = 2 "+int"
  17.         (* Addition *)
  18.   and prefix - : int -> int -> int = 2 "-int"
  19.   and sub_int : int -> int -> int = 2 "-int"
  20.         (* Substraction *)
  21.   and prefix * : int -> int -> int = 2 "*int"
  22.   and mult_int : int -> int -> int = 2 "*int"
  23.         (* Product *)
  24.   and prefix / : int -> int -> int = 2 "div"
  25.         (* Integer division. Raises Division_by_zero if second argument is 0 *)
  26.   and prefix mod : int -> int -> int = 2 "mod"
  27.         (* Remainder. Raises Division_by_zero if second argument is 0.
  28.            Gives unpredictable results if either argument is negative. *)
  29.   and prefix = : int -> int -> bool = 2 "=int"
  30.   and eq_int : int -> int -> bool = 2 "=int"
  31.         (* Integer equality. Equivalent to generic equality, just faster. *)
  32.   and prefix <> : int -> int -> bool = 2 "<>int"
  33.   and neq_int : int -> int -> bool = 2 "<>int"
  34.         (* Negation of the above. *)
  35.   and prefix < : int -> int -> bool = 2 "<int"
  36.   and lt_int : int -> int -> bool = 2 "<int"
  37.   and prefix > : int -> int -> bool = 2 ">int"
  38.   and gt_int : int -> int -> bool = 2 ">int"
  39.   and prefix <= : int -> int -> bool = 2 "<=int"
  40.   and le_int : int -> int -> bool = 2 "<=int"
  41.   and prefix >= : int -> int -> bool = 2 ">=int"
  42.   and ge_int : int -> int -> bool = 2 ">=int"
  43.         (* Usual comparisons between integers. *)
  44. ;;
  45.  
  46. value land : int -> int -> int = 2 "and"
  47.         (* Bitwise logical and. *)
  48.   and lor : int -> int -> int = 2 "or"
  49.         (* Bitwise logical or. *)
  50.   and lxor : int -> int -> int = 2 "xor"
  51.         (* Bitwise logical exclusive or. *)
  52.   and lshift_left : int -> int -> int = 2 "shift_left"
  53.         (* "lshift_left n m" shifts n to the left by m bits. *)
  54.   and lshift_right : int -> int -> int = 2 "shift_right"
  55.         (* "lshift_right n m" shifts n to the right by m bits.
  56.            This is an arithmetic shift (the sign bit is replicated). *)
  57. ;;
  58.  
  59. value string_of_int : int -> string = 1 "string_of_int" "alloc"
  60.         (* Converts the given integer to its decimal representation *)
  61.   and int_of_string : string -> int = 1 "int_of_string"
  62.         (* Converts the given string to an integer, in decimal.
  63.            Raises failure "int_of_string" if the given string is not
  64.            a valid representation of an integer. *)
  65. ;;
  66.