Project

General

Profile

Feature #10474 ยป combine_some_macros_into_one_at_math.c.patch

gogotanaka (Kazuki Tanaka), 11/04/2014 05:46 AM

View differences:

math.c
VALUE rb_mMath;
VALUE rb_eMathDomainError;
#define Need_Float(x) do {if (!RB_TYPE_P(x, T_FLOAT)) {(x) = rb_to_float(x);}} while(0)
#define Need_Float2(x,y) do {\
Need_Float(x);\
Need_Float(y);\
} while (0)
#define Get_RFloat_Value(x) RFLOAT_VALUE(RB_TYPE_P(x, T_FLOAT) ? x : rb_to_float(x))
#define domain_error(msg) \
rb_raise(rb_eMathDomainError, "Numerical argument is out of domain - " #msg)
......
# define M_PI 3.14159265358979323846
#endif
double dx, dy;
Need_Float2(y, x);
dx = RFLOAT_VALUE(x);
dy = RFLOAT_VALUE(y);
dx = Get_RFloat_Value(x);
dy = Get_RFloat_Value(y);
if (dx == 0.0 && dy == 0.0) {
if (!signbit(dx))
return DBL2NUM(dy);
......
static VALUE
math_cos(VALUE obj, VALUE x)
{
Need_Float(x);
return DBL2NUM(cos(RFLOAT_VALUE(x)));
return DBL2NUM(cos(Get_RFloat_Value(x)));
}
/*
......
static VALUE
math_sin(VALUE obj, VALUE x)
{
Need_Float(x);
return DBL2NUM(sin(RFLOAT_VALUE(x)));
return DBL2NUM(sin(Get_RFloat_Value(x)));
}
......
static VALUE
math_tan(VALUE obj, VALUE x)
{
Need_Float(x);
return DBL2NUM(tan(RFLOAT_VALUE(x)));
return DBL2NUM(tan(Get_RFloat_Value(x)));
}
/*
......
{
double d0, d;
Need_Float(x);
d0 = RFLOAT_VALUE(x);
d0 = Get_RFloat_Value(x);
/* check for domain error */
if (d0 < -1.0 || 1.0 < d0) domain_error("acos");
d = acos(d0);
......
{
double d0, d;
Need_Float(x);
d0 = RFLOAT_VALUE(x);
d0 = Get_RFloat_Value(x);
/* check for domain error */
if (d0 < -1.0 || 1.0 < d0) domain_error("asin");
d = asin(d0);
......
static VALUE
math_atan(VALUE obj, VALUE x)
{
Need_Float(x);
return DBL2NUM(atan(RFLOAT_VALUE(x)));
return DBL2NUM(atan(Get_RFloat_Value(x)));
}
#ifndef HAVE_COSH
......
static VALUE
math_cosh(VALUE obj, VALUE x)
{
Need_Float(x);
return DBL2NUM(cosh(RFLOAT_VALUE(x)));
return DBL2NUM(cosh(Get_RFloat_Value(x)));
}
#ifndef HAVE_SINH
......
static VALUE
math_sinh(VALUE obj, VALUE x)
{
Need_Float(x);
return DBL2NUM(sinh(RFLOAT_VALUE(x)));
return DBL2NUM(sinh(Get_RFloat_Value(x)));
}
#ifndef HAVE_TANH
......
static VALUE
math_tanh(VALUE obj, VALUE x)
{
Need_Float(x);
return DBL2NUM(tanh(RFLOAT_VALUE(x)));
return DBL2NUM(tanh(Get_RFloat_Value(x)));
}
/*
......
{
double d0, d;
Need_Float(x);
d0 = RFLOAT_VALUE(x);
d0 = Get_RFloat_Value(x);
/* check for domain error */
if (d0 < 1.0) domain_error("acosh");
d = acosh(d0);
......
static VALUE
math_asinh(VALUE obj, VALUE x)
{
Need_Float(x);
return DBL2NUM(asinh(RFLOAT_VALUE(x)));
return DBL2NUM(asinh(Get_RFloat_Value(x)));
}
/*
......
{
double d0, d;
Need_Float(x);
d0 = RFLOAT_VALUE(x);
d0 = Get_RFloat_Value(x);
/* check for domain error */
if (d0 < -1.0 || +1.0 < d0) domain_error("atanh");
/* check for pole error */
......
static VALUE
math_exp(VALUE obj, VALUE x)
{
Need_Float(x);
return DBL2NUM(exp(RFLOAT_VALUE(x)));
return DBL2NUM(exp(Get_RFloat_Value(x)));
}
#if defined __CYGWIN__
......
numbits = 0;
}
Need_Float(x);
d0 = RFLOAT_VALUE(x);
d0 = Get_RFloat_Value(x);
/* check for domain error */
if (d0 < 0.0) domain_error("log");
/* check for pole error */
......
numbits = 0;
}
Need_Float(x);
d0 = RFLOAT_VALUE(x);
d0 = Get_RFloat_Value(x);
/* check for domain error */
if (d0 < 0.0) domain_error("log2");
/* check for pole error */
......
numbits = 0;
}
Need_Float(x);
d0 = RFLOAT_VALUE(x);
d0 = Get_RFloat_Value(x);
/* check for domain error */
if (d0 < 0.0) domain_error("log10");
/* check for pole error */
......
{
double d0, d;
Need_Float(x);
d0 = RFLOAT_VALUE(x);
d0 = Get_RFloat_Value(x);
/* check for domain error */
if (d0 < 0.0) domain_error("sqrt");
if (d0 == 0.0) return DBL2NUM(0.0);
......
static VALUE
math_cbrt(VALUE obj, VALUE x)
{
Need_Float(x);
return DBL2NUM(cbrt(RFLOAT_VALUE(x)));
return DBL2NUM(cbrt(Get_RFloat_Value(x)));
}
/*
......
double d;
int exp;
Need_Float(x);
d = frexp(RFLOAT_VALUE(x), &exp);
d = frexp(Get_RFloat_Value(x), &exp);
return rb_assoc_new(DBL2NUM(d), INT2NUM(exp));
}
......
static VALUE
math_ldexp(VALUE obj, VALUE x, VALUE n)
{
Need_Float(x);
return DBL2NUM(ldexp(RFLOAT_VALUE(x), NUM2INT(n)));
return DBL2NUM(ldexp(Get_RFloat_Value(x), NUM2INT(n)));
}
/*
......
static VALUE
math_hypot(VALUE obj, VALUE x, VALUE y)
{
Need_Float2(x, y);
return DBL2NUM(hypot(RFLOAT_VALUE(x), RFLOAT_VALUE(y)));
return DBL2NUM(hypot(Get_RFloat_Value(x), Get_RFloat_Value(y)));
}
/*
......
static VALUE
math_erf(VALUE obj, VALUE x)
{
Need_Float(x);
return DBL2NUM(erf(RFLOAT_VALUE(x)));
return DBL2NUM(erf(Get_RFloat_Value(x)));
}
/*
......
static VALUE
math_erfc(VALUE obj, VALUE x)
{
Need_Float(x);
return DBL2NUM(erfc(RFLOAT_VALUE(x)));
return DBL2NUM(erfc(Get_RFloat_Value(x)));
}
/*
......
};
double d0, d;
double intpart, fracpart;
Need_Float(x);
d0 = RFLOAT_VALUE(x);
d0 = Get_RFloat_Value(x);
/* check for domain error */
if (isinf(d0) && signbit(d0)) domain_error("gamma");
fracpart = modf(d0, &intpart);
......
double d0, d;
int sign=1;
VALUE v;
Need_Float(x);
d0 = RFLOAT_VALUE(x);
d0 = Get_RFloat_Value(x);
/* check for domain error */
if (isinf(d0)) {
if (signbit(d0)) domain_error("lgamma");
    (1-1/1)