AI22-0078-1

!standard A.5.7(14/5)                                    23-06-05  AI22-0078-1/01

!standard A.5.7(24/5)

!class Binding Interpretation 23-06-05

!status Amendment 1-2022  23-06-27

!status WG9 Approved 23-10-12

!status ARG Approved  6-0-1  23-06-11

!status work item 23-06-05

!status received 23-06-05

!submitter Tucker Taft (on behalf of a colleague)

!priority Low

!difficulty Easy

!qualifier Omission

!subject Decimal conversions for Big_Reals

!summary

A Decimal_Conversions generic is added to Big_Reals.

!issue

Big_Numbers.Big_Reals has generics for converting to floating point and ordinary fixed point, but not for decimal fixed point. In other places in the standard where we have a generic for both floating point and ordinary fixed, we generally include an analogous generic for decimal fixed point (for example, Text_IO).

!recommendation

Add a Decimal_Conversions generic to Ada.Big_Numbers.Big_Reals.

!wording

Add after A.5.7(14/5):

   generic
      type Num is delta <> digits <>;
   package Decimal_Conversions is
      function To_Big_Real (Arg : Num) return Valid_Big_Real;
      function From_Big_Real (Arg : Valid_Big_Real) return Num
         with Pre => In_Range (Arg,
                               Low  => To_Big_Real (Num'First),
                               High => To_Big_Real (Num'Last))
                     or else (raise Constraint_Error);
   end Decimal_Conversions;

Modify A.5.7(24/5):

For an instance of Float_Conversions{,}[ or] Fixed_Conversions{, or Decimal_Conversions}, To_Big_Real is exact (that is, the result represents exactly the same mathematical value as the argument) and From_Big_Real is subject to the same precision rules as a type conversion of a value of type T to the target type Num, where T is a hypothetical floating point type whose model numbers include all of the model numbers of Num as well as the exact mathematical value of the argument.

!discussion

This does seem like an oversight. Probably someone forgot that decimal types do not match

ordinary fixed point formals.

!corrigendum A.5.7(14/5)

@dinsa

@xcode{   @b{generic}

      @b{type} Num @b{is delta} <>;

   @b{package} Fixed_Conversions @b{is}

      @b{function} To_Big_Real (Arg : Num) @b{return} Valid_Big_Real;

      @b{function} From_Big_Real (Arg : Valid_Big_Real) @b{return} Num

         @b{with} Pre => In_Range (Arg,

                               Low  => To_Big_Real (Num'First),

                               High => To_Big_Real (Num'Last))

                     @b{or else} (@b{raise} Constraint_Error);

   @b{end} Fixed_Conversions;}

@dinst

@xcode{   @b{generic}
     @b{type} Num @b{is delta} <> @b{digits} <>;
  @b{package} Decimal_Conversions @b{is}
     @b{function} To_Big_Real (Arg : Num) @b{return} Valid_Big_Real;
     @b{function} From_Big_Real (Arg : Valid_Big_Real) @b{return} Num
        @b{with} Pre => In_Range (Arg,
                              Low  => To_Big_Real (Num'First),
                              High => To_Big_Real (Num'Last))
                    @b{or else} (@b{raise} Constraint_Error);
  @b{end} Decimal_Conversions;}

!corrigendum A.5.7(24/5)

@drepl

For an instance of Float_Conversions or Fixed_Conversions, To_Big_Real is exact (that is, the result represents exactly the same mathematical value as the argument) and From_Big_Real is subject to the same precision rules as a type conversion of a value of type T to the target type Num, where T is a hypothetical floating point type whose model numbers include all of the model numbers of Num as well as the exact mathematical value of the argument.

@dby

For an instance of Float_Conversions, Fixed_Conversions, or Decimal_Conversions, To_Big_Real is exact (that is, the result represents exactly the same mathematical value as the argument) and From_Big_Real is subject to the same precision rules as a type conversion of a value of type T to the target type Num, where T is a hypothetical floating point type whose model numbers include all of the model numbers of Num as well as the exact mathematical value of the argument.

!ACATS test

An ACATS C-Test should check that the generic exists and operates as expected.

!appendix

This AI is associated with Github Issue #39 (https://github.com/Ada-Rapporteur-Group/User-Community-Input/issues/39).

********************************************************************************