public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-1520] [Ada] Fix floating-point exponentiation with Integer'First exponent
Date: Wed, 16 Jun 2021 08:46:04 +0000 (GMT)	[thread overview]
Message-ID: <20210616084604.BB5C7398A429@sourceware.org> (raw)

https://gcc.gnu.org/g:f4fe186bfe3e74c7c9b2d49b635565ea9a4df1b2

commit r12-1520-gf4fe186bfe3e74c7c9b2d49b635565ea9a4df1b2
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Wed Mar 3 20:15:42 2021 +0100

    [Ada] Fix floating-point exponentiation with Integer'First exponent
    
    gcc/ada/
    
            * urealp.adb (Scale): Change first paramter to Uint and adjust.
            (Equivalent_Decimal_Exponent): Pass U.Den directly to Scale.
            * libgnat/s-exponr.adb (Negative): Rename to...
            (Safe_Negative): ...this and change its lower bound.
            (Exponr): Adjust to above renaming and deal with Integer'First.

Diff:
---
 gcc/ada/libgnat/s-exponr.adb |  9 ++++++---
 gcc/ada/urealp.adb           | 10 ++++------
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/gcc/ada/libgnat/s-exponr.adb b/gcc/ada/libgnat/s-exponr.adb
index ece53b51a39..ad7f40188dd 100644
--- a/gcc/ada/libgnat/s-exponr.adb
+++ b/gcc/ada/libgnat/s-exponr.adb
@@ -57,8 +57,8 @@ function System.Exponr (Left : Num; Right : Integer) return Num is
    subtype Double_T is Double_Real.Double_T;
    --  The double floating-point type
 
-   subtype Negative is Integer range Integer'First .. -1;
-   --  The range of negative exponents
+   subtype Safe_Negative is Integer range Integer'First + 1 .. -1;
+   --  The range of safe negative exponents
 
    function Expon (Left : Num; Right : Natural) return Num;
    --  Routine used if Right is greater than 4
@@ -113,9 +113,12 @@ begin
             return Num'Machine (Sqr * Sqr);
          end;
 
-      when Negative =>
+      when Safe_Negative =>
          return Num'Machine (1.0 / Exponr (Left, -Right));
 
+      when Integer'First =>
+         return Num'Machine (1.0 / (Exponr (Left, Integer'Last) * Left));
+
       when others =>
          return Num'Machine (Expon (Left, Right));
    end case;
diff --git a/gcc/ada/urealp.adb b/gcc/ada/urealp.adb
index 59d5c08f322..0f57043ffcd 100644
--- a/gcc/ada/urealp.adb
+++ b/gcc/ada/urealp.adb
@@ -270,23 +270,21 @@ package body Urealp is
         15 => (Num =>  53_385_559, Den =>   45_392_361),  -- 1.176091259055681
         16 => (Num =>  78_897_839, Den =>   65_523_237)); -- 1.204119982655924
 
-      function Scale (X : Int; R : Ratio) return Int;
+      function Scale (X : Uint; R : Ratio) return Int;
       --  Compute the value of X scaled by R
 
       -----------
       -- Scale --
       -----------
 
-      function Scale (X : Int; R : Ratio) return Int is
-         type Wide_Int is range -2**63 .. 2**63 - 1;
-
+      function Scale (X : Uint; R : Ratio) return Int is
       begin
-         return Int (Wide_Int (X) * Wide_Int (R.Num) / Wide_Int (R.Den));
+         return UI_To_Int (X * R.Num / R.Den);
       end Scale;
 
    begin
       pragma Assert (U.Rbase /= 0);
-      return Scale (UI_To_Int (U.Den), Logs (U.Rbase));
+      return Scale (U.Den, Logs (U.Rbase));
    end Equivalent_Decimal_Exponent;
 
    ----------------


                 reply	other threads:[~2021-06-16  8:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210616084604.BB5C7398A429@sourceware.org \
    --to=pmderodat@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).