1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- S Y S T E M . E X N _ L L F --
9 -- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 -- Note: the reason for treating exponents in the range 0 .. 4 specially is
33 -- to ensure identical results to the static inline expansion in the case of
34 -- a compile time known exponent in this range. The use of Float'Machine and
35 -- Long_Float'Machine is to avoid unwanted extra precision in the results.
37 package body System
.Exn_LLF
is
40 (Left
: Long_Long_Float;
41 Right
: Integer) return Long_Long_Float;
42 -- Common routine used if Right not in 0 .. 4
50 Right
: Integer) return Float
60 return Float'Machine (Left
* Left
);
62 return Float'Machine (Left
* Left
* Left
);
64 Temp
:= Float'Machine (Left
* Left
);
65 return Float'Machine (Temp
* Temp
);
69 (Float (Exp
(Long_Long_Float (Left
), Right
)));
77 function Exn_Long_Float
79 Right
: Integer) return Long_Float
89 return Long_Float'Machine (Left
* Left
);
91 return Long_Float'Machine (Left
* Left
* Left
);
93 Temp
:= Long_Float'Machine (Left
* Left
);
94 return Long_Float'Machine (Temp
* Temp
);
98 (Long_Float (Exp
(Long_Long_Float (Left
), Right
)));
102 -------------------------
103 -- Exn_Long_Long_Float --
104 -------------------------
106 function Exn_Long_Long_Float
107 (Left
: Long_Long_Float;
108 Right
: Integer) return Long_Long_Float
110 Temp
: Long_Long_Float;
120 return Left
* Left
* Left
;
125 return Exp
(Left
, Right
);
127 end Exn_Long_Long_Float
;
134 (Left
: Long_Long_Float;
135 Right
: Integer) return Long_Long_Float
137 Result
: Long_Long_Float := 1.0;
138 Factor
: Long_Long_Float := Left
;
139 Exp
: Integer := Right
;
142 -- We use the standard logarithmic approach, Exp gets shifted right
143 -- testing successive low order bits and Factor is the value of the
144 -- base raised to the next power of 2. If the low order bit or Exp is
145 -- set, multiply the result by this factor. For negative exponents,
146 -- invert result upon return.
150 if Exp
rem 2 /= 0 then
151 Result
:= Result
* Factor
;
156 Factor
:= Factor
* Factor
;
161 -- Here we have a negative exponent, and we compute the result as:
163 -- 1.0 / (Left ** (-Right))
165 -- Note that the case of Left being zero is not special, it will
166 -- simply result in a division by zero at the end, yielding a
167 -- correctly signed infinity, or possibly generating an overflow.
169 -- Note on overflow: The coding of this routine assumes that the
170 -- target generates infinities with standard IEEE semantics. If this
171 -- is not the case, then the code below may raise Constraint_Error.
172 -- This follows the implementation permission given in RM 4.5.6(12).
177 if Exp
rem 2 /= 0 then
178 Result
:= Result
* Factor
;
183 Factor
:= Factor
* Factor
;