15# define _USE_MATH_DEFINES 1
29#if defined(HAVE_SIGNBIT) && defined(__GNUC__) && defined(__sun) && \
34#define RB_BIGNUM_TYPE_P(x) RB_TYPE_P((x), T_BIGNUM)
39#define Get_Double(x) rb_num_to_dbl(x)
41#define domain_error(msg) \
42 rb_raise(rb_eMathDomainError, "Numerical argument is out of domain - " #msg)
80 if (dx == 0.0 && dy == 0.0) {
91 const double dz = (3.0 *
M_PI / 4.0);
95 const double dz = (
M_PI / 4.0);
239 return (exp(x) + exp(-x)) / 2;
267 return (exp(x) - exp(-x)) / 2;
295# if defined(HAVE_SINH) && defined(HAVE_COSH)
296 const double c =
cosh(x);
299 const double e = exp(x+x);
300 if (!
isinf(e))
return (e - 1) / (e + 1);
302 return x > 0 ? 1.0 : -1.0;
421#if defined __CYGWIN__
422# include <cygwin/version.h>
423# if CYGWIN_VERSION_DLL_MAJOR < 1005
426# define log(x) ((x) < 0.0 ? nan("") : log(x))
427# define log10(x) ((x) < 0.0 ? nan("") : log10(x))
431# define M_LN2 0.693147180559945309417232121458176568
434# define M_LN10 2.30258509299404568401799145468436421
437static double math_log1(
VALUE x);
476 d /= math_log1(base);
482get_double_rshift(
VALUE x,
size_t *pnumbits)
502 double d = get_double_rshift(x, &numbits);
517 return log10(x)/log10(2.0);
520extern double log2(
double);
545 double d = get_double_rshift(x, &numbits);
575 double d = get_double_rshift(x, &numbits);
582 return DBL2NUM(log10(d) + numbits * log10(2));
623 return rb_math_sqrt(x);
626#define f_boolcast(x) ((x) ? Qtrue : Qfalse)
641 return f_negative_p(x);
653 im = sqrt((d - re) / 2.0);
654 re = sqrt((d + re) / 2.0);
661 if (d == 0.0)
return DBL2NUM(0.0);
707 r = (2.0 * r + (
f / r / r)) / 3.0;
849 static const double fact_table[] = {
869 121645100408832000.0,
870 2432902008176640000.0,
871 51090942171709440000.0,
872 1124000727777607680000.0,
877 enum {NFACT_TABLE =
numberof(fact_table)};
890 if (1.0 <= d && d <= (
double)NFACT_TABLE) {
891 return DBL2NUM(fact_table[(
int)d - 1]);
936 return math_##n(0, x);\
941rb_math_##n(VALUE x, VALUE y)\
943 return math_##n(0, x, y);\
VALUE rb_assoc_new(VALUE car, VALUE cdr)
#define FUNC_MINIMIZED(x)
size_t rb_absint_numwords(VALUE val, size_t word_numbits, size_t *nlz_bits_ret)
VALUE rb_big_rshift(VALUE x, VALUE y)
VALUE rb_complex_abs(VALUE self)
VALUE rb_complex_new(VALUE x, VALUE y)
#define rb_define_module_function(klass, mid, func, arity)
Defines klass#mid and makes it a module function.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_define_module(const char *name)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Thin wrapper to ruby/config.h.
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
void rb_define_const(VALUE, const char *, VALUE)
double hypot(double, double)
double lgamma_r(double, int *)
Internal header for Bignums.
Internal header for Complex.
Internal header for Object.
Internal header for RubyVM.
#define RB_BIGNUM_TYPE_P(x)
VALUE rb_math_log(int argc, const VALUE *argv)
#define domain_error(msg)
VALUE rb_eMathDomainError
Internal header for Math.