OSDN Git Service

* acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
[pf3gnuchains/gcc-fork.git] / libgfortran / generated / pow_r8_i8.c
1 /* Support routines for the intrinsic power (**) operator.
2    Copyright 2004 Free Software Foundation, Inc.
3    Contributed by Paul Brook
4
5 This file is part of the GNU Fortran 95 runtime library (libgfor).
6
7 Libgfor is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 Ligbfor is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with libgfor; see the file COPYING.LIB.  If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 #include "config.h"
23 #include "libgfortran.h"
24
25 /* Use Binary Method to calculate the powi. This is not an optimal but
26    a simple and reasonable arithmetic. See section 4.6.3, "Evaluation of
27    Powers" of Donald E. Knuth, "Seminumerical Algorithms", Vol. 2, "The Art
28    of Computer Programming", 3rd Edition, 1998.  */
29
30 GFC_REAL_8 pow_r8_i8 (GFC_REAL_8 a, GFC_INTEGER_8 b);
31 export_proto(pow_r8_i8);
32
33 GFC_REAL_8
34 pow_r8_i8 (GFC_REAL_8 a, GFC_INTEGER_8 b)
35 {
36   GFC_REAL_8 pow, x;
37   GFC_INTEGER_8 n, u;
38   
39   n = b;
40   x = a;
41   pow = 1;
42   if (n != 0)
43     {
44       if (n < 0)
45         {
46
47           n = -n;
48           x = pow / x;
49         }
50       u = n;
51       for (;;)
52         {
53           if (u & 1)
54             pow *= x;
55           u >>= 1;
56           if (u)
57             x *= x;
58           else
59             break;
60         }
61     }
62   return pow;
63 }