• Oddity with function returning image of fixed point type

    From Jesper Quorning@21:1/5 to All on Thu Sep 2 03:25:45 2021
    Is something odd going on here?
    I did not expect Image_Odd1/2 to return floating point images.


    with Ada.Text_Io; use Ada.Text_Io;

    procedure Fpt_Last is

    type Fpt is delta 0.01 digits 4;

    Image_Last : constant String := Fpt'Image (Fpt'Last);

    function Image_Ok return String is
    begin
    return Fpt'Last'Image;
    -- return Fpt'Image (Fpt'Last); -- Also ok
    end Image_Ok;

    Last : constant Fpt := Fpt'Last;

    function Image_Odd_1 return String is (Fpt'Last'Img);
    function Image_Odd_2 return String is (Fpt'Last'Image);
    function Image_Ok_2 return String is (Fpt'Image (FPT'Last));
    function Image_Ok_3 return String is (Last'Image);

    begin
    Put_Line ("Image_Last : " & Image_Last);
    Put_Line ("Image_Ok : " & Image_Ok);
    Put_Line ("Image_Odd_1 : " & Image_Odd_1);
    Put_Line ("Image_Odd_2 : " & Image_Odd_2);
    Put_Line ("Image_Ok_2 : " & Image_Ok_2);
    Put_Line ("Image_Ok_3 : " & Image_Ok_3);
    end Fpt_Last;


    Output:

    Image_Last : 99.99
    Image_Ok : 99.99
    Image_Odd_1 : 9.99900000000000000E+01
    Image_Odd_2 : 9.99900000000000000E+01
    Image_Ok_2 : 99.99
    Image_Ok_3 : 99.99

    Compiled with gnatmake version 10.3.0 or CE 2020 on macOS 10.13.6.


    /Jesper

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stephen Leake@21:1/5 to Jesper Quorning on Thu Sep 2 10:08:31 2021
    Jesper Quorning <jesper.quorning@gmail.com> writes:

    Is something odd going on here?
    I did not expect Image_Odd1/2 to return floating point images.

    Right, this looks like a compiler bug. LRM 3.5(13):

    S'Last
    S'Last denotes the upper bound of the range of S. The
    value of this attribute is of the type of S.

    But this is acting like Fpt'Last is universal_real.

    --
    -- Stephe

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dmitry A. Kazakov@21:1/5 to Stephen Leake on Thu Sep 2 19:32:57 2021
    On 2021-09-02 19:08, Stephen Leake wrote:
    Jesper Quorning <jesper.quorning@gmail.com> writes:

    Is something odd going on here?
    I did not expect Image_Odd1/2 to return floating point images.

    Right, this looks like a compiler bug. LRM 3.5(13):

    S'Last
    S'Last denotes the upper bound of the range of S. The
    value of this attribute is of the type of S.

    But this is acting like Fpt'Last is universal_real.

    No, it is this:

    LRM 4.10 (40/5)

    "X'Image denotes the result of calling function S'Image with Arg being
    X, where S is the nominal subtype of X."

    The question is what is the nominal subtype of Fpt'Last.

    --
    Regards,
    Dmitry A. Kazakov
    http://www.dmitry-kazakov.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jesper Quorning@21:1/5 to All on Thu Sep 2 16:24:05 2021
    torsdag den 2. september 2021 kl. 19.33.00 UTC+2 skrev Dmitry A. Kazakov:
    On 2021-09-02 19:08, Stephen Leake wrote:
    Jesper Quorning <jesper....@gmail.com> writes:

    Is something odd going on here?
    I did not expect Image_Odd1/2 to return floating point images.

    Right, this looks like a compiler bug. LRM 3.5(13):

    S'Last
    S'Last denotes the upper bound of the range of S. The
    value of this attribute is of the type of S.

    But this is acting like Fpt'Last is universal_real.

    No, it is this:

    LRM 4.10 (40/5)
    Had to go back to Ada 83 LRM to find a chapter 4.10.

    "X'Image denotes the result of calling function S'Image with Arg being
    X, where S is the nominal subtype of X."
    LRM 3.5 (35-36) says about the same.

    The question is what is the nominal subtype of Fpt'Last.

    Well Image_Ok and Image_Odd_2 should both return Fpt'Last'Image so one of them must be bad.

    Found LRM 3.5 (27.7/2) describing the image of a fixed point type.

    Thanks for your responses. I will report the issue.

    /Jesper

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)