Decimal conversions to and from integers #
IEEE 754-2019 §§5.4.1, 5.8 and 7.2(j) require rounding to an integer before checking its destination range. In particular, a negative fraction can convert to unsigned zero, and a value just outside an endpoint can round into range.
The ten operations, one per direction and exactness, share the exact coefficient
rounder used by decimal integral rounding. No intervening decimal precision rounding
occurs. The Exact variants signal inexact only on successful conversion. Every NaN,
infinity, or rounded integer outside the destination range raises invalid instead,
and the invalid result is integer zero.
Signed destinations use the two's-complement FixedInt bounds.
Unsigned destinations use the range of BitVec. Width zero denotes only zero
in both cases. Integer sources have no signed zero and therefore convert to +0.
Integer destination format, whose signedness and width do not depend on the decimal source.
Instances For
An integer result and the flags raised by this conversion alone.
- value : ℤ
The rounded integer when valid, or zero when the conversion is invalid.
- status : Numerics.IEEEStatus
Flags raised by this operation alone. A successful
Exactvariant may raise inexact.
Instances For
Instances For
Round an exact rational once to the integer grid, with sign-sensitive directed rounding.
Instances For
Invalid result: integer zero with only the invalid flag set.
Instances For
Shared conversion kernel. signalInexact selects exact or quiet conversion and changes
neither the rounding direction nor the delivered integer.
Instances For
Convert to the nearest integer, ties to even. Never raises inexact, and raises invalid only for a nonfinite input or a rounded result outside the destination range.
Instances For
Convert to the nearest integer, ties away from zero. Never raises inexact, and raises invalid only for a nonfinite input or a rounded result outside the destination range.
Instances For
Convert toward zero. Never raises inexact, and raises invalid only for a nonfinite input or a rounded result outside the destination range.
Instances For
Convert toward positive infinity. Never raises inexact, and raises invalid only for a nonfinite input or a rounded result outside the destination range.
Instances For
Convert toward negative infinity. Never raises inexact, and raises invalid only for a nonfinite input or a rounded result outside the destination range.
Instances For
Convert to the nearest integer, ties to even, raising inexact when a valid result changes.
Instances For
Convert to the nearest integer, ties away, raising inexact when a valid result changes.
Instances For
Convert toward zero, raising inexact when a valid result changes value.
Instances For
Convert toward positive infinity, raising inexact when a valid result changes value.
Instances For
Convert toward negative infinity, raising inexact when a valid result changes value.
Instances For
Convert an arbitrary signed integer to a decimal destination, with preferred quantum zero and one destination rounding (§5.4.1).
Instances For
Convert a two's-complement source by its exact signed value.
Instances For
Convert an unsigned word by its exact nonnegative value.
Instances For
Pack a signed conversion into the fixed-width carrier, keeping its status. The conversion has already checked the range, so packing never wraps around.
Instances For
Pack an unsigned conversion after its range check.