1988-07-22 16:53:29 +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$ */
|
1988-07-22 16:53:29 +00:00
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
extern int errno;
|
1989-05-18 15:37:54 +00:00
|
|
|
extern double modf(), exp(), log();
|
1988-07-22 16:53:29 +00:00
|
|
|
|
|
|
|
double
|
|
|
|
pow(x,y)
|
|
|
|
double x,y;
|
|
|
|
{
|
1989-05-18 15:37:54 +00:00
|
|
|
/* Simple version for now. The Cody and Waite book has
|
|
|
|
a very complicated, much more precise version, but
|
|
|
|
this version has machine-dependant arrays A1 and A2,
|
|
|
|
and I don't know yet how to solve this ???
|
|
|
|
*/
|
1988-07-22 16:53:29 +00:00
|
|
|
double dummy;
|
1989-05-18 15:37:54 +00:00
|
|
|
int result_neg = 0;
|
1988-07-22 16:53:29 +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-05-18 15:37:54 +00:00
|
|
|
result_neg = 1;
|
1988-07-22 16:53:29 +00:00
|
|
|
}
|
1989-05-18 15:37:54 +00:00
|
|
|
x = -x;
|
|
|
|
}
|
|
|
|
x = log(x);
|
|
|
|
if (x < 0) {
|
|
|
|
x = -x;
|
|
|
|
y = -y;
|
|
|
|
}
|
|
|
|
if (y > M_LN_MAX_D/x) {
|
|
|
|
errno = ERANGE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (y < M_LN_MIN_D/x) {
|
|
|
|
errno = ERANGE;
|
|
|
|
return 0;
|
1988-07-22 16:53:29 +00:00
|
|
|
}
|
|
|
|
|
1989-05-18 15:37:54 +00:00
|
|
|
x = exp(x * y);
|
|
|
|
return result_neg ? -x : x;
|
1988-07-22 16:53:29 +00:00
|
|
|
}
|