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