-- d.K Do not reject components in extensions overlapping with parent
-- d.L Depend on back end for limited types in if and case expressions
-- d.M Relaxed RM semantics
- -- d.N
+ -- d.N Use rounding when converting from floating point to fixed point
-- d.O Dump internal SCO tables
-- d.P Previous (non-optimized) handling of length comparisons
-- d.Q Previous (incomplete) style check for binary operators
-- d.M Relaxed RM semantics. This flag sets Opt.Relaxed_RM_Semantics
-- See Opt.Relaxed_RM_Semantics for more details.
+ -- d.N Use rounding instead of truncation when dynamically converting from
+ -- a floating-point type to an ordinary fixed-point type, for the sake
+ -- of compatibility with earlier versions of the compiler.
+
-- d.O Dump internal SCO tables. Before outputting the SCO information to
-- the ALI file, the internal SCO tables (SCO_Table/SCO_Unit_Table)
-- are dumped for debugging purposes.
Expr_Id : constant Entity_Id := Make_Temporary (Loc, 'T', Conv);
Int_Typ : constant Entity_Id :=
Small_Integer_Type_For (RM_Size (Btyp), Uns => False);
+ Trunc : constant Boolean := Float_Truncate (Conv);
begin
+ Conv := Convert_To (Int_Typ, Expression (Conv));
+ Set_Float_Truncate (Conv, Trunc);
+
-- Generate a temporary with the integer value. Required in the
-- CCG compiler to ensure that run-time checks reference this
-- integer expression (instead of the resulting fixed-point
Defining_Identifier => Expr_Id,
Object_Definition => New_Occurrence_Of (Int_Typ, Loc),
Constant_Present => True,
- Expression =>
- Convert_To (Int_Typ, Expression (Conv))));
+ Expression => Conv));
-- Create integer objects for range checking of result.
with Atree; use Atree;
with Checks; use Checks;
+with Debug; use Debug;
with Einfo; use Einfo;
with Einfo.Entities; use Einfo.Entities;
with Einfo.Utils; use Einfo.Utils;
-- Fall through to use floating-point for the close result set case,
-- as a result of the numerator or denominator of the small ratio not
- -- being a sufficiently small integer.
+ -- being sufficiently small. See also Expand_Convert_Float_To_Fixed.
Set_Result (N,
Build_Multiply (N,
Fpt_Value (Expr),
Real_Literal (N, Small_Ratio)),
- Rng_Check);
+ Rng_Check,
+ Trunc => not Rounded_Result (N));
end Expand_Convert_Fixed_To_Fixed;
-----------------------------------
if Small = Ureal_1 then
Set_Result (N, Expr, Rng_Check, Trunc => True);
- -- Normal case where multiply is required. Rounding is truncating
- -- for decimal fixed point types only, see RM 4.6(29), except if the
- -- conversion comes from an attribute reference 'Round (RM 3.5.10 (14)):
- -- The attribute is implemented by means of a conversion that must
- -- round.
+ -- Normal case where multiply is required. The conversion is truncating
+ -- for fixed-point types, see RM 4.6(29), except if the conversion comes
+ -- from an attribute reference 'Round (RM 3.5.10 (14)): the attribute is
+ -- implemented by means of a conversion that needs to round. However, if
+ -- the switch -gnatd.N is specified, we use rounding for ordinary fixed-
+ -- point types, for compatibility with earlier versions of the compiler.
else
- Set_Result
- (N => N,
- Expr =>
- Build_Multiply
- (N => N,
- L => Fpt_Value (Expr),
- R => Real_Literal (N, Ureal_1 / Small)),
- Rchk => Rng_Check,
- Trunc => Is_Decimal_Fixed_Point_Type (Result_Type)
- and not Rounded_Result (N));
+ Set_Result (N,
+ Build_Multiply (N,
+ L => Fpt_Value (Expr),
+ R => Real_Literal (N, Ureal_1 / Small)),
+ Rchk => Rng_Check,
+ Trunc => not Rounded_Result (N)
+ and then not
+ (Debug_Flag_Dot_NN
+ and then Is_Ordinary_Fixed_Point_Type (Result_Type)));
end if;
end Expand_Convert_Float_To_Fixed;
-- Fall through to use floating-point for the close result set case,
-- as a result of the numerator or denominator of the small value not
- -- being a sufficiently small integer.
+ -- being sufficiently small. See also Expand_Convert_Float_To_Fixed.
Set_Result (N,
Build_Multiply (N,
Fpt_Value (Expr),
Real_Literal (N, Ureal_1 / Small)),
- Rng_Check);
+ Rng_Check,
+ Trunc => not Rounded_Result (N));
end Expand_Convert_Integer_To_Fixed;
--------------------------------