]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix rounding test with odd bases
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 2 Apr 2025 11:13:33 +0000 (13:13 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 12 Jun 2025 08:37:54 +0000 (10:37 +0200)
The test as currently written is incorrect for odd bases.

gcc/ada/ChangeLog:

* libgnat/s-valuer.adb (Round_Extra): Use multiplicative test.

gcc/ada/libgnat/s-valuer.adb

index 6f557e93207979ed1c1227ec0175b8bb75dc596a..93e292cc34f47237360935cc13940c3542701f5b 100644 (file)
@@ -135,7 +135,9 @@ package body System.Value_R is
       B : constant Uns := Uns (Base);
 
    begin
-      if Digit >= Base / 2 then
+      --  Beware that Base may be odd
+
+      if 2 * Unsigned (Digit) >= Base then
 
          --  If Extra is maximum, round Value