TorchLean API

FloatLib.Floats.Formats.DecimalInterchange.Conversion.Binary.Runtime

Numeric conversion between binary and decimal interchange #

Both directions evaluate the finite input exactly as a rational before rounding once to the destination. Binary-to-decimal conversion prefers quantum zero on an exact result, so it selects the representable cohort member whose quantum is closest to zero. For an inexact result, decimal projection supplies the least quantum. Decimal-to-binary conversion uses the binary rational kernels. Nearest-away first rounds the exact rational to the destination binary grid, then encodes that dyadic with the binary encoder.

Zeros and infinities retain their signs. NaNs are quieted and raise invalid exactly when signaling. The diagnostic payload is interpreted as a natural number: it is preserved when it fits the destination, otherwise replaced by zero. This is a payload-selection policy, not a claim that IEEE 754 specifies a unique payload when narrowing.

Decimal destinations use tininess before rounding. Binary destinations use the library convention: tininess after rounding to the destination precision with an unbounded exponent range. The constants for the binary midpoint and predecessor are shared with the scalar status implementation.

References #

Extract the diagnostic payload of an IEEE binary NaN, excluding its quiet bit.

Instances For

    Convert a binary model to a decimal datum. Exact finite results prefer quantum zero, and a zero keeps its source sign. Custom binary models convert through their descriptors, but the IEEE class guarantees hold only for IEEE source formats.

    Instances For

      Encode a quiet binary NaN with its sign and a fitting natural-number payload. toBinary uses this only for an IEEE destination.

      Instances For

        Binary grid exponent for a rational magnitude, bounded below by the subnormal quantum.

        Instances For

          Round to nearest, ties away, on the destination's binary grid. The significand can reach 2^precision after a carry, and that value is still representable unless it overflows.

          Instances For

            Round a sign and a nonnegative rational magnitude, as toBinary supplies them, into the binary destination.

            Instances For

              Whether a directed conversion increases a nonzero magnitude. Nearest modes use midpoint rules and give false here.

              Instances For

                IEEE overflow test: the precision-rounded unbounded result against the exponent limit. The largest finite significand of an IEEE binary layout is odd, so both nearest modes overflow at the upper midpoint itself.

                Instances For

                  Tininess after precision rounding, including exact values that deliver the smallest normal but whose rounding with an unbounded exponent range is still tiny.

                  Instances For

                    Default binary conversion flags, using exact rational comparisons. Invalid and divide-by-zero are absent on the finite path. Overflow always raises inexact.

                    Instances For

                      Ternary value of a binary conversion: the delivered value compared with the exact signed rational, read through toRat? like the inexact flag of binaryStatus. A non-finite delivery is an overflow and compares by the sign of the exact value.

                      Instances For

                        Convert a decimal datum to an IEEE binary destination in any of the five rounding directions. The IEEE descriptor proof excludes finite-only exceptional-value policies. Finite input coefficients and quantum exponents are evaluated exactly, so the source decimal cohort does not affect the binary result. The ternary value compares the delivered value with the exact decimal value, and infinities and NaNs have .eq.

                        Instances For