home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / lib / Int.sig < prev    next >
Encoding:
Text File  |  1997-08-18  |  3.8 KB  |  111 lines  |  [TEXT/Moml]

  1. (* Int -- SML Basis Library *)
  2.  
  3. type int = int
  4.  
  5. val precision : int option
  6. val minInt    : int option
  7. val maxInt    : int option
  8.  
  9. val ~    : int -> int                   (* Overflow      *)
  10. val *    : int * int -> int             (* Overflow      *)
  11. val div  : int * int -> int             (* Div, Overflow *)
  12. val mod  : int * int -> int             (* Div           *)
  13. val quot : int * int -> int             (* Div, Overflow *)
  14. val rem  : int * int -> int             (* Div           *)
  15. val +    : int * int -> int             (* Overflow      *)
  16. val -    : int * int -> int             (* Overflow      *)
  17. val >    : int * int -> bool
  18. val >=   : int * int -> bool
  19. val <    : int * int -> bool
  20. val <=   : int * int -> bool
  21. val abs  : int -> int                   (* Overflow      *)
  22. val min  : int * int -> int
  23. val max  : int * int -> int
  24.  
  25. val sign      : int -> int
  26. val sameSign  : int * int -> bool
  27. val compare   : int * int -> order
  28.  
  29. val toInt     : int -> int
  30. val fromInt   : int -> int
  31. val toLarge   : int -> int
  32. val fromLarge : int -> int
  33.  
  34. val toString   : int -> string
  35. val fromString : string -> int option   (* Overflow      *)
  36.  
  37. val scan : StringCvt.radix 
  38.            -> (char, 'a) StringCvt.reader -> (int, 'a) StringCvt.reader
  39. val fmt  : StringCvt.radix -> int -> string
  40.  
  41. (* 
  42.    [precision] is SOME n, where n is the number of significant bits in an
  43.    integer.  In Moscow ML n is 31 in 32-bit architectures and 63 in 64-bit
  44.    architectures.
  45.  
  46.    [minInt] is SOME n, where n is the most negative integer.
  47.  
  48.    [maxInt] is SOME n, where n is the most positive integer.
  49.  
  50.    [~, *, div, mod, +, -, >, >=, <, <=, abs] are the usual operations
  51.    on integers, as prescribed by the Definition.
  52.  
  53.    [quot(i, d)] is the quotient of i by d, rounding towards zero (instead 
  54.    of rounding towards minus infinity, as done by div).
  55.  
  56.    [rem(i, d)] is the remainder for quot.  That is, 
  57.    if    q' = quot(i, d)  and  r' = rem(i, d)
  58.    then  d * q' + r' = i  and  0 <= d * q' <= i  or  i <= d * q' <= 0.
  59.    The recommended fixity for quot and rem is  
  60.                         infix 7 quot rem
  61.  
  62.    [min(x, y)] is the smaller of x and y.
  63.  
  64.    [max(x, y)] is the larger of x and y.
  65.  
  66.    [sign x] is ~1, 0, or 1, according as x is negative, zero, or positive.
  67.  
  68.    [compare(x, y)] returns LESS, EQUAL, or GREATER, according 
  69.    as x is less than, equal to, or greater than y.
  70.  
  71.    [sameSign(x, y)] is true iff sign x = sign y.
  72.  
  73.    [toDefault x] is x.
  74.  
  75.    [fromDefault x] is x.
  76.  
  77.    [fmt radix i] returns a string representing i, in the radix (base)
  78.    specified by radix.
  79.  
  80.      radix    description                     output format  
  81.      ------------------------------------------------------
  82.       BIN     signed binary      (base  2)    ~?[01]+
  83.       OCT     signed octal       (base  8)    ~?[0-7]+
  84.       DEC     signed decimal     (base 10)    ~?[0-9]+
  85.       HEX     signed hexadecimal (base 16)    ~?[0-9A-F]+
  86.  
  87.    [toString i] returns a string representing i in signed decimal format.
  88.    Equivalent to (fmt DEC i).
  89.    
  90.    [fromString s] returns SOME(i) if a decimal integer numeral can be
  91.    scanned from a prefix of string s, ignoring any initial whitespace;
  92.    returns NONE otherwise.  A decimal integer numeral must have form,
  93.    after possible initial whitespace: 
  94.         [+~-]?[0-9]+
  95.  
  96.    [scan radix getc charsrc] attempts to scan an integer numeral
  97.    from the character source charsrc, using the accessor getc, and
  98.    ignoring any initial whitespace.  The radix argument specifies the base
  99.    of the numeral (BIN, OCT, DEC, HEX).  If successful, it returns
  100.    SOME(i, rest) where i is the value of the number scanned, and rest
  101.    is the unused part of the character source.  A numeral must have
  102.    form, after possible initial whitespace:
  103.  
  104.      radix    input format 
  105.      ---------------------------
  106.       BIN     [+~-]?[0-1]+
  107.       OCT     [+~-]?[0-7]+
  108.       DEC     [+~-]?[0-9]+
  109.       HEX     [+~-]?[0-9a-fA-F]+
  110. *)
  111.