* [Ada] Incorrect values in conversion from fixed-point subtype with 'Small
@ 2019-07-22 14:02 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2019-07-22 14:02 UTC (permalink / raw)
To: gcc-patches; +Cc: Ed Schonberg
[-- Attachment #1: Type: text/plain, Size: 1473 bytes --]
This patch fixes incorrect computations involving a fixed-point subtype
whose parent type has an aspect specification for 'Small.
Executing the following:
gnatmake -q conv
./conv
must yield:
9000.000000
9.00000000000000E+03
9000.000000
9.00000000000000E+03
9.00000000000000E+03
9.00000000000000E+03
9.00000000000000E+03
9.00000000000000E+03
----
with Text_IO; use Text_IO;
procedure Conv is
V_P : constant := 10.0 ** (-6);
M_V : constant := 9000.0;
N_V : constant := -9000.0;
type V_T is delta V_P range N_V .. M_V with Small => V_P;
subtype S_T is V_T range 0.0 .. M_V;
function Convert (Input : in S_T) return Long_Float is
begin
Put_Line (Input'Img);
Put_Line (Long_Float'Image (Long_Float (Input)));
return Long_Float (Input);
end Convert;
begin
declare
Var_S : constant S_T := S_T'Last;
Output : constant Long_Float := Convert (Var_S);
begin
Put_Line (Long_Float'Image (Convert (Var_S)));
Put_Line (Long_Float'Image (Long_Float (Var_S)));
Put_Line (Output'Img);
end;
Put_Line (Long_Float'Image (Long_Float (S_T'Last)));
end Conv;
Tested on x86_64-pc-linux-gnu, committed on trunk
2019-07-22 Ed Schonberg <schonberg@adacore.com>
gcc/ada/
* freeze.adb (Freeze_Fixed_Point_Type): When freezing a
fixed-point subtype, check whether the parent type declarastion
includes an aspect specification for the 'Small type attribute,
and inherit the specified value.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1034 bytes --]
--- gcc/ada/freeze.adb
+++ gcc/ada/freeze.adb
@@ -8003,6 +8003,7 @@ package body Freeze is
Brng : constant Node_Id := Scalar_Range (Btyp);
BLo : constant Node_Id := Low_Bound (Brng);
BHi : constant Node_Id := High_Bound (Brng);
+ Par : constant Entity_Id := First_Subtype (Typ);
Small : constant Ureal := Small_Value (Typ);
Loval : Ureal;
Hival : Ureal;
@@ -8055,6 +8056,16 @@ package body Freeze is
end if;
end if;
+ -- The 'small attribute may have been specified with an aspect,
+ -- in which case it is processed after a subtype declaration, so
+ -- inherit now the specified value.
+
+ if Typ /= Par
+ and then Present (Find_Aspect (Par, Aspect_Small))
+ then
+ Set_Small_Value (Typ, Small_Value (Par));
+ end if;
+
-- Immediate return if the range is already analyzed. This means that
-- the range is already set, and does not need to be computed by this
-- routine.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-07-22 14:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-22 14:02 [Ada] Incorrect values in conversion from fixed-point subtype with 'Small Pierre-Marie de Rodat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).