13# define _USE_MATH_DEFINES 1
20#if defined(HAVE_SIGNBIT) && defined(__GNUC__) && defined(__sun) && \
25#define RB_BIGNUM_TYPE_P(x) RB_TYPE_P((x), T_BIGNUM)
30#define Get_Double(x) rb_num_to_dbl(x)
32#define domain_error(msg) \
33 rb_raise(rb_eMathDomainError, "Numerical argument is out of domain - " #msg)
71 if (dx == 0.0 && dy == 0.0) {
82 const double dz = (3.0 *
M_PI / 4.0);
86 const double dz = (
M_PI / 4.0);
230 return (
exp(x) +
exp(-x)) / 2;
258 return (
exp(x) -
exp(-x)) / 2;
286# if defined(HAVE_SINH) && defined(HAVE_COSH)
287 const double c =
cosh(x);
290 const double e =
exp(x+x);
291 if (!
isinf(e))
return (e - 1) / (e + 1);
293 return x > 0 ? 1.0 : -1.0;
412#if defined __CYGWIN__
413# include <cygwin/version.h>
414# if CYGWIN_VERSION_DLL_MAJOR < 1005
417# define log(x) ((x) < 0.0 ? nan("") : log(x))
418# define log10(x) ((x) < 0.0 ? nan("") : log10(x))
422# define M_LN2 0.693147180559945309417232121458176568
425# define M_LN10 2.30258509299404568401799145468436421
428static double math_log1(
VALUE x);
467 d /= math_log1(base);
473get_double_rshift(
VALUE x,
size_t *pnumbits)
493 double d = get_double_rshift(x, &numbits);
511extern double log2(
double);
536 double d = get_double_rshift(x, &numbits);
566 double d = get_double_rshift(x, &numbits);
614 return rb_math_sqrt(x);
617#define f_boolcast(x) ((x) ? Qtrue : Qfalse)
632 return f_negative_p(x);
644 im =
sqrt((d - re) / 2.0);
645 re =
sqrt((d + re) / 2.0);
652 if (d == 0.0)
return DBL2NUM(0.0);
698 r = (2.0 * r + (
f / r / r)) / 3.0;
840 static const double fact_table[] = {
860 121645100408832000.0,
861 2432902008176640000.0,
862 51090942171709440000.0,
863 1124000727777607680000.0,
868 enum {NFACT_TABLE =
numberof(fact_table)};
881 if (1.0 <= d && d <= (
double)NFACT_TABLE) {
882 return DBL2NUM(fact_table[(
int)d - 1]);
927 return math_##n(0, x);\
932rb_math_##n(VALUE x, VALUE y)\
934 return math_##n(0, x, y);\
VALUE rb_define_class_under(VALUE, const char *, VALUE)
Defines a class under the namespace of outer.
VALUE rb_define_module(const char *)
VALUE rb_eMathDomainError
#define RB_BIGNUM_TYPE_P(x)
VALUE rb_math_log(int argc, const VALUE *argv)
FUNC_MINIMIZED(static VALUE math_log(int, const VALUE *, VALUE))
#define domain_error(msg)