Decimal.Signal
Signals are used to control the behaviour of the decimal functions under exceptional conditions.
val make : unit -> array
make ()
a new set of signals. All the signals are unset initially.
set array id bool
sets the state of the signal id
in array
to bool
.
val to_string : id -> string
to_string id
is id
's name.
val pp : Stdlib.Format.formatter -> array -> unit
pp f array
pretty-prints the signal array.
val clamped : id
Exponent of a 0 changed to fit bounds.
This occurs and signals clamped if the exponent of a result has been altered in order to fit the constraints of a specific concrete representation. This may occur when the exponent of a zero result would be outside the bounds of a representation, or when a large normal number would have an encoded exponent that cannot be represented. In this latter case, the exponent is reduced to fit and the corresponding number of zero digits are appended to the coefficient ("fold-down").
val invalid_operation : id
An invalid operation was performed.
Various bad things cause this:
The result of the operation after these is a NaN
.
val conversion_syntax : id
Trying to convert badly formed string.
This occurs and signals invalid-operation if a string is being converted to a number and it does not conform to the numeric string syntax. The result is NaN
.
val div_by_zero : id
Division by 0.
This occurs and signals division-by-zero if division of a finite number by zero was attempted (during a divide-integer or divide operation, or a power operation with negative right-hand operand), and the dividend was not zero.
The result of the operation is (sign)Inf
, where (sign)
is the exclusive or of the signs of the operands for divide, or is 1 for an odd power of -0, for power.
val div_impossible : id
Cannot perform the division adequately.
This occurs and signals invalid-operation if the integer result of a divide-integer or remainder operation had too many digits (would be longer than precision). The result is NaN
.
val div_undefined : id
Undefined result of division.
This occurs and signals invalid-operation if division by zero was attempted (during a divide-integer, divide, or remainder operation), and the dividend is also zero. The result is NaN
.
val inexact : id
Had to round, losing information.
This occurs and signals inexact whenever the result of an operation is not exact (that is, it needed to be rounded and any discarded digits were non- zero), or if an overflow or underflow condition occurs. The result in all cases is unchanged. The inexact signal may be tested (or trapped) to determine if a given operation (or sequence of operations) was inexact.
val rounded : id
Number got rounded (not necessarily changed during rounding).
This occurs and signals rounded whenever the result of an operation is rounded (that is, some zero or non-zero digits were discarded from the coefficient), or if an overflow or underflow condition occurs. The result in all cases is unchanged.
The rounded signal may be tested (or trapped) to determine if a given operation (or sequence of operations) caused a loss of precision.
val subnormal : id
Exponent < Emin before rounding.
This occurs and signals subnormal whenever the result of a conversion or operation is subnormal (that is, its adjusted exponent is less than Emin, before any rounding). The result in all cases is unchanged. The subnormal signal may be tested (or trapped) to determine if a given or operation (or sequence of operations) yielded a subnormal result.
val overflow : id
Numerical overflow.
This occurs and signals overflow if the adjusted exponent of a result (from a conversion or from an operation that is not an attempt to divide by zero), after rounding, would be greater than the largest value that can be handled by the implementation (the value Emax).
The result depends on the rounding mode:
For round-half-up and round-half-even (and for round-half-down and round- up, if implemented), the result of the operation is sign,inf
, where sign is the sign of the intermediate result. For round-down, the result is the largest finite number that can be represented in the current precision, with the sign of the intermediate result. For round-ceiling, the result is the same as for round-down if the sign of the intermediate result is -
, or is Inf
otherwise. For round-floor, the result is the same as for round-down if the sign of the intermediate result is +
, or is -Inf
otherwise. In all cases, Inexact and Rounded will also be raised.
val underflow : id
Numerical underflow with result rounded to 0.
This occurs and signals underflow if a result is inexact and the adjusted exponent of the result would be smaller (more negative) than the smallest value that can be handled by the implementation (the value Emin). That is, the result is both inexact and subnormal.
The result after an underflow will be a subnormal number rounded, if necessary, so that its exponent is not less than Etiny. This may result in 0 with the sign of the intermediate result and an exponent of Etiny.
In all cases, Inexact, Rounded, and Subnormal will also be raised.