s-imgrea.adb (Image_Floating_Point): Don't add space before +Inf.
authorRobert Dewar <dewar@adacore.com>
Mon, 4 Aug 2014 08:09:31 +0000 (08:09 +0000)
committerArnaud Charlet <charlet@gcc.gnu.org>
Mon, 4 Aug 2014 08:09:31 +0000 (10:09 +0200)
2014-08-04  Robert Dewar  <dewar@adacore.com>

* s-imgrea.adb (Image_Floating_Point): Don't add space before +Inf.
* s-fatgen.adb (Pred): Handle Float'First.
(Succ): Handle Float'Last.

From-SVN: r213539

gcc/ada/ChangeLog
gcc/ada/s-fatgen.adb
gcc/ada/s-imgrea.adb

index b797f135baf883c315716ac9487bd891a72ddfb0..985c915be826b8eebc79028ce04d88484f160095 100644 (file)
@@ -1,3 +1,9 @@
+2014-08-04  Robert Dewar  <dewar@adacore.com>
+
+       * s-imgrea.adb (Image_Floating_Point): Don't add space before +Inf.
+       * s-fatgen.adb (Pred): Handle Float'First.
+       (Succ): Handle Float'Last.
+
 2014-08-04  Ed Schonberg  <schonberg@adacore.com>
 
        * sem_util.adb (Is_Potentially_Unevaluated): If the original
index 01bb2b44a973207dad0ffb45a339c163108d8411..be564cf6a0e223fd4093b1f0bc1758306e1e1896 100644 (file)
@@ -401,22 +401,37 @@ package body System.Fat_Gen is
    -- Pred --
    ----------
 
-   --  Subtract from the given number a number equivalent to the value of its
-   --  least significant bit. Given that the most significant bit represents
-   --  a value of 1.0 * radix ** (exp - 1), the value we want is obtained by
-   --  shifting this by (mantissa-1) bits to the right, i.e. decreasing the
-   --  exponent by that amount.
-
-   --  Zero has to be treated specially, since its exponent is zero
-
    function Pred (X : T) return T is
       X_Frac : T;
       X_Exp  : UI;
 
    begin
+      --  Zero has to be treated specially, since its exponent is zero
+
       if X = 0.0 then
          return -Succ (X);
 
+      --  Special treatment for most negative number
+
+      elsif X = T'First then
+
+         --  If not generating infinities, we raise a constraint error
+
+         if T'Machine_Overflows then
+            raise Constraint_Error with "Pred of largest negative number";
+
+         --  Otherwise generate a negative infinity
+
+         else
+            return X / (X - X);
+         end if;
+
+      --  Subtract from the given number a number equivalent to the value
+      --  of its least significant bit. Given that the most significant bit
+      --  represents a value of 1.0 * radix ** (exp - 1), the value we want
+      --  is obtained by shifting this by (mantissa-1) bits to the right,
+      --  i.e. decreasing the exponent by that amount.
+
       else
          Decompose (X, X_Frac, X_Exp);
 
@@ -624,17 +639,14 @@ package body System.Fat_Gen is
    -- Succ --
    ----------
 
-   --  Similar computation to that of Pred: find value of least significant
-   --  bit of given number, and add. Zero has to be treated specially since
-   --  the exponent can be zero, and also we want the smallest denormal if
-   --  denormals are supported.
-
    function Succ (X : T) return T is
       X_Frac : T;
       X_Exp  : UI;
       X1, X2 : T;
 
    begin
+      --  Treat zero specially since it has a zero exponent
+
       if X = 0.0 then
          X1 := 2.0 ** T'Machine_Emin;
 
@@ -648,6 +660,27 @@ package body System.Fat_Gen is
 
          return X1;
 
+      --  Special treatment for largest positive number
+
+      elsif X = T'Last then
+
+         --  If not generating infinities, we raise a constraint error
+
+         if T'Machine_Overflows then
+            raise Constraint_Error with "Succ of largest negative number";
+
+         --  Otherwise generate a positive infinity
+
+         else
+            return X / (X - X);
+         end if;
+
+      --  Add to the given number a number equivalent to the value
+      --  of its least significant bit. Given that the most significant bit
+      --  represents a value of 1.0 * radix ** (exp - 1), the value we want
+      --  is obtained by shifting this by (mantissa-1) bits to the right,
+      --  i.e. decreasing the exponent by that amount.
+
       else
          Decompose (X, X_Frac, X_Exp);
 
index fcfd107dd0327f6fb2a38bec6f4dcc4e471bbb09..075a5774000d3e1974161d432ca0e022aa2fea2e 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2013, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2014, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -93,9 +93,10 @@ package body System.Img_Real is
       --  output of -0.0 on targets where this is the case). We can of
       --  course still see a -0.0 on a target where Signed_Zeroes is
       --  False (since this attribute refers to the proper handling of
-      --  negative zeroes, not to their existence).
+      --  negative zeroes, not to their existence). We do not generate
+      --  a blank for positive infinity, since we output an explicit +.
 
-      if not Is_Negative (V)
+      if (not Is_Negative (V) and then V <= Long_Long_Float'Last)
         or else (not Long_Long_Float'Signed_Zeros and then V = -0.0)
       then
          S (1) := ' ';