![]() | Library Documentation | Structures | Signatures | Identifiers | Packages | About |
IEEE_REAL (basis)Types and operations related to an IEEE implementation of reals.
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.structure IEEEReal : IEEE_REAL (basis)
signature IEEE_REAL =
sig
exception Unordered
datatype real_order = LESS | EQUAL | GREATER | UNORDERED
datatype float_class
= NAN
| 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 = {
class : float_class,
sign : bool,
digits : int list,
exp : int
}
val toString : decimal_approx -> string
val scan : (char, 'a) StringCvt.reader -> (decimal_approx, 'a) StringCvt.reader
val fromString : string -> decimal_approx option
end
Implementation note:
Some platforms do not support all of the rounding modes. An SML
implementation built on these platforms will necessarily be
non-conforming with, presumably, setRoundingMode raising an
exception for the unsupported modes.
ZERO "0.0"
NORMAL "0.d(1)d(2)...d(n)"
SUBNORMAL "0.d(1)d(2)...d(n)"
INF "inf"
NAN "nan"
If the sign field is true, a #"~" is prepended. If the exp field is
non-zero and the class is NORMAL or SUBNORMAL, the string
"E"^(Integer.toString exp) is appended. The composition toString o
REAL.toDecimal is equivalent to REAL.fmt StringCvt.EXACT.
[+~-]?([0-9]+.[0-9]+? | .[0-9]+)(e | E)[+~-]?[0-9]+?
The optional sign determines the value of the sign field, with a
default of false. Initial zeros are stripped from the integer part and
trailing zeros are stripped from the fractional part, yielding two
lists il and fl, respectively, of digits. If il is non-empty, then
class is set to NORMAL, digits is set to il@fl with any trailing zeros
removed and exp is set to the length of il plus the value of the
scanned exponent, if any. If il is empty and so is fl, then class is
set to ZERO, digits = [] and exp = 0. Finally, if il is empty but fl
is not, let m be the number of leading zeros in fl and let fl' be fl
after the leading zeros are removed. Then, class is set to NORMAL,
digits is set to fl' and exp is set to -m plus the value of the
scanned exponent, if any. They also accept the following string
representations of non-finite values:
[+~-]?(inf | infinity | nan)
where the alphabetic characters are case-insensitive. The optional
sign determines the value of the sign field, with a default of
false. In the first and second cases, d will have class set to INF. In
the third case, class is set to NAN. In all these cases, d will have
digits = [] and exp = 0.