OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libgfortran/] [m4/] [pow.m4] - Blame information for rev 20

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
`/* 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 (libgfortran).
6
 
7
Libgfortran is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public
9
License as published by the Free Software Foundation; either
10
version 2 of the License, or (at your option) any later version.
11
 
12
In addition to the permissions in the GNU General Public License, the
13
Free Software Foundation gives you unlimited permission to link the
14
compiled version of this file into combinations with other programs,
15
and to distribute those combinations without any restriction coming
16
from the use of this file.  (The General Public License restrictions
17
do apply in other respects; for example, they cover modification of
18
the file, and distribution when not linked into a combine
19
executable.)
20
 
21
Libgfortran is distributed in the hope that it will be useful,
22
but WITHOUT ANY WARRANTY; without even the implied warranty of
23
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
GNU General Public License for more details.
25
 
26
You should have received a copy of the GNU General Public
27
License along with libgfortran; see the file COPYING.  If not,
28
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29
Boston, MA 02110-1301, USA.  */
30
 
31
#include "config.h"
32
#include "libgfortran.h"'
33
include(iparm.m4)dnl
34
 
35
/* Use Binary Method to calculate the powi. This is not an optimal but
36
   a simple and reasonable arithmetic. See section 4.6.3, "Evaluation of
37
   Powers" of Donald E. Knuth, "Seminumerical Algorithms", Vol. 2, "The Art
38
   of Computer Programming", 3rd Edition, 1998.  */
39
 
40
`#if defined (HAVE_'rtype_name`) && defined (HAVE_'atype_name`)'
41
 
42
rtype_name `pow_'rtype_code`_'atype_code (rtype_name a, atype_name b);
43
export_proto(pow_`'rtype_code`_'atype_code);
44
 
45
rtype_name
46
`pow_'rtype_code`_'atype_code (rtype_name a, atype_name b)
47
{
48
  rtype_name pow, x;
49
  atype_name n, u;
50
 
51
  n = b;
52
  x = a;
53
  pow = 1;
54
  if (n != 0)
55
    {
56
      if (n < 0)
57
        {
58
ifelse(rtype_letter,i,`dnl
59
          if (x == 1)
60
            return 1;
61
          if (x == -1)
62
            return (n & 1) ? -1 : 1;
63
          return (x == 0) ? 1 / x : 0;
64
',`
65
          n = -n;
66
          x = pow / x;
67
')dnl
68
        }
69
      u = n;
70
      for (;;)
71
        {
72
          if (u & 1)
73
            pow *= x;
74
          u >>= 1;
75
          if (u)
76
            x *= x;
77
          else
78
            break;
79
        }
80
    }
81
  return pow;
82
}
83
 
84
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.