The IEEEReal structure
The IEEEReal structure defines types associated with an IEEE implementation of floating-point numbers. In addition, it provides control for the floating-point hardware's rounding mode. Refer to the IEEE standard 754-1985 and the ANSI/IEEE standard 854-1987 for additional information.
Synopsis
signature IEEE_REAL
structure IEEEReal : IEEE_REAL
Interface
exception Unordered
datatype real_order = LESS | EQUAL | GREATER | UNORDERED
datatype nan_mode = QUIET | SIGNALLING
datatype float_class
= NAN of nan_mode
| INF
| ZERO
| NORMAL
| SUBNORMAL
datatype rounding_mode
= TO_NEAREST
| TO_NEGINF
| TO_POSINF
| TO_ZERO
val setRoundingMode : rounding_mode -> unit
val getRoundingMode : unit -> rounding_mode
type decimal_approx = { kind : float_class, sign : bool, digits : int list, exp : int }
val toString : decimal_approx -> string
val fromString : string -> decimal_approx option
Description
-
exception Unordered -
-
datatype real_order -
-
datatype nan_mode -
-
datatype float_class -
-
datatype rounding_mode -
-
setRoundingMode modegetRoundingMode () -
set and get the rounding mode of the underlying hardware.
-
type decimal_approx -
provides a structured decimal representation of a real. The
kindfield indicates the real class. Ifsignistrue, the number is negative. The integers in thedigitslist must be digits, i.e., between 0 and 9.When
kindisNORMALorSUBNORMAL, a value of of typedecimal_approxwithdigits= [d(1), d(2), ..., d(n)] corresponds to the real number s * 0.d(1)d(2)...d(n) 10(exp), where s is -1 ifsignistrueand 1 otherwise. WhenkindisZEROorINF, the value corresponds to zero or infinity, respectively, with its sign determined bysign. WhenkindisNAN _, the value corresponds to a NaN real value whose whose fraction bits are the binary equivalent of 0.d(1)d(2)...d(n) and whose sign bit is set ifsignistrue.
-
toString d -
returns a string representation of d. Assuming
digits= [d(1), d(2), ..., d(n)] and ignoring thesignandexpfields,toStringgenerates the following strings depending on thekindfield:
ZERO 0.0 NORMAL 0.d(1)d(2)...d(n) SUBNORMAL 0.d(1)d(2)...d(n) INF inf NAN _ nan(d(1)d(2)...d(n))
If thesignfield istrue, a#"~"is prepended. If theexpfield is non-zero and thekindis NORMAL or SUBNORMAL, the string"E"^(Integer.toString exp)is appended.toString o REAL.toDecimalis equivalent toREAL.fmt IEEEReal.EXACT.
-
fromString s -
returns
SOME rif the decimal approximationrcan be parsed from a prefix of string s, ignoring initial whitespace; NONE is returned if no such conversion is possible.fromStringaccepts any of the following regular expressions:[+~-]?(INF|INFINITY) [+~-]?(NAN|NAN\([0-9]+\)) [+~-]?(([0-9]+(\.[0-9]+)?)|(\.[0-9]+))([eE][+~-]?[0-9]+)?where alphabetic characters are case-insensitive. The optional sign determines the value of thesignfield, with a default offalse. In the first case,kindis set to INF,digits = []andexp = 0. In the second case,kindis set to NAN andexp = 0. If the optional digits are provided, they become the list of digits; otherwise,digits = []. In the last case, initial 0's are stripped from the integer part and trailing 0's are stripped from the fractional part, yielding two listsilandfl, respectively, of integers. If no digits are left, i.e., both lists are empty,kindis set to ZERO,digits = []andexp = 0. Otherwise,kindis set to NORMAL,digits = il@fl, andexpis set to the length ofilplus the value of the exponent, if it exists.
See Also
REAL, MATH