ack/lang/cem/libcc.ansi/pure/math/sinh.c

89 lines
1.5 KiB
C
Raw Normal View History

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
2018-06-21 20:33:47 +00:00
#include <math.h>
#include <float.h>
#include <errno.h>
#include "localmath.h"
1989-05-10 16:08:14 +00:00
static double
sinh_cosh(double x, int cosh_flag)
1989-05-10 16:08:14 +00:00
{
/* Algorithm and coefficients from:
"Software manual for the elementary functions"
by W.J. Cody and W. Waite, Prentice-Hall, 1980
*/
static double p[] = {
-0.35181283430177117881e+6,
-0.11563521196851768270e+5,
-0.16375798202630751372e+3,
-0.78966127417357099479e+0
};
static double q[] = {
-0.21108770058106271242e+7,
2018-06-21 20:33:47 +00:00
0.36162723109421836460e+5,
-0.27773523119650701167e+3,
2018-06-21 20:33:47 +00:00
1.0
};
2018-06-21 20:33:47 +00:00
int negative = x < 0;
double y = negative ? -x : x;
1989-05-10 16:08:14 +00:00
2018-06-21 20:33:47 +00:00
if (__IsNan(x))
{
1991-03-19 16:39:40 +00:00
errno = EDOM;
return x;
}
2018-06-21 20:33:47 +00:00
if (!cosh_flag && y <= 1.0)
{
/* ??? check for underflow ??? */
y = y * y;
2018-06-21 20:33:47 +00:00
return x + x * y * POLYNOM3(y, p) / POLYNOM3(y, q);
1989-05-10 16:08:14 +00:00
}
2018-06-21 20:33:47 +00:00
if (y >= M_LN_MAX_D)
{
/* exp(y) would cause overflow */
#define LNV 0.69316101074218750000e+0
#define VD2M1 0.52820835025874852469e-4
double w = y - LNV;
if (w < M_LN_MAX_D + M_LN2 - LNV)
{
x = exp(w);
x += VD2M1 * x;
}
2018-06-21 20:33:47 +00:00
else
{
1989-05-10 16:08:14 +00:00
errno = ERANGE;
x = HUGE_VAL;
1989-05-10 16:08:14 +00:00
}
}
2018-06-21 20:33:47 +00:00
else
{
double z = exp(y);
x = 0.5 * (z + (cosh_flag ? 1.0 : -1.0) / z);
1989-05-10 16:08:14 +00:00
}
return negative ? -x : x;
}
double
sinh(double x)
{
return sinh_cosh(x, 0);
}
double
cosh(double x)
{
2018-06-21 20:33:47 +00:00
if (x < 0)
x = -x;
return sinh_cosh(x, 1);
1989-05-10 16:08:14 +00:00
}