at_wini also needs a pci_reserve() for the pci compatability device, if
[minix3.git] / lib / math / pow.c
blobb4a9006e3b0b294372ea065b4d34bc63641db807
1 /*
2 * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
5 * Author: Ceriel J.H. Jacobs
6 */
7 /* $Header$ */
9 #include <math.h>
10 #include <float.h>
11 #include <errno.h>
12 #include "localmath.h"
14 double
15 pow(double x, double y)
17 /* Simple version for now. The Cody and Waite book has
18 a very complicated, much more precise version, but
19 this version has machine-dependent arrays A1 and A2,
20 and I don't know yet how to solve this ???
22 double dummy;
23 int result_neg = 0;
25 if ((x == 0 && y == 0) ||
26 (x < 0 && modf(y, &dummy) != 0)) {
27 errno = EDOM;
28 return 0;
31 if (x == 0) return x;
33 if (x < 0) {
34 if (modf(y/2.0, &dummy) != 0) {
35 /* y was odd */
36 result_neg = 1;
38 x = -x;
40 x = log(x);
42 if (x < 0) {
43 x = -x;
44 y = -y;
46 /* Beware of overflow in the multiplication */
47 if (x > 1.0 && y > DBL_MAX/x) {
48 errno = ERANGE;
49 return result_neg ? -HUGE_VAL : HUGE_VAL;
52 x = exp(x * y);
53 return result_neg ? -x : x;