diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2024-11-26 21:20:08 +0100 |
---|---|---|
committer | Marc Poulhiès <dkm@gcc.gnu.org> | 2024-12-13 09:36:00 +0100 |
commit | 83b250bf58f681aff7a6856579cfd89e759b2a93 (patch) | |
tree | 78f242c1d454e8f9ea94b2e9f814cfa54f3eebfd /gcc/ada/libgnat | |
parent | 3ea199a18919585285745c1c71cf9cb53a17d689 (diff) | |
download | gcc-83b250bf58f681aff7a6856579cfd89e759b2a93.zip gcc-83b250bf58f681aff7a6856579cfd89e759b2a93.tar.gz gcc-83b250bf58f681aff7a6856579cfd89e759b2a93.tar.bz2 |
ada: Remove implicit assumption in the double case
The assumption is fulfilled in all the instantiations of the package, but
it should not be made in the generic code.
gcc/ada/ChangeLog:
* libgnat/s-imager.adb (Set_Image_Real): In the case where a double
integer is needed, do not implicit assume that it can contain up to
'Digits of the floating-point type.
Diffstat (limited to 'gcc/ada/libgnat')
-rw-r--r-- | gcc/ada/libgnat/s-imager.adb | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/gcc/ada/libgnat/s-imager.adb b/gcc/ada/libgnat/s-imager.adb index 89f9c1b..f304788 100644 --- a/gcc/ada/libgnat/s-imager.adb +++ b/gcc/ada/libgnat/s-imager.adb @@ -432,30 +432,39 @@ package body System.Image_R is -- Otherwise, do the conversion in two steps - else pragma Assert (X <= 10.0 ** Num'Digits * Num (Uns'Last)); + else declare - Y : constant Uns := To_Unsigned (X / Powten (Num'Digits)); + Halfdigs : constant Natural := Maxdigs / 2; - Buf : String (1 .. Num'Digits); + Buf : String (1 .. Halfdigs); Len : Natural; + Y : Uns; begin + -- Compute upper Halfdigs stripped from leading zeros + + Y := To_Unsigned (X / Powten (Halfdigs)); Set_Image_Unsigned (Y, Digs, Ndigs); - X := X - From_Unsigned (Y) * Powten (Num'Digits); + -- Compute lower Halfdigs stripped from leading zeros Len := 0; + X := X - From_Unsigned (Y) * Powten (Halfdigs); Set_Image_Unsigned (To_Unsigned (X), Buf, Len); + pragma Assert (Len <= Halfdigs); + + -- Concatenate unmodified upper part with zero-padded + -- lower part up to Halfdigs. - for J in 1 .. Num'Digits - Len loop + for J in 1 .. Halfdigs - Len loop Digs (Ndigs + J) := '0'; end loop; for J in 1 .. Len loop - Digs (Ndigs + Num'Digits - Len + J) := Buf (J); + Digs (Ndigs + Halfdigs - Len + J) := Buf (J); end loop; - Ndigs := Ndigs + Num'Digits; + Ndigs := Ndigs + Halfdigs; end; end if; end if; |