ada: Use truncation for dynamic conversions from floating point to fixed point
commit18a72d68c9daf72a5690be652fd1b0eb217035a2
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 29 Mar 2023 10:52:57 +0000 (29 12:52 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Fri, 26 May 2023 07:29:19 +0000 (26 09:29 +0200)
treed007b549010909ef0f5ac6d41ad927f53fc137d0
parent3e62561d5ffbb07fa97a4dddfd729fceb7cfce75
ada: Use truncation for dynamic conversions from floating point to fixed point

This changes the implementation of dynamic conversions from floating-point
to ordinary fixed-point types, from rounding (to the nearest number) to
truncation (toward zero), so as to make them consistent with both static
conversions between these types and also the value of the Machine_Rounds
attribute, which is False for all fixed-point types with GNAT.

The rounding is still available under the debug switch -gnatd.N for the
sake of backward compatibility with the previous implementation.

gcc/ada/

* debug.adb (d.N): Document new usage.
* exp_ch4.adb (Expand_N_Type_Conversion): Copy the Float_Truncate
flag when rewriting a floating-point to fixed-point conversion as
a floating-point to integer conversion.
* exp_fixd.adb: Add with and use clauses for Debug.
(Expand_Convert_Fixed_To_Fixed): Generate a truncation in all cases
except if the result is explicitly rounded.
(Expand_Convert_Integer_To_Fixed): Likewise.
(Expand_Convert_Float_To_Fixed): Generate a truncation for all kind
of fixed-point types, except if the result is explicitly rounded, or
-gnatd.N is specified and the type is an ordinary fixed-point type.
* sinfo.ads (Float_Truncate): Document usage for floating-point to
fixed-point conversions.
gcc/ada/debug.adb
gcc/ada/exp_ch4.adb
gcc/ada/exp_fixd.adb
gcc/ada/sinfo.ads