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 415 # define nan(x) nan() 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 428 static double math_log1(
VALUE x);
460 d /= math_log1(base);
466 get_double_rshift(
VALUE x,
size_t *pnumbits)
486 double d = get_double_rshift(x, &numbits);
493 return log(d) + numbits *
M_LN2;
501 return log10(x)/log10(2.0);
504 extern double log2(
double);
529 double d = get_double_rshift(x, &numbits);
559 double d = get_double_rshift(x, &numbits);
566 return DBL2NUM(log10(d) + numbits * log10(2));
608 #define f_boolcast(x) ((x) ? Qtrue : Qfalse) 610 f_negative_p(
VALUE x)
623 return f_negative_p(x);
635 im = sqrt((d - re) / 2.0);
636 re = sqrt((d + re) / 2.0);
643 if (d == 0.0)
return DBL2NUM(0.0);
824 static const double fact_table[] = {
844 121645100408832000.0,
845 2432902008176640000.0,
846 51090942171709440000.0,
847 1124000727777607680000.0,
852 enum {NFACT_TABLE =
numberof(fact_table)};
865 if (1.0 <= d && d <= (
double)NFACT_TABLE) {
866 return DBL2NUM(fact_table[(
int)d - 1]);
909 rb_math_##n(VALUE x)\ 911 return math_##n(0, x);\ 916 rb_math_##n(VALUE x, VALUE y)\ 918 return math_##n(0, x, y);\ 930 return math_log(argc, argv, 0);
RUBY_EXTERN double cbrt(double)
RUBY_EXTERN int signbit(double x)
VALUE rb_eMathDomainError
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
RUBY_EXTERN double tgamma(double)
#define RB_BIGNUM_TYPE_P(x)
RUBY_EXTERN double lgamma_r(double, int *)
#define RB_TYPE_P(obj, type)
void rb_define_const(VALUE, const char *, VALUE)
RUBY_SYMBOL_EXPORT_BEGIN RUBY_EXTERN double acosh(double)
RUBY_EXTERN double erfc(double)
RUBY_EXTERN int isinf(double)
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
RUBY_EXTERN double atanh(double)
RUBY_EXTERN double hypot(double, double)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
VALUE rb_assoc_new(VALUE car, VALUE cdr)
#define domain_error(msg)
RUBY_EXTERN double asinh(double)
VALUE rb_complex_new(VALUE x, VALUE y)
VALUE rb_math_sqrt(VALUE x)
#define BIGNUM_POSITIVE_P(b)
size_t rb_absint_numwords(VALUE val, size_t word_numbits, size_t *nlz_bits_ret)
VALUE rb_complex_abs(VALUE cmp)
VALUE rb_big_rshift(VALUE x, VALUE y)
VALUE rb_define_module(const char *name)
VALUE rb_math_log(int argc, const VALUE *argv)
RUBY_EXTERN double erf(double)