1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- S Y S T E M . E X N _ L L F --
9 -- Copyright (C) 1992-2009 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 package body System
.Exn_LLF
is
34 -------------------------
35 -- Exn_Long_Long_Float --
36 -------------------------
38 function Exn_Long_Long_Float
39 (Left
: Long_Long_Float;
41 return Long_Long_Float
43 Result
: Long_Long_Float := 1.0;
44 Factor
: Long_Long_Float := Left
;
45 Exp
: Integer := Right
;
48 -- We use the standard logarithmic approach, Exp gets shifted right
49 -- testing successive low order bits and Factor is the value of the
50 -- base raised to the next power of 2. If the low order bit or Exp is
51 -- set, multiply the result by this factor. For negative exponents,
52 -- invert result upon return.
56 if Exp
rem 2 /= 0 then
57 Result
:= Result
* Factor
;
62 Factor
:= Factor
* Factor
;
67 -- Here we have a negative exponent, and we compute the result as:
69 -- 1.0 / (Left ** (-Right))
71 -- Note that the case of Left being zero is not special, it will
72 -- simply result in a division by zero at the end, yielding a
73 -- correctly signed infinity, or possibly generating an overflow.
75 -- Note on overflow: The coding of this routine assumes that the
76 -- target generates infinities with standard IEEE semantics. If this
77 -- is not the case, then the code below may raise Constraint_Error.
78 -- This follows the implementation permission given in RM 4.5.6(12).
83 if Exp
rem 2 /= 0 then
84 Result
:= Result
* Factor
;
89 Factor
:= Factor
* Factor
;
95 end Exn_Long_Long_Float
;