Ruby  2.4.2p198(2017-09-14revision59899)
Macros | Functions | Variables
math.c File Reference
#include "internal.h"
#include <float.h>
#include <math.h>
#include <errno.h>
Include dependency graph for math.c:

Go to the source code of this file.

Macros

#define RB_BIGNUM_TYPE_P(x)   RB_TYPE_P((x), T_BIGNUM)
 
#define Get_Double(x)   rb_num_to_dbl(x)
 
#define domain_error(msg)   rb_raise(rb_eMathDomainError, "Numerical argument is out of domain - " #msg)
 
#define M_LN2   0.693147180559945309417232121458176568
 
#define M_LN10   2.30258509299404568401799145468436421
 
#define f_boolcast(x)   ((x) ? Qtrue : Qfalse)
 
#define exp1(n)
 
#define exp2(n)
 

Functions

static VALUE math_atan2 (VALUE unused_obj, VALUE y, VALUE x)
 
static VALUE math_cos (VALUE unused_obj, VALUE x)
 
static VALUE math_sin (VALUE unused_obj, VALUE x)
 
static VALUE math_tan (VALUE unused_obj, VALUE x)
 
static VALUE math_acos (VALUE unused_obj, VALUE x)
 
static VALUE math_asin (VALUE unused_obj, VALUE x)
 
static VALUE math_atan (VALUE unused_obj, VALUE x)
 
double cosh (double x)
 
static VALUE math_cosh (VALUE unused_obj, VALUE x)
 
double sinh (double x)
 
static VALUE math_sinh (VALUE unused_obj, VALUE x)
 
double tanh (double x)
 
static VALUE math_tanh (VALUE unused_obj, VALUE x)
 
static VALUE math_acosh (VALUE unused_obj, VALUE x)
 
static VALUE math_asinh (VALUE unused_obj, VALUE x)
 
static VALUE math_atanh (VALUE unused_obj, VALUE x)
 
static VALUE math_exp (VALUE unused_obj, VALUE x)
 
static double math_log1 (VALUE x)
 
static VALUE math_log (int argc, const VALUE *argv, VALUE unused_obj)
 
static double get_double_rshift (VALUE x, size_t *pnumbits)
 
double log2 (double x)
 
static VALUE math_log2 (VALUE unused_obj, VALUE x)
 
static VALUE math_log10 (VALUE unused_obj, VALUE x)
 
static VALUE math_sqrt (VALUE unused_obj, VALUE x)
 
static VALUE f_negative_p (VALUE x)
 
static VALUE f_signbit (VALUE x)
 
VALUE rb_math_sqrt (VALUE x)
 
static VALUE math_cbrt (VALUE unused_obj, VALUE x)
 
static VALUE math_frexp (VALUE unused_obj, VALUE x)
 
static VALUE math_ldexp (VALUE unused_obj, VALUE x, VALUE n)
 
static VALUE math_hypot (VALUE unused_obj, VALUE x, VALUE y)
 
static VALUE math_erf (VALUE unused_obj, VALUE x)
 
static VALUE math_erfc (VALUE unused_obj, VALUE x)
 
static VALUE math_gamma (VALUE unused_obj, VALUE x)
 
static VALUE math_lgamma (VALUE unused_obj, VALUE x)
 
 exp2 (atan2)
 
 exp1 (sin)
 
void Init_Math (void)
 

Variables

VALUE rb_mMath
 
VALUE rb_eMathDomainError
 

Macro Definition Documentation

◆ domain_error

#define domain_error (   msg)    rb_raise(rb_eMathDomainError, "Numerical argument is out of domain - " #msg)

◆ exp1

#define exp1 (   n)
Value:
VALUE \
rb_math_##n(VALUE x)\
{\
return math_##n(0, x);\
}
unsigned long VALUE
Definition: ruby.h:85

Definition at line 925 of file math.c.

◆ exp2

#define exp2 (   n)
Value:
VALUE \
rb_math_##n(VALUE x, VALUE y)\
{\
return math_##n(0, x, y);\
}
unsigned long VALUE
Definition: ruby.h:85

Definition at line 932 of file math.c.

◆ f_boolcast

#define f_boolcast (   x)    ((x) ? Qtrue : Qfalse)

Definition at line 601 of file math.c.

Referenced by f_negative_p(), and f_signbit().

◆ Get_Double

#define Get_Double (   x)    rb_num_to_dbl(x)

◆ M_LN10

#define M_LN10   2.30258509299404568401799145468436421

Definition at line 425 of file math.c.

◆ M_LN2

#define M_LN2   0.693147180559945309417232121458176568

Definition at line 422 of file math.c.

Referenced by math_log1().

◆ RB_BIGNUM_TYPE_P

#define RB_BIGNUM_TYPE_P (   x)    RB_TYPE_P((x), T_BIGNUM)

Definition at line 25 of file math.c.

Referenced by get_double_rshift().

Function Documentation

◆ cosh()

double cosh ( double  x)

Definition at line 228 of file math.c.

Referenced by math_cosh(), and tanh().

◆ exp1()

exp1 ( sin  )

◆ exp2()

exp2 ( atan2  )

Definition at line 939 of file math.c.

References math_log().

◆ f_negative_p()

static VALUE f_negative_p ( VALUE  x)
inlinestatic

Definition at line 603 of file math.c.

References f_boolcast, FIX2LONG, FIXNUM_P, INT2FIX, and rb_funcall().

Referenced by f_signbit().

◆ f_signbit()

static VALUE f_signbit ( VALUE  x)
inlinestatic

Definition at line 610 of file math.c.

References f, f_boolcast, f_negative_p(), isnan, RB_TYPE_P, RFLOAT_VALUE, signbit(), and T_FLOAT.

Referenced by rb_math_sqrt().

◆ get_double_rshift()

static double get_double_rshift ( VALUE  x,
size_t *  pnumbits 
)
static

◆ Init_Math()

void Init_Math ( void  )

Definition at line 1039 of file math.c.

References InitVM.

◆ log2()

double log2 ( double  x)

Definition at line 499 of file math.c.

Referenced by math_log2().

◆ math_acos()

static VALUE math_acos ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 173 of file math.c.

References DBL2NUM, domain_error, and Get_Double.

Referenced by exp1().

◆ math_acosh()

static VALUE math_acosh ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 332 of file math.c.

References acosh(), DBL2NUM, domain_error, and Get_Double.

Referenced by exp1().

◆ math_asin()

static VALUE math_asin ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 197 of file math.c.

References DBL2NUM, domain_error, and Get_Double.

Referenced by exp1().

◆ math_asinh()

static VALUE math_asinh ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 357 of file math.c.

References asinh(), DBL2NUM, and Get_Double.

Referenced by exp1().

◆ math_atan()

static VALUE math_atan ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 221 of file math.c.

References DBL2NUM, and Get_Double.

Referenced by exp1().

◆ math_atan2()

static VALUE math_atan2 ( VALUE  unused_obj,
VALUE  y,
VALUE  x 
)
static

Definition at line 66 of file math.c.

References DBL2NUM, Get_Double, isinf(), M_PI, and signbit().

Referenced by exp1().

◆ math_atanh()

static VALUE math_atanh ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 377 of file math.c.

References atanh(), DBL2NUM, domain_error, Get_Double, and INFINITY.

Referenced by exp1().

◆ math_cbrt()

static VALUE math_cbrt ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 676 of file math.c.

References cbrt(), DBL2NUM, and Get_Double.

Referenced by exp1().

◆ math_cos()

static VALUE math_cos ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 111 of file math.c.

References DBL2NUM, and Get_Double.

Referenced by exp1().

◆ math_cosh()

static VALUE math_cosh ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 249 of file math.c.

References cosh(), DBL2NUM, and Get_Double.

Referenced by exp1().

◆ math_erf()

static VALUE math_erf ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 749 of file math.c.

References DBL2NUM, erf(), and Get_Double.

Referenced by exp1().

◆ math_erfc()

static VALUE math_erfc ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 769 of file math.c.

References DBL2NUM, erfc(), Get_Double, INFINITY, isinf(), isnan, lgamma_r(), signbit(), and tgamma().

Referenced by exp1().

◆ math_exp()

static VALUE math_exp ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 407 of file math.c.

References DBL2NUM, and Get_Double.

Referenced by exp1().

◆ math_frexp()

static VALUE math_frexp ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 693 of file math.c.

References DBL2NUM, Get_Double, INT2NUM, and rb_assoc_new().

Referenced by exp1().

◆ math_gamma()

static VALUE math_gamma ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 850 of file math.c.

References DBL2NUM, domain_error, Get_Double, isinf(), numberof, signbit(), and tgamma().

Referenced by exp1().

◆ math_hypot()

static VALUE math_hypot ( VALUE  unused_obj,
VALUE  x,
VALUE  y 
)
static

Definition at line 729 of file math.c.

References DBL2NUM, Get_Double, and hypot().

Referenced by exp1().

◆ math_ldexp()

static VALUE math_ldexp ( VALUE  unused_obj,
VALUE  x,
VALUE  n 
)
static

Definition at line 713 of file math.c.

References DBL2NUM, Get_Double, and NUM2INT.

Referenced by exp1().

◆ math_lgamma()

static VALUE math_lgamma ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 909 of file math.c.

References DBL2NUM, domain_error, Get_Double, INFINITY, INT2FIX, isinf(), lgamma_r(), rb_assoc_new(), and signbit().

Referenced by exp1().

◆ math_log()

static VALUE math_log ( int  argc,
const VALUE argv,
VALUE  unused_obj 
)
static

Definition at line 452 of file math.c.

References DBL2NUM, math_log1(), and rb_scan_args().

Referenced by exp1(), and exp2().

◆ math_log1()

static double math_log1 ( VALUE  x)
static

Definition at line 483 of file math.c.

References domain_error, get_double_rshift(), INFINITY, and M_LN2.

Referenced by math_log().

◆ math_log10()

static VALUE math_log10 ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 556 of file math.c.

References DBL2NUM, domain_error, get_double_rshift(), and INFINITY.

Referenced by exp1().

◆ math_log2()

static VALUE math_log2 ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 526 of file math.c.

References DBL2NUM, domain_error, get_double_rshift(), INFINITY, and log2().

Referenced by exp1().

◆ math_sin()

static VALUE math_sin ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 132 of file math.c.

References DBL2NUM, and Get_Double.

Referenced by exp1().

◆ math_sinh()

static VALUE math_sinh ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 277 of file math.c.

References DBL2NUM, Get_Double, and sinh().

Referenced by exp1().

◆ math_sqrt()

static VALUE math_sqrt ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 596 of file math.c.

References rb_math_sqrt().

Referenced by exp1().

◆ math_tan()

static VALUE math_tan ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 153 of file math.c.

References DBL2NUM, and Get_Double.

Referenced by exp1().

◆ math_tanh()

static VALUE math_tanh ( VALUE  unused_obj,
VALUE  x 
)
static

Definition at line 312 of file math.c.

References DBL2NUM, Get_Double, and tanh().

Referenced by exp1().

◆ rb_math_sqrt()

VALUE rb_math_sqrt ( VALUE  x)

Definition at line 620 of file math.c.

References DBL2NUM, domain_error, f_signbit(), Get_Double, neg, rb_complex_abs(), rb_complex_new(), RB_TYPE_P, RCOMPLEX, and T_COMPLEX.

Referenced by math_sqrt().

◆ sinh()

double sinh ( double  x)

Definition at line 256 of file math.c.

Referenced by math_sinh(), and tanh().

◆ tanh()

double tanh ( double  x)

Definition at line 284 of file math.c.

References cosh(), isinf(), and sinh().

Referenced by math_tanh().

Variable Documentation

◆ rb_eMathDomainError

VALUE rb_eMathDomainError

Definition at line 28 of file math.c.

Referenced by exp1().

◆ rb_mMath

VALUE rb_mMath

Definition at line 27 of file math.c.

Referenced by exp1().