[Ada] Fix rounding of fixed-point arithmetic operation
authorYannick Moy <moy@adacore.com>
Tue, 17 Sep 2019 08:02:56 +0000 (08:02 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Tue, 17 Sep 2019 08:02:56 +0000 (08:02 +0000)
commite34716b8dd8836a565b4cf0c26f7244161f194f1
tree65a5f634701b28725bcded695f9b90b8a2b74351
parent0d4fcc9f622ee428849091c51108a4823819e9a6
[Ada] Fix rounding of fixed-point arithmetic operation

Fixed-point multiplication, division and conversion may lead to calling
the function Double_Divide in s-arit64 runtime unit. In the special case
where arguments have the special values X = -2**63 and the absolute
value of the product of its other arguments Y*Z = 2**64, the rounded
value should be either -1 or 1, but currently Double_Divide returns a
quotient of 0.

Rounding only applies when Round attribute is called on the arithmetic
operation for a decimal fixed-point result, or the result type is
integer.

This fixes correctly applies rounding away from 0 in that special case.

2019-09-17  Yannick Moy  <moy@adacore.com>

gcc/ada/

* libgnat/s-arit64.adb (Double_Divide): Correctly handle the
special case when rounding.

gcc/testsuite/

* gnat.dg/fixedpnt7.adb: New testcase.

From-SVN: r275796
gcc/ada/ChangeLog
gcc/ada/libgnat/s-arit64.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/fixedpnt7.adb [new file with mode: 0644]