TorchLean API

FloatLib.Floats.Formats.DecimalInterchange.Conversion.Integer.Runtime

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 explicit-direction operations 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 instead raises invalid. This binding documents integer zero as its default invalid delivery and reports invalid explicitly in the result status.

Signed destinations use the existing 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.

@[reducible, inline]

Signedness and width are independent of the decimal source format.

Instances For

    An integer result and the flags raised by this conversion alone.

    • value :

      The rounded integer when valid, or zero for this binding's invalid delivery.

    • status : Status

      Flags raised by this operation alone; successful exact variants may raise inexact.

    Instances For

      Round an exact rational once to the integer grid, with sign-sensitive directed rounding.

      Instances For

        This binding's invalid integer result is zero, with only the invalid flag set.

        Instances For

          Shared conversion kernel. signalInexact selects exact versus quiet conversion; it does not change the rounding direction or the delivered integer.

          Instances For
            @[reducible, inline]

            Nearest integer, ties to even; suppress inexact, but report invalid conversion.

            Instances For
              @[reducible, inline]

              Nearest integer, ties away from zero; suppress inexact, but report invalid conversion.

              Instances For
                @[reducible, inline]

                Round toward zero; suppress inexact, but report invalid conversion.

                Instances For
                  @[reducible, inline]

                  Round toward positive infinity; suppress inexact, but report invalid conversion.

                  Instances For
                    @[reducible, inline]

                    Round toward negative infinity; suppress inexact, but report invalid conversion.

                    Instances For
                      @[reducible, inline]

                      Nearest integer, ties to even; report inexact precisely when a valid result changes value.

                      Instances For
                        @[reducible, inline]

                        Nearest integer, ties away from zero; report inexact on a valid numerical change.

                        Instances For
                          @[reducible, inline]

                          Round toward zero; report inexact on a valid numerical change.

                          Instances For
                            @[reducible, inline]

                            Round toward positive infinity; report inexact on a valid numerical change.

                            Instances For
                              @[reducible, inline]

                              Round toward negative infinity; report inexact on a valid numerical change.

                              Instances For

                                Convert an arbitrary signed integer directly 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 existing fixed-width carrier, retaining its status. The conversion has already checked the range; packing does not implement wraparound conversion.

                                      Instances For

                                        Pack an unsigned conversion after its range check.

                                        Instances For