1989-05-10 16:08:14 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*
|
|
|
|
* Author: Ceriel J.H. Jacobs
|
|
|
|
*/
|
1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1989-05-10 16:08:14 +00:00
|
|
|
|
|
|
|
#include <math.h>
|
1989-12-18 15:44:36 +00:00
|
|
|
#include <float.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "localmath.h"
|
1989-05-10 16:08:14 +00:00
|
|
|
|
|
|
|
double
|
|
|
|
pow(double x, double y)
|
|
|
|
{
|
1989-12-18 15:44:36 +00:00
|
|
|
/* Simple version for now. The Cody and Waite book has
|
|
|
|
a very complicated, much more precise version, but
|
|
|
|
this version has machine-dependent arrays A1 and A2,
|
|
|
|
and I don't know yet how to solve this ???
|
|
|
|
*/
|
1989-05-10 16:08:14 +00:00
|
|
|
double dummy;
|
1989-12-18 15:44:36 +00:00
|
|
|
int result_neg = 0;
|
1989-05-10 16:08:14 +00:00
|
|
|
|
|
|
|
if ((x == 0 && y == 0) ||
|
|
|
|
(x < 0 && modf(y, &dummy) != 0)) {
|
|
|
|
errno = EDOM;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x == 0) return x;
|
|
|
|
|
|
|
|
if (x < 0) {
|
|
|
|
if (modf(y/2.0, &dummy) != 0) {
|
|
|
|
/* y was odd */
|
1989-12-18 15:44:36 +00:00
|
|
|
result_neg = 1;
|
1989-05-10 16:08:14 +00:00
|
|
|
}
|
1989-12-18 15:44:36 +00:00
|
|
|
x = -x;
|
|
|
|
}
|
|
|
|
x = log(x);
|
1990-08-28 13:59:36 +00:00
|
|
|
|
1989-12-18 15:44:36 +00:00
|
|
|
if (x < 0) {
|
|
|
|
x = -x;
|
|
|
|
y = -y;
|
|
|
|
}
|
1990-08-28 13:59:36 +00:00
|
|
|
/* Beware of overflow in the multiplication */
|
|
|
|
if (x > 1.0 && y > DBL_MAX/x) {
|
1989-12-18 15:44:36 +00:00
|
|
|
errno = ERANGE;
|
1990-08-28 13:59:36 +00:00
|
|
|
return result_neg ? -HUGE_VAL : HUGE_VAL;
|
1989-05-10 16:08:14 +00:00
|
|
|
}
|
|
|
|
|
1989-12-18 15:44:36 +00:00
|
|
|
x = exp(x * y);
|
|
|
|
return result_neg ? -x : x;
|
1989-05-10 16:08:14 +00:00
|
|
|
}
|