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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include <math.h>
/*
* some rather simple minded replacements
* for functions missing in most msvc incarnations
*/
double
x_trunc(double x)
{
return (x < 0) ? ceil(x) : floor(x);
}
double
x_nearbyint(double x)
{
/* thats grossly incorrect, anyway, don't worry, be crappy ... */
return floor(x + 0.5);
}
double
x_asinh(double x)
{
return (x > 0) ? log(x + sqrt(x * x + 1.0)) : -log(-x + sqrt(x * x + 1.0));
}
double
x_acosh(double x)
{
/* domain check (HUGE_VAL like gnu libc) */
if (x < 1.0)
return HUGE_VAL;
else
return log(x + sqrt(x * x - 1.0));
}
double
x_atanh(double x)
{
/* domain check (HUGE_VAL like gnu libc) */
if (fabs(x) >= 1.0)
return HUGE_VAL;
else
return log((1.0 + x) / (1.0 - x)) / 2.0;
}
|