* include/ruby/ruby.h (DBL2NUM): renamed from DOUBLE2NUM.

a patch from Tadashi Saito <shiba at mail2.accsnet.ne.jp>
  in [ruby-dev:36102].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19160 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2008-09-05 18:24:21 +00:00
Родитель 80abde2c89
Коммит 31b6ea65bb
15 изменённых файлов: 113 добавлений и 107 удалений

Просмотреть файл

@ -1,3 +1,9 @@
Sat Sep 6 06:05:09 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* include/ruby/ruby.h (DBL2NUM): renamed from DOUBLE2NUM.
a patch from Tadashi Saito <shiba at mail2.accsnet.ne.jp>
in [ruby-dev:36102].
Sat Sep 6 03:18:17 2008 Tanaka Akira <akr@fsij.org>
* transcode.c (allocate_converted_string): add arguments for a buffer

Просмотреть файл

@ -1237,7 +1237,7 @@ rb_big2dbl(VALUE x)
static VALUE
rb_big_to_f(VALUE x)
{
return DOUBLE2NUM(rb_big2dbl(x));
return DBL2NUM(rb_big2dbl(x));
}
/*
@ -1499,7 +1499,7 @@ rb_big_plus(VALUE x, VALUE y)
return bignorm(bigadd(x, y, 1));
case T_FLOAT:
return DOUBLE2NUM(rb_big2dbl(x) + RFLOAT_VALUE(y));
return DBL2NUM(rb_big2dbl(x) + RFLOAT_VALUE(y));
default:
return rb_num_coerce_bin(x, y, '+');
@ -1524,7 +1524,7 @@ rb_big_minus(VALUE x, VALUE y)
return bignorm(bigadd(x, y, 0));
case T_FLOAT:
return DOUBLE2NUM(rb_big2dbl(x) - RFLOAT_VALUE(y));
return DBL2NUM(rb_big2dbl(x) - RFLOAT_VALUE(y));
default:
return rb_num_coerce_bin(x, y, '-');
@ -1588,7 +1588,7 @@ rb_big_mul0(VALUE x, VALUE y)
break;
case T_FLOAT:
return DOUBLE2NUM(rb_big2dbl(x) * RFLOAT_VALUE(y));
return DBL2NUM(rb_big2dbl(x) * RFLOAT_VALUE(y));
default:
return rb_num_coerce_bin(x, y, '*');
@ -1817,7 +1817,7 @@ rb_big_divide(VALUE x, VALUE y, ID op)
{
double div = rb_big2dbl(x) / RFLOAT_VALUE(y);
if (op == '/') {
return DOUBLE2NUM(div);
return DBL2NUM(div);
}
else {
return rb_dbl2big(div);
@ -2010,7 +2010,7 @@ rb_big_fdiv(VALUE x, VALUE y)
if (ey) y = big_shift(y, ey);
bignum:
bigdivrem(x, y, &z, 0);
return DOUBLE2NUM(ldexp(big2dbl(z), ex - ey));
return DBL2NUM(ldexp(big2dbl(z), ex - ey));
}
case T_FLOAT:
if (isnan(RFLOAT_VALUE(y))) return y;
@ -2035,7 +2035,7 @@ rb_big_fdiv(VALUE x, VALUE y)
default:
return rb_num_coerce_bin(x, y, rb_intern("fdiv"));
}
return DOUBLE2NUM(dx / dy);
return DBL2NUM(dx / dy);
}
static VALUE
@ -2148,7 +2148,7 @@ rb_big_pow(VALUE x, VALUE y)
default:
return rb_num_coerce_bin(x, y, rb_intern("**"));
}
return DOUBLE2NUM(pow(rb_big2dbl(x), d));
return DBL2NUM(pow(rb_big2dbl(x), d));
}
static VALUE

8
gc.c
Просмотреть файл

@ -2696,14 +2696,14 @@ gc_profile_record_get(void)
for (i =0; i < objspace->profile.count; i++) {
prof = rb_hash_new();
rb_hash_aset(prof, ID2SYM(rb_intern("GC_TIME")), DOUBLE2NUM(objspace->profile.record[i].gc_time));
rb_hash_aset(prof, ID2SYM(rb_intern("GC_INVOKE_TIME")), DOUBLE2NUM(objspace->profile.record[i].gc_invoke_time));
rb_hash_aset(prof, ID2SYM(rb_intern("GC_TIME")), DBL2NUM(objspace->profile.record[i].gc_time));
rb_hash_aset(prof, ID2SYM(rb_intern("GC_INVOKE_TIME")), DBL2NUM(objspace->profile.record[i].gc_invoke_time));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_USE_SIZE")), rb_uint2inum(objspace->profile.record[i].heap_use_size));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_TOTAL_SIZE")), rb_uint2inum(objspace->profile.record[i].heap_total_size));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_TOTAL_OBJECTS")), rb_uint2inum(objspace->profile.record[i].heap_total_objects));
#if GC_PROFILE_MORE_DETAIL
rb_hash_aset(prof, ID2SYM(rb_intern("GC_MARK_TIME")), DOUBLE2NUM(objspace->profile.record[i].gc_mark_time));
rb_hash_aset(prof, ID2SYM(rb_intern("GC_SWEEP_TIME")), DOUBLE2NUM(objspace->profile.record[i].gc_sweep_time));
rb_hash_aset(prof, ID2SYM(rb_intern("GC_MARK_TIME")), DBL2NUM(objspace->profile.record[i].gc_mark_time));
rb_hash_aset(prof, ID2SYM(rb_intern("GC_SWEEP_TIME")), DBL2NUM(objspace->profile.record[i].gc_sweep_time));
rb_hash_aset(prof, ID2SYM(rb_intern("ALLOCATE_INCREASE")), rb_uint2inum(objspace->profile.record[i].allocate_increase));
rb_hash_aset(prof, ID2SYM(rb_intern("ALLOCATE_LIMIT")), rb_uint2inum(objspace->profile.record[i].allocate_limit));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_USE_SLOTS")), rb_uint2inum(objspace->profile.record[i].heap_use_slots));

Просмотреть файл

@ -568,7 +568,7 @@ struct RFloat {
double float_value;
};
#define RFLOAT_VALUE(v) (RFLOAT(v)->float_value)
#define DOUBLE2NUM(dbl) rb_float_new(dbl)
#define DBL2NUM(dbl) rb_float_new(dbl)
#define ELTS_SHARED FL_USER2

Просмотреть файл

@ -1319,7 +1319,7 @@ opt_plus
else if (HEAP_CLASS_OF(recv) == rb_cFloat &&
HEAP_CLASS_OF(obj) == rb_cFloat &&
BASIC_OP_UNREDEFINED_P(BOP_PLUS)) {
val = DOUBLE2NUM(RFLOAT_VALUE(recv) + RFLOAT_VALUE(obj));
val = DBL2NUM(RFLOAT_VALUE(recv) + RFLOAT_VALUE(obj));
}
#endif
@ -1420,7 +1420,7 @@ opt_mult
else if (HEAP_CLASS_OF(recv) == rb_cFloat &&
HEAP_CLASS_OF(obj) == rb_cFloat &&
BASIC_OP_UNREDEFINED_P(BOP_MULT)) {
val = DOUBLE2NUM(RFLOAT_VALUE(recv) * RFLOAT_VALUE(obj));
val = DBL2NUM(RFLOAT_VALUE(recv) * RFLOAT_VALUE(obj));
}
#endif
else {
@ -1484,7 +1484,7 @@ opt_div
else if (HEAP_CLASS_OF(recv) == rb_cFloat &&
HEAP_CLASS_OF(obj) == rb_cFloat &&
BASIC_OP_UNREDEFINED_P(BOP_DIV)) {
val = DOUBLE2NUM(RFLOAT_VALUE(recv) / RFLOAT_VALUE(obj));
val = DBL2NUM(RFLOAT_VALUE(recv) / RFLOAT_VALUE(obj));
}
#endif
else {
@ -1564,7 +1564,7 @@ opt_mod
mod += y;
div -= 1.0;
}
val = DOUBLE2NUM(mod);
val = DBL2NUM(mod);
}
else {
goto INSN_LABEL(normal_dispatch);

Просмотреть файл

@ -1306,7 +1306,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
d = strtod(ptr, &e);
d = load_mantissa(d, e, RSTRING_LEN(str) - (e - ptr));
}
v = DOUBLE2NUM(d);
v = DBL2NUM(d);
v = r_entry(v, arg);
v = r_leave(v, arg);
}

60
math.c
Просмотреть файл

@ -85,7 +85,7 @@ VALUE
math_atan2(VALUE obj, VALUE y, VALUE x)
{
Need_Float2(y, x);
return DOUBLE2NUM(atan2(RFLOAT_VALUE(y), RFLOAT_VALUE(x)));
return DBL2NUM(atan2(RFLOAT_VALUE(y), RFLOAT_VALUE(x)));
}
@ -101,7 +101,7 @@ VALUE
math_cos(VALUE obj, VALUE x)
{
Need_Float(x);
return DOUBLE2NUM(cos(RFLOAT_VALUE(x)));
return DBL2NUM(cos(RFLOAT_VALUE(x)));
}
/*
@ -117,7 +117,7 @@ math_sin(VALUE obj, VALUE x)
{
Need_Float(x);
return DOUBLE2NUM(sin(RFLOAT_VALUE(x)));
return DBL2NUM(sin(RFLOAT_VALUE(x)));
}
@ -133,7 +133,7 @@ math_tan(VALUE obj, VALUE x)
{
Need_Float(x);
return DOUBLE2NUM(tan(RFLOAT_VALUE(x)));
return DBL2NUM(tan(RFLOAT_VALUE(x)));
}
/*
@ -152,7 +152,7 @@ math_acos(VALUE obj, VALUE x)
errno = 0;
d = acos(RFLOAT_VALUE(x));
domain_check(d, "acos");
return DOUBLE2NUM(d);
return DBL2NUM(d);
}
/*
@ -171,7 +171,7 @@ math_asin(VALUE obj, VALUE x)
errno = 0;
d = asin(RFLOAT_VALUE(x));
domain_check(d, "asin");
return DOUBLE2NUM(d);
return DBL2NUM(d);
}
/*
@ -185,7 +185,7 @@ static VALUE
math_atan(VALUE obj, VALUE x)
{
Need_Float(x);
return DOUBLE2NUM(atan(RFLOAT_VALUE(x)));
return DBL2NUM(atan(RFLOAT_VALUE(x)));
}
#ifndef HAVE_COSH
@ -208,7 +208,7 @@ math_cosh(VALUE obj, VALUE x)
{
Need_Float(x);
return DOUBLE2NUM(cosh(RFLOAT_VALUE(x)));
return DBL2NUM(cosh(RFLOAT_VALUE(x)));
}
#ifndef HAVE_SINH
@ -231,7 +231,7 @@ VALUE
math_sinh(VALUE obj, VALUE x)
{
Need_Float(x);
return DOUBLE2NUM(sinh(RFLOAT_VALUE(x)));
return DBL2NUM(sinh(RFLOAT_VALUE(x)));
}
#ifndef HAVE_TANH
@ -254,7 +254,7 @@ static VALUE
math_tanh(VALUE obj, VALUE x)
{
Need_Float(x);
return DOUBLE2NUM(tanh(RFLOAT_VALUE(x)));
return DBL2NUM(tanh(RFLOAT_VALUE(x)));
}
/*
@ -273,7 +273,7 @@ math_acosh(VALUE obj, VALUE x)
errno = 0;
d = acosh(RFLOAT_VALUE(x));
domain_check(d, "acosh");
return DOUBLE2NUM(d);
return DBL2NUM(d);
}
/*
@ -287,7 +287,7 @@ static VALUE
math_asinh(VALUE obj, VALUE x)
{
Need_Float(x);
return DOUBLE2NUM(asinh(RFLOAT_VALUE(x)));
return DBL2NUM(asinh(RFLOAT_VALUE(x)));
}
/*
@ -307,7 +307,7 @@ math_atanh(VALUE obj, VALUE x)
d = atanh(RFLOAT_VALUE(x));
domain_check(d, "atanh");
infinity_check(x, d, "atanh");
return DOUBLE2NUM(d);
return DBL2NUM(d);
}
/*
@ -321,7 +321,7 @@ VALUE
math_exp(VALUE obj, VALUE x)
{
Need_Float(x);
return DOUBLE2NUM(exp(RFLOAT_VALUE(x)));
return DBL2NUM(exp(RFLOAT_VALUE(x)));
}
#if defined __CYGWIN__
@ -359,7 +359,7 @@ math_log(int argc, VALUE *argv)
}
domain_check(d, "log");
infinity_check(x, d, "log");
return DOUBLE2NUM(d);
return DBL2NUM(d);
}
#ifndef log2
@ -391,7 +391,7 @@ math_log2(VALUE obj, VALUE x)
d = log2(RFLOAT_VALUE(x));
domain_check(d, "log2");
infinity_check(x, d, "log2");
return DOUBLE2NUM(d);
return DBL2NUM(d);
}
/*
@ -411,7 +411,7 @@ math_log10(VALUE obj, VALUE x)
d = log10(RFLOAT_VALUE(x));
domain_check(d, "log10");
infinity_check(x, d, "log10");
return DOUBLE2NUM(d);
return DBL2NUM(d);
}
/*
@ -447,7 +447,7 @@ math_sqrt(VALUE obj, VALUE x)
errno = 0;
d = sqrt(RFLOAT_VALUE(x));
domain_check(d, "sqrt");
return DOUBLE2NUM(d);
return DBL2NUM(d);
}
/*
@ -486,7 +486,7 @@ static VALUE
math_cbrt(VALUE obj, VALUE x)
{
Need_Float(x);
return DOUBLE2NUM(cbrt(RFLOAT_VALUE(x)));
return DBL2NUM(cbrt(RFLOAT_VALUE(x)));
}
/*
@ -510,7 +510,7 @@ math_frexp(VALUE obj, VALUE x)
Need_Float(x);
d = frexp(RFLOAT_VALUE(x), &exp);
return rb_assoc_new(DOUBLE2NUM(d), INT2NUM(exp));
return rb_assoc_new(DBL2NUM(d), INT2NUM(exp));
}
/*
@ -527,7 +527,7 @@ static VALUE
math_ldexp(VALUE obj, VALUE x, VALUE n)
{
Need_Float(x);
return DOUBLE2NUM(ldexp(RFLOAT_VALUE(x), NUM2INT(n)));
return DBL2NUM(ldexp(RFLOAT_VALUE(x), NUM2INT(n)));
}
/*
@ -544,7 +544,7 @@ VALUE
math_hypot(VALUE obj, VALUE x, VALUE y)
{
Need_Float2(x, y);
return DOUBLE2NUM(hypot(RFLOAT_VALUE(x), RFLOAT_VALUE(y)));
return DBL2NUM(hypot(RFLOAT_VALUE(x), RFLOAT_VALUE(y)));
}
/*
@ -558,7 +558,7 @@ static VALUE
math_erf(VALUE obj, VALUE x)
{
Need_Float(x);
return DOUBLE2NUM(erf(RFLOAT_VALUE(x)));
return DBL2NUM(erf(RFLOAT_VALUE(x)));
}
/*
@ -572,7 +572,7 @@ static VALUE
math_erfc(VALUE obj, VALUE x)
{
Need_Float(x);
return DOUBLE2NUM(erfc(RFLOAT_VALUE(x)));
return DBL2NUM(erfc(RFLOAT_VALUE(x)));
}
/*
@ -624,7 +624,7 @@ math_gamma(VALUE obj, VALUE x)
errno = 0;
d = tgamma(RFLOAT_VALUE(x));
domain_check(d, "gamma");
return DOUBLE2NUM(d);
return DBL2NUM(d);
}
/*
@ -649,7 +649,7 @@ math_lgamma(VALUE obj, VALUE x)
errno = 0;
d = lgamma_r(RFLOAT_VALUE(x), &sign);
domain_check(d, "lgamma");
v = DOUBLE2NUM(d);
v = DBL2NUM(d);
return rb_assoc_new(v, INT2FIX(sign));
}
@ -667,15 +667,15 @@ Init_Math(void)
rb_mMath = rb_define_module("Math");
#ifdef M_PI
rb_define_const(rb_mMath, "PI", DOUBLE2NUM(M_PI));
rb_define_const(rb_mMath, "PI", DBL2NUM(M_PI));
#else
rb_define_const(rb_mMath, "PI", DOUBLE2NUM(atan(1.0)*4.0));
rb_define_const(rb_mMath, "PI", DBL2NUM(atan(1.0)*4.0));
#endif
#ifdef M_E
rb_define_const(rb_mMath, "E", DOUBLE2NUM(M_E));
rb_define_const(rb_mMath, "E", DBL2NUM(M_E));
#else
rb_define_const(rb_mMath, "E", DOUBLE2NUM(exp(1.0)));
rb_define_const(rb_mMath, "E", DBL2NUM(exp(1.0)));
#endif
rb_define_module_function(rb_mMath, "atan2", math_atan2, 2);

Просмотреть файл

@ -562,7 +562,7 @@ flo_coerce(VALUE x, VALUE y)
static VALUE
flo_uminus(VALUE flt)
{
return DOUBLE2NUM(-RFLOAT_VALUE(flt));
return DBL2NUM(-RFLOAT_VALUE(flt));
}
/*
@ -578,11 +578,11 @@ flo_plus(VALUE x, VALUE y)
{
switch (TYPE(y)) {
case T_FIXNUM:
return DOUBLE2NUM(RFLOAT_VALUE(x) + (double)FIX2LONG(y));
return DBL2NUM(RFLOAT_VALUE(x) + (double)FIX2LONG(y));
case T_BIGNUM:
return DOUBLE2NUM(RFLOAT_VALUE(x) + rb_big2dbl(y));
return DBL2NUM(RFLOAT_VALUE(x) + rb_big2dbl(y));
case T_FLOAT:
return DOUBLE2NUM(RFLOAT_VALUE(x) + RFLOAT_VALUE(y));
return DBL2NUM(RFLOAT_VALUE(x) + RFLOAT_VALUE(y));
default:
return rb_num_coerce_bin(x, y, '+');
}
@ -601,11 +601,11 @@ flo_minus(VALUE x, VALUE y)
{
switch (TYPE(y)) {
case T_FIXNUM:
return DOUBLE2NUM(RFLOAT_VALUE(x) - (double)FIX2LONG(y));
return DBL2NUM(RFLOAT_VALUE(x) - (double)FIX2LONG(y));
case T_BIGNUM:
return DOUBLE2NUM(RFLOAT_VALUE(x) - rb_big2dbl(y));
return DBL2NUM(RFLOAT_VALUE(x) - rb_big2dbl(y));
case T_FLOAT:
return DOUBLE2NUM(RFLOAT_VALUE(x) - RFLOAT_VALUE(y));
return DBL2NUM(RFLOAT_VALUE(x) - RFLOAT_VALUE(y));
default:
return rb_num_coerce_bin(x, y, '-');
}
@ -624,11 +624,11 @@ flo_mul(VALUE x, VALUE y)
{
switch (TYPE(y)) {
case T_FIXNUM:
return DOUBLE2NUM(RFLOAT_VALUE(x) * (double)FIX2LONG(y));
return DBL2NUM(RFLOAT_VALUE(x) * (double)FIX2LONG(y));
case T_BIGNUM:
return DOUBLE2NUM(RFLOAT_VALUE(x) * rb_big2dbl(y));
return DBL2NUM(RFLOAT_VALUE(x) * rb_big2dbl(y));
case T_FLOAT:
return DOUBLE2NUM(RFLOAT_VALUE(x) * RFLOAT_VALUE(y));
return DBL2NUM(RFLOAT_VALUE(x) * RFLOAT_VALUE(y));
default:
return rb_num_coerce_bin(x, y, '*');
}
@ -651,12 +651,12 @@ flo_div(VALUE x, VALUE y)
switch (TYPE(y)) {
case T_FIXNUM:
f_y = FIX2LONG(y);
return DOUBLE2NUM(RFLOAT_VALUE(x) / (double)f_y);
return DBL2NUM(RFLOAT_VALUE(x) / (double)f_y);
case T_BIGNUM:
d = rb_big2dbl(y);
return DOUBLE2NUM(RFLOAT_VALUE(x) / d);
return DBL2NUM(RFLOAT_VALUE(x) / d);
case T_FLOAT:
return DOUBLE2NUM(RFLOAT_VALUE(x) / RFLOAT_VALUE(y));
return DBL2NUM(RFLOAT_VALUE(x) / RFLOAT_VALUE(y));
default:
return rb_num_coerce_bin(x, y, '/');
}
@ -726,7 +726,7 @@ flo_mod(VALUE x, VALUE y)
return rb_num_coerce_bin(x, y, '%');
}
flodivmod(RFLOAT_VALUE(x), fy, 0, &mod);
return DOUBLE2NUM(mod);
return DBL2NUM(mod);
}
static VALUE
@ -773,7 +773,7 @@ flo_divmod(VALUE x, VALUE y)
}
flodivmod(RFLOAT_VALUE(x), fy, &div, &mod);
a = dbl2ival(div);
b = DOUBLE2NUM(mod);
b = DBL2NUM(mod);
return rb_assoc_new(a, b);
}
@ -790,11 +790,11 @@ flo_pow(VALUE x, VALUE y)
{
switch (TYPE(y)) {
case T_FIXNUM:
return DOUBLE2NUM(pow(RFLOAT_VALUE(x), (double)FIX2LONG(y)));
return DBL2NUM(pow(RFLOAT_VALUE(x), (double)FIX2LONG(y)));
case T_BIGNUM:
return DOUBLE2NUM(pow(RFLOAT_VALUE(x), rb_big2dbl(y)));
return DBL2NUM(pow(RFLOAT_VALUE(x), rb_big2dbl(y)));
case T_FLOAT:
return DOUBLE2NUM(pow(RFLOAT_VALUE(x), RFLOAT_VALUE(y)));
return DBL2NUM(pow(RFLOAT_VALUE(x), RFLOAT_VALUE(y)));
default:
return rb_num_coerce_bin(x, y, rb_intern("**"));
}
@ -1130,7 +1130,7 @@ static VALUE
flo_abs(VALUE flt)
{
double val = fabs(RFLOAT_VALUE(flt));
return DOUBLE2NUM(val);
return DBL2NUM(val);
}
/*
@ -1312,7 +1312,7 @@ flo_round(int argc, VALUE *argv, VALUE num)
else number /= f;
}
if (ndigits > 0) return DOUBLE2NUM(number);
if (ndigits > 0) return DBL2NUM(number);
if (!FIXABLE(number)) {
return rb_dbl2big(number);
@ -1501,7 +1501,7 @@ num_step(int argc, VALUE *argv, VALUE from)
if (err>0.5) err=0.5;
n = floor(n + err) + 1;
for (i=0; i<n; i++) {
rb_yield(DOUBLE2NUM(i*unit+beg));
rb_yield(DBL2NUM(i*unit+beg));
}
}
else {
@ -2106,7 +2106,7 @@ fix_plus(VALUE x, VALUE y)
case T_BIGNUM:
return rb_big_plus(y, x);
case T_FLOAT:
return DOUBLE2NUM((double)FIX2LONG(x) + RFLOAT_VALUE(y));
return DBL2NUM((double)FIX2LONG(x) + RFLOAT_VALUE(y));
default:
return rb_num_coerce_bin(x, y, '+');
}
@ -2140,7 +2140,7 @@ fix_minus(VALUE x, VALUE y)
x = rb_int2big(FIX2LONG(x));
return rb_big_minus(x, y);
case T_FLOAT:
return DOUBLE2NUM((double)FIX2LONG(x) - RFLOAT_VALUE(y));
return DBL2NUM((double)FIX2LONG(x) - RFLOAT_VALUE(y));
default:
return rb_num_coerce_bin(x, y, '-');
}
@ -2199,7 +2199,7 @@ fix_mul(VALUE x, VALUE y)
case T_BIGNUM:
return rb_big_mul(y, x);
case T_FLOAT:
return DOUBLE2NUM((double)FIX2LONG(x) * RFLOAT_VALUE(y));
return DBL2NUM((double)FIX2LONG(x) * RFLOAT_VALUE(y));
default:
return rb_num_coerce_bin(x, y, '*');
}
@ -2248,13 +2248,13 @@ static VALUE
fix_fdiv(VALUE x, VALUE y)
{
if (FIXNUM_P(y)) {
return DOUBLE2NUM((double)FIX2LONG(x) / (double)FIX2LONG(y));
return DBL2NUM((double)FIX2LONG(x) / (double)FIX2LONG(y));
}
switch (TYPE(y)) {
case T_BIGNUM:
return DOUBLE2NUM((double)FIX2LONG(x) / rb_big2dbl(y));
return DBL2NUM((double)FIX2LONG(x) / rb_big2dbl(y));
case T_FLOAT:
return DOUBLE2NUM((double)FIX2LONG(x) / RFLOAT_VALUE(y));
return DBL2NUM((double)FIX2LONG(x) / RFLOAT_VALUE(y));
default:
return rb_num_coerce_bin(x, y, rb_intern("fdiv"));
}
@ -2279,7 +2279,7 @@ fix_divide(VALUE x, VALUE y, ID op)
if (op == '/') {
div = (double)FIX2LONG(x) / RFLOAT_VALUE(y);
return DOUBLE2NUM(div);
return DBL2NUM(div);
}
else {
if (RFLOAT_VALUE(y) == 0) rb_num_zerodiv();
@ -2347,7 +2347,7 @@ fix_mod(VALUE x, VALUE y)
double mod;
flodivmod((double)FIX2LONG(x), RFLOAT_VALUE(y), 0, &mod);
return DOUBLE2NUM(mod);
return DBL2NUM(mod);
}
default:
return rb_num_coerce_bin(x, y, '%');
@ -2381,7 +2381,7 @@ fix_divmod(VALUE x, VALUE y)
flodivmod((double)FIX2LONG(x), RFLOAT_VALUE(y), &div, &mod);
a = dbl2ival(div);
b = DOUBLE2NUM(mod);
b = DBL2NUM(mod);
return rb_assoc_new(a, b);
}
default:
@ -2453,7 +2453,7 @@ fix_pow(VALUE x, VALUE y)
if (b == 1) return x;
if (a == 0) {
if (b > 0) return INT2FIX(0);
return DOUBLE2NUM(1.0 / zero);
return DBL2NUM(1.0 / zero);
}
if (a == 1) return INT2FIX(1);
if (a == -1) {
@ -2479,12 +2479,12 @@ fix_pow(VALUE x, VALUE y)
x = rb_int2big(FIX2LONG(x));
return rb_big_pow(x, y);
case T_FLOAT:
if (RFLOAT_VALUE(y) == 0.0) return DOUBLE2NUM(1.0);
if (RFLOAT_VALUE(y) == 0.0) return DBL2NUM(1.0);
if (a == 0) {
return DOUBLE2NUM(RFLOAT_VALUE(y) < 0 ? (1.0 / zero) : 0.0);
return DBL2NUM(RFLOAT_VALUE(y) < 0 ? (1.0 / zero) : 0.0);
}
if (a == 1) return DOUBLE2NUM(1.0);
return DOUBLE2NUM(pow((double)a, RFLOAT_VALUE(y)));
if (a == 1) return DBL2NUM(1.0);
return DBL2NUM(pow((double)a, RFLOAT_VALUE(y)));
default:
return rb_num_coerce_bin(x, y, rb_intern("**"));
}
@ -2854,7 +2854,7 @@ fix_to_f(VALUE num)
val = (double)FIX2LONG(num);
return DOUBLE2NUM(val);
return DBL2NUM(val);
}
/*
@ -3245,9 +3245,9 @@ Init_Numeric(void)
rb_define_const(rb_cFloat, "MAX_EXP", INT2FIX(DBL_MAX_EXP));
rb_define_const(rb_cFloat, "MIN_10_EXP", INT2FIX(DBL_MIN_10_EXP));
rb_define_const(rb_cFloat, "MAX_10_EXP", INT2FIX(DBL_MAX_10_EXP));
rb_define_const(rb_cFloat, "MIN", DOUBLE2NUM(DBL_MIN));
rb_define_const(rb_cFloat, "MAX", DOUBLE2NUM(DBL_MAX));
rb_define_const(rb_cFloat, "EPSILON", DOUBLE2NUM(DBL_EPSILON));
rb_define_const(rb_cFloat, "MIN", DBL2NUM(DBL_MIN));
rb_define_const(rb_cFloat, "MAX", DBL2NUM(DBL_MAX));
rb_define_const(rb_cFloat, "EPSILON", DBL2NUM(DBL_EPSILON));
rb_define_method(rb_cFloat, "to_s", flo_to_s, 0);
rb_define_method(rb_cFloat, "coerce", flo_coerce, 1);

Просмотреть файл

@ -850,7 +850,7 @@ nil_to_i(VALUE obj)
static VALUE
nil_to_f(VALUE obj)
{
return DOUBLE2NUM(0.0);
return DBL2NUM(0.0);
}
/*
@ -2230,16 +2230,16 @@ rb_Float(VALUE val)
{
switch (TYPE(val)) {
case T_FIXNUM:
return DOUBLE2NUM((double)FIX2LONG(val));
return DBL2NUM((double)FIX2LONG(val));
case T_FLOAT:
return val;
case T_BIGNUM:
return DOUBLE2NUM(rb_big2dbl(val));
return DBL2NUM(rb_big2dbl(val));
case T_STRING:
return DOUBLE2NUM(rb_str_to_dbl(val, Qtrue));
return DBL2NUM(rb_str_to_dbl(val, Qtrue));
case T_NIL:
rb_raise(rb_eTypeError, "can't convert nil into Float");

12
pack.c
Просмотреть файл

@ -1649,7 +1649,7 @@ pack_unpack(VALUE str, VALUE fmt)
float tmp;
memcpy(&tmp, s, sizeof(float));
s += sizeof(float);
UNPACK_PUSH(DOUBLE2NUM((double)tmp));
UNPACK_PUSH(DBL2NUM((double)tmp));
}
PACK_ITEM_ADJUST();
break;
@ -1663,7 +1663,7 @@ pack_unpack(VALUE str, VALUE fmt)
memcpy(&tmp, s, sizeof(float));
s += sizeof(float);
tmp = VTOHF(tmp,ftmp);
UNPACK_PUSH(DOUBLE2NUM((double)tmp));
UNPACK_PUSH(DBL2NUM((double)tmp));
}
PACK_ITEM_ADJUST();
break;
@ -1677,7 +1677,7 @@ pack_unpack(VALUE str, VALUE fmt)
memcpy(&tmp, s, sizeof(double));
s += sizeof(double);
tmp = VTOHD(tmp,dtmp);
UNPACK_PUSH(DOUBLE2NUM(tmp));
UNPACK_PUSH(DBL2NUM(tmp));
}
PACK_ITEM_ADJUST();
break;
@ -1689,7 +1689,7 @@ pack_unpack(VALUE str, VALUE fmt)
double tmp;
memcpy(&tmp, s, sizeof(double));
s += sizeof(double);
UNPACK_PUSH(DOUBLE2NUM(tmp));
UNPACK_PUSH(DBL2NUM(tmp));
}
PACK_ITEM_ADJUST();
break;
@ -1703,7 +1703,7 @@ pack_unpack(VALUE str, VALUE fmt)
memcpy(&tmp, s, sizeof(float));
s += sizeof(float);
tmp = NTOHF(tmp,ftmp);
UNPACK_PUSH(DOUBLE2NUM((double)tmp));
UNPACK_PUSH(DBL2NUM((double)tmp));
}
PACK_ITEM_ADJUST();
break;
@ -1717,7 +1717,7 @@ pack_unpack(VALUE str, VALUE fmt)
memcpy(&tmp, s, sizeof(double));
s += sizeof(double);
tmp = NTOHD(tmp,dtmp);
UNPACK_PUSH(DOUBLE2NUM(tmp));
UNPACK_PUSH(DBL2NUM(tmp));
}
PACK_ITEM_ADJUST();
break;

Просмотреть файл

@ -6920,7 +6920,7 @@ parser_yylex(struct parser_params *parser)
rb_warningS("Float %s out of range", tok());
errno = 0;
}
set_yylval_literal(DOUBLE2NUM(d));
set_yylval_literal(DBL2NUM(d));
return tFLOAT;
}
set_yylval_literal(rb_cstr_to_inum(tok(), 10, Qfalse));

Просмотреть файл

@ -5047,10 +5047,10 @@ rb_proc_times(VALUE obj)
times(&buf);
return rb_struct_new(rb_cProcessTms,
utime = DOUBLE2NUM(buf.tms_utime / hertz),
stime = DOUBLE2NUM(buf.tms_stime / hertz),
cutime = DOUBLE2NUM(buf.tms_cutime / hertz),
sctime = DOUBLE2NUM(buf.tms_cstime / hertz));
utime = DBL2NUM(buf.tms_utime / hertz),
stime = DBL2NUM(buf.tms_stime / hertz),
cutime = DBL2NUM(buf.tms_cutime / hertz),
sctime = DBL2NUM(buf.tms_cstime / hertz));
#else
rb_notimplement();
#endif

Просмотреть файл

@ -505,7 +505,7 @@ rb_f_rand(int argc, VALUE *argv, VALUE obj)
limit = (struct RBignum *)rb_big_minus((VALUE)limit, INT2FIX(1));
if (FIXNUM_P((VALUE)limit)) {
if (FIX2LONG((VALUE)limit) == -1)
return DOUBLE2NUM(genrand_real(mt));
return DBL2NUM(genrand_real(mt));
return LONG2NUM(limited_rand(mt, FIX2LONG((VALUE)limit)));
}
return limited_big_rand(mt, limit);
@ -522,7 +522,7 @@ rb_f_rand(int argc, VALUE *argv, VALUE obj)
}
if (max == 0) {
return DOUBLE2NUM(genrand_real(mt));
return DBL2NUM(genrand_real(mt));
}
if (max < 0) max = -max;
val = limited_rand(mt, max-1);

Просмотреть файл

@ -3763,7 +3763,7 @@ rb_str_to_i(int argc, VALUE *argv, VALUE str)
static VALUE
rb_str_to_f(VALUE str)
{
return DOUBLE2NUM(rb_str_to_dbl(str, Qfalse));
return DBL2NUM(rb_str_to_dbl(str, Qfalse));
}

4
time.c
Просмотреть файл

@ -1016,7 +1016,7 @@ time_to_f(VALUE time)
struct time_object *tobj;
GetTimeval(time, tobj);
return DOUBLE2NUM((double)tobj->ts.tv_sec+(double)tobj->ts.tv_nsec/1e9);
return DBL2NUM((double)tobj->ts.tv_sec+(double)tobj->ts.tv_nsec/1e9);
}
/*
@ -1513,7 +1513,7 @@ time_minus(VALUE time1, VALUE time2)
f = (double)(unsigned_time_t)(tobj->ts.tv_sec - tobj2->ts.tv_sec);
f += ((double)tobj->ts.tv_nsec - (double)tobj2->ts.tv_nsec)*1e-9;
return DOUBLE2NUM(f);
return DBL2NUM(f);
}
return time_add(tobj, time2, -1);
}