summaryrefslogtreecommitdiff
path: root/math.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-13 16:00:53 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-13 16:00:53 +0000
commit25c0cb981af8fda9860ec6e365b9ea7a9e3f498f (patch)
treeb9b571a43d86bda67a18a05d95f0a437b5500b3b /math.c
parentc4af7f51b7c703cfdf4a84f633af6b892b5d14a8 (diff)
* include/ruby/ruby.h: introduce 2 macros:
RFLOAT_VALUE(v), DOUBLE2NUM(dbl). Rename RFloat#value -> RFloat#double_value. Do not touch RFloat#double_value directly. * bignum.c, insns.def, marshal.c, math.c, numeric.c, object.c, pack.c, parse.y, process.c, random.c, sprintf.c, string.c, time.c: apply above changes. * ext/dl/mkcallback.rb, ext/json/ext/generator/generator.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'math.c')
-rw-r--r--math.c74
1 files changed, 37 insertions, 37 deletions
diff --git a/math.c b/math.c
index 1e55902..e37ec75 100644
--- a/math.c
+++ b/math.c
@@ -55,7 +55,7 @@ static VALUE
math_atan2(VALUE obj, VALUE y, VALUE x)
{
Need_Float2(y, x);
- return rb_float_new(atan2(RFLOAT(y)->value, RFLOAT(x)->value));
+ return DOUBLE2NUM(atan2(RFLOAT_VALUE(y), RFLOAT_VALUE(x)));
}
@@ -71,7 +71,7 @@ static VALUE
math_cos(VALUE obj, VALUE x)
{
Need_Float(x);
- return rb_float_new(cos(RFLOAT(x)->value));
+ return DOUBLE2NUM(cos(RFLOAT_VALUE(x)));
}
/*
@@ -87,7 +87,7 @@ math_sin(VALUE obj, VALUE x)
{
Need_Float(x);
- return rb_float_new(sin(RFLOAT(x)->value));
+ return DOUBLE2NUM(sin(RFLOAT_VALUE(x)));
}
@@ -103,7 +103,7 @@ math_tan(VALUE obj, VALUE x)
{
Need_Float(x);
- return rb_float_new(tan(RFLOAT(x)->value));
+ return DOUBLE2NUM(tan(RFLOAT_VALUE(x)));
}
/*
@@ -120,9 +120,9 @@ math_acos(VALUE obj, VALUE x)
Need_Float(x);
errno = 0;
- d = acos(RFLOAT(x)->value);
+ d = acos(RFLOAT_VALUE(x));
domain_check(d, "acos");
- return rb_float_new(d);
+ return DOUBLE2NUM(d);
}
/*
@@ -139,9 +139,9 @@ math_asin(VALUE obj, VALUE x)
Need_Float(x);
errno = 0;
- d = asin(RFLOAT(x)->value);
+ d = asin(RFLOAT_VALUE(x));
domain_check(d, "asin");
- return rb_float_new(d);
+ return DOUBLE2NUM(d);
}
/*
@@ -155,7 +155,7 @@ static VALUE
math_atan(VALUE obj, VALUE x)
{
Need_Float(x);
- return rb_float_new(atan(RFLOAT(x)->value));
+ return DOUBLE2NUM(atan(RFLOAT_VALUE(x)));
}
#ifndef HAVE_COSH
@@ -178,7 +178,7 @@ math_cosh(VALUE obj, VALUE x)
{
Need_Float(x);
- return rb_float_new(cosh(RFLOAT(x)->value));
+ return DOUBLE2NUM(cosh(RFLOAT_VALUE(x)));
}
#ifndef HAVE_SINH
@@ -201,7 +201,7 @@ static VALUE
math_sinh(VALUE obj, VALUE x)
{
Need_Float(x);
- return rb_float_new(sinh(RFLOAT(x)->value));
+ return DOUBLE2NUM(sinh(RFLOAT_VALUE(x)));
}
#ifndef HAVE_TANH
@@ -224,7 +224,7 @@ static VALUE
math_tanh(VALUE obj, VALUE x)
{
Need_Float(x);
- return rb_float_new(tanh(RFLOAT(x)->value));
+ return DOUBLE2NUM(tanh(RFLOAT_VALUE(x)));
}
/*
@@ -241,9 +241,9 @@ math_acosh(VALUE obj, VALUE x)
Need_Float(x);
errno = 0;
- d = acosh(RFLOAT(x)->value);
+ d = acosh(RFLOAT_VALUE(x));
domain_check(d, "acosh");
- return rb_float_new(d);
+ return DOUBLE2NUM(d);
}
/*
@@ -257,7 +257,7 @@ static VALUE
math_asinh(VALUE obj, VALUE x)
{
Need_Float(x);
- return rb_float_new(asinh(RFLOAT(x)->value));
+ return DOUBLE2NUM(asinh(RFLOAT_VALUE(x)));
}
/*
@@ -274,9 +274,9 @@ math_atanh(VALUE obj, VALUE x)
Need_Float(x);
errno = 0;
- d = atanh(RFLOAT(x)->value);
+ d = atanh(RFLOAT_VALUE(x));
domain_check(d, "atanh");
- return rb_float_new(d);
+ return DOUBLE2NUM(d);
}
/*
@@ -290,7 +290,7 @@ static VALUE
math_exp(VALUE obj, VALUE x)
{
Need_Float(x);
- return rb_float_new(exp(RFLOAT(x)->value));
+ return DOUBLE2NUM(exp(RFLOAT_VALUE(x)));
}
#if defined __CYGWIN__
@@ -321,13 +321,13 @@ math_log(int argc, VALUE *argv)
rb_scan_args(argc, argv, "11", &x, &base);
Need_Float(x);
errno = 0;
- d = log(RFLOAT(x)->value);
+ d = log(RFLOAT_VALUE(x));
if (!NIL_P(base)) {
Need_Float(base);
- d /= log(RFLOAT(base)->value);
+ d /= log(RFLOAT_VALUE(base));
}
domain_check(d, "log");
- return rb_float_new(d);
+ return DOUBLE2NUM(d);
}
#ifndef log2
@@ -356,11 +356,11 @@ math_log2(VALUE obj, VALUE x)
Need_Float(x);
errno = 0;
- d = log2(RFLOAT(x)->value);
+ d = log2(RFLOAT_VALUE(x));
if (errno) {
rb_sys_fail("log2");
}
- return rb_float_new(d);
+ return DOUBLE2NUM(d);
}
/*
@@ -377,9 +377,9 @@ math_log10(VALUE obj, VALUE x)
Need_Float(x);
errno = 0;
- d = log10(RFLOAT(x)->value);
+ d = log10(RFLOAT_VALUE(x));
domain_check(d, "log10");
- return rb_float_new(d);
+ return DOUBLE2NUM(d);
}
/*
@@ -396,9 +396,9 @@ math_sqrt(VALUE obj, VALUE x)
Need_Float(x);
errno = 0;
- d = sqrt(RFLOAT(x)->value);
+ d = sqrt(RFLOAT_VALUE(x));
domain_check(d, "sqrt");
- return rb_float_new(d);
+ return DOUBLE2NUM(d);
}
/*
@@ -421,8 +421,8 @@ math_frexp(VALUE obj, VALUE x)
Need_Float(x);
- d = frexp(RFLOAT(x)->value, &exp);
- return rb_assoc_new(rb_float_new(d), INT2NUM(exp));
+ d = frexp(RFLOAT_VALUE(x), &exp);
+ return rb_assoc_new(DOUBLE2NUM(d), INT2NUM(exp));
}
/*
@@ -439,7 +439,7 @@ static VALUE
math_ldexp(VALUE obj, VALUE x, VALUE n)
{
Need_Float(x);
- return rb_float_new(ldexp(RFLOAT(x)->value, NUM2INT(n)));
+ return DOUBLE2NUM(ldexp(RFLOAT_VALUE(x), NUM2INT(n)));
}
/*
@@ -456,7 +456,7 @@ static VALUE
math_hypot(VALUE obj, VALUE x, VALUE y)
{
Need_Float2(x, y);
- return rb_float_new(hypot(RFLOAT(x)->value, RFLOAT(y)->value));
+ return DOUBLE2NUM(hypot(RFLOAT_VALUE(x), RFLOAT_VALUE(y)));
}
/*
@@ -470,7 +470,7 @@ static VALUE
math_erf(VALUE obj, VALUE x)
{
Need_Float(x);
- return rb_float_new(erf(RFLOAT(x)->value));
+ return DOUBLE2NUM(erf(RFLOAT_VALUE(x)));
}
/*
@@ -484,7 +484,7 @@ static VALUE
math_erfc(VALUE obj, VALUE x)
{
Need_Float(x);
- return rb_float_new(erfc(RFLOAT(x)->value));
+ return DOUBLE2NUM(erfc(RFLOAT_VALUE(x)));
}
/*
@@ -501,15 +501,15 @@ Init_Math(void)
rb_mMath = rb_define_module("Math");
#ifdef M_PI
- rb_define_const(rb_mMath, "PI", rb_float_new(M_PI));
+ rb_define_const(rb_mMath, "PI", DOUBLE2NUM(M_PI));
#else
- rb_define_const(rb_mMath, "PI", rb_float_new(atan(1.0)*4.0));
+ rb_define_const(rb_mMath, "PI", DOUBLE2NUM(atan(1.0)*4.0));
#endif
#ifdef M_E
- rb_define_const(rb_mMath, "E", rb_float_new(M_E));
+ rb_define_const(rb_mMath, "E", DOUBLE2NUM(M_E));
#else
- rb_define_const(rb_mMath, "E", rb_float_new(exp(1.0)));
+ rb_define_const(rb_mMath, "E", DOUBLE2NUM(exp(1.0)));
#endif
rb_define_module_function(rb_mMath, "atan2", math_atan2, 2);