diff options
author | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-08-04 08:09:31 +0000 |
---|---|---|
committer | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-08-04 08:09:31 +0000 |
commit | e00420a65724457eda04f056f4d38454b6d9c68d (patch) | |
tree | 13efdf4ce1f9572139eb45845f4cef3eb107141e /gcc/ada/s-fatgen.adb | |
parent | ed10407c3fe4ea5d6b7cc9e998e613960cd6e2a7 (diff) | |
download | gcc-e00420a65724457eda04f056f4d38454b6d9c68d.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@213539 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/s-fatgen.adb')
-rw-r--r-- | gcc/ada/s-fatgen.adb | 59 |
1 files changed, 46 insertions, 13 deletions
diff --git a/gcc/ada/s-fatgen.adb b/gcc/ada/s-fatgen.adb index 01bb2b44a97..be564cf6a0e 100644 --- a/gcc/ada/s-fatgen.adb +++ b/gcc/ada/s-fatgen.adb @@ -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); |