]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/generated/pow_c8_i4.c
lcm.c (optimize_mode_switching): Free ptr even when mode_set is NULL_RTX.
[thirdparty/gcc.git] / libgfortran / generated / pow_c8_i4.c
CommitLineData
5b200ac2
FW
1/* Support routines for the intrinsic power (**) operator.
2 Copyright 2004 Free Software Foundation, Inc.
3 Contributed by Paul Brook
4
5This file is part of the GNU Fortran 95 runtime library (libgfor).
6
7Libgfor is free software; you can redistribute it and/or
8modify it under the terms of the GNU Lesser General Public
9License as published by the Free Software Foundation; either
10version 2.1 of the License, or (at your option) any later version.
11
12Ligbfor is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with libgfor; see the file COPYING.LIB. If not,
19write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
21
22#include "config.h"
23#include "libgfortran.h"
24
25/* Uuse 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
30GFC_COMPLEX_8
31prefix(pow_c8_i4) (GFC_COMPLEX_8 a, GFC_INTEGER_4 b)
32{
33 GFC_COMPLEX_8 pow, x;
34 GFC_INTEGER_4 n, u;
35
36 n = b;
37 x = a;
38 pow = 1;
39 if (n != 0)
40 {
41 if (n < 0)
42 {
43
44 n = -n;
45 x = pow / x;
46 }
47 u = n;
48 for (;;)
49 {
50 if (u & 1)
51 pow *= x;
52 u >>= 1;
53 if (u)
54 x *= x;
55 else
56 break;
57 }
58 }
59 return pow;
60}