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

  1. (* Real -- SML Basis Library *)
  2.  
  3. type real = real
  4.  
  5. exception Div
  6. and Overflow
  7.  
  8. val ~    : real -> real
  9. val +    : real * real -> real
  10. val -    : real * real -> real
  11. val *    : real * real -> real
  12. val /    : real * real -> real
  13. val abs  : real -> real
  14. val min  : real * real -> real
  15. val max  : real * real -> real
  16. val sign : real -> int
  17. val compare : real * real -> order
  18.  
  19. val sameSign    : real * real -> bool
  20. val toDefault   : real -> real
  21. val fromDefault : real -> real
  22. val fromInt     : int -> real
  23.  
  24. val floor : real -> int
  25. val ceil  : real -> int
  26. val trunc : real -> int
  27. val round : real -> int
  28.  
  29. val >    : real * real -> bool
  30. val >=   : real * real -> bool
  31. val <    : real * real -> bool
  32. val <=   : real * real -> bool
  33.  
  34. val toString   : real -> string
  35. val fromString : string -> real option
  36. val scan       : (char, 'a) StringCvt.reader -> (real, 'a) StringCvt.reader
  37. val fmt        : StringCvt.realfmt -> real -> string
  38.  
  39. (* [~, *, /, +, -, >, >=, <, <=, abs] are the usual operations on reals.
  40.  
  41.    [min(x, y)] is the smaller of x and y.
  42.  
  43.    [max(x, y)] is the larger of x and y.
  44.  
  45.    [sign x] is ~1, 0, or 1, according as x is negative, zero, or positive.
  46.  
  47.    [compare(x, y)] returns LESS, EQUAL, or GREATER, according 
  48.    as x is less than, equal to, or greater than y.
  49.  
  50.    [sameSign(x, y)] is true iff sign x = sign y.
  51.  
  52.    [toDefault x] is x.
  53.  
  54.    [fromDefault x] is x.
  55.  
  56.    [fromInt i] is the floating-point number representing integer i.
  57.  
  58.    [floor r] is the largest integer <= r (rounds towards minus infinity).
  59.    May raise Overflow.
  60.  
  61.    [ceil r] is the smallest integer >= r (rounds towards plus infinity).
  62.    May raise Overflow.
  63.  
  64.    [trunc r] is numerically largest integer between r and zero 
  65.    (rounds towards zero). May raise Overflow.
  66.  
  67.    [round r] is the integer nearest to r, using the default rounding
  68.    mode.  NOTE: This isn't the required behaviour: it should round to
  69.    nearest even integer in case of a tie.  May raise Overflow.
  70.  
  71.    [fmt spec r] returns a string representing r, in the format
  72.    specified by spec.
  73.  
  74.       spec          description                            C printf 
  75.       ---------------------------------------------------------------
  76.       SCI NONE      scientific,   6 digits after point       %e
  77.       SCI (SOME n)  scientific,   n digits after point       %.ne
  78.       FIX NONE      fixed-point,  6 digits after point       %f
  79.       FIX (SOME n)  fixed-point,  n digits after point       %.nf
  80.       GEN NONE      auto choice, 12 significant digits       %.12g
  81.       GEN (SOME n)  auto choice,  n significant digits       %.ng
  82.  
  83.    [toString r] returns a string representing r, with automatic choice
  84.    of format according to the magnitude of r.  
  85.    Equivalent to (fmt (GEN NONE) r).
  86.    
  87.    [fromString s] returns SOME(r) if a floating-point numeral can be
  88.    scanned from a prefix of string s, ignoring any initial whitespace;
  89.    returns NONE otherwise.  The valid forms of floating-point numerals
  90.    are described by:
  91.     [+~-]?(([0-9]+(\.[0-9]+)?)|(\.[0-9]+))([eE][+~-]?[0-9]+)?
  92.  
  93.    [scan getc charsrc] attempts to scan a floating-point number from
  94.    the character source charsrc, using the accessor getc, and ignoring
  95.    any initial whitespace.  If successful, it returns SOME(r, rest)
  96.    where r is the number scanned, and rest is the unused part of the
  97.    character source.  The valid forms of floating-point numerals
  98.    are described by:
  99.     [+~-]?(([0-9]+(\.[0-9]+)?)|(\.[0-9]+))([eE][+~-]?[0-9]+)?
  100. *)
  101.