File: int_power.c

package info (click to toggle)
g2clib 1.2.2-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 588 kB
  • sloc: ansic: 4,982; makefile: 441
file content (30 lines) | stat: -rwxr-xr-x 462 bytes parent folder | download | duplicates (36)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "grib2.h"
/*
 * w. ebisuzaki
 *
 *  return x**y
 *
 *
 *  input: double x
 *         int y
 */
double int_power(double x, g2int y) {

        double value;

        if (y < 0) {
                y = -y;
                x = 1.0 / x;
        }
        value = 1.0;

        while (y) {
                if (y & 1) {
                        value *= x;
                }
                x = x * x;
                y >>= 1;
        }
        return value;
}