From fcbf63e62c627deae76c1b8cb8c0876c536ed811 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 16 Mar 2020 18:49:26 +0900 Subject: Fresh start --- jni/ruby/missing/acosh.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 jni/ruby/missing/acosh.c (limited to 'jni/ruby/missing/acosh.c') diff --git a/jni/ruby/missing/acosh.c b/jni/ruby/missing/acosh.c new file mode 100644 index 0000000..004bfb1 --- /dev/null +++ b/jni/ruby/missing/acosh.c @@ -0,0 +1,93 @@ +/********************************************************************** + + acosh.c - + + $Author: akr $ + created at: Fri Apr 12 00:34:17 JST 2002 + + public domain rewrite of acosh(3), asinh(3) and atanh(3) + +**********************************************************************/ + +#include +#include +#include +#include "ruby.h" + +/* DBL_MANT_DIG must be less than 4 times of bits of int */ +#ifndef DBL_MANT_DIG +#define DBL_MANT_DIG 53 /* in this case, at least 12 digit precision */ +#endif +#define BIG_CRITERIA_BIT (1< 0 +#define BIG_CRITERIA (1.0*BIG_CRITERIA_BIT) +#else +#define BIG_CRITERIA (1.0*(1< 0 +#define SMALL_CRITERIA (1.0/SMALL_CRITERIA_BIT) +#else +#define SMALL_CRITERIA (1.0*(1< BIG_CRITERIA) + x += x; + else + x += sqrt((x + 1) * (x - 1)); + return log(x); +} +#endif + +#ifndef HAVE_ASINH +double +asinh(double x) +{ + int neg = x < 0; + double z = fabs(x); + + if (z < SMALL_CRITERIA) return x; + if (z < (1.0/(1< BIG_CRITERIA) { + z = log(z + z); + } + else { + z = log(z + sqrt(z * z + 1)); + } + if (neg) z = -z; + return z; +} +#endif + +#ifndef HAVE_ATANH +double +atanh(double x) +{ + int neg = x < 0; + double z = fabs(x); + + if (z < SMALL_CRITERIA) return x; + z = log(z > 1 ? -1 : (1 + z) / (1 - z)) / 2; + if (neg) z = -z; + if (isinf(z)) +#if defined(ERANGE) + errno = ERANGE; +#elif defined(EDOM) + errno = EDOM; +#else + ; +#endif + return z; +} +#endif -- cgit v1.2.3