Skip to content

Commit

Permalink
* include/ruby/ruby.h: introduce 2 macros:
Browse files Browse the repository at this point in the history
  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
  • Loading branch information
ko1 committed Nov 13, 2007
1 parent c4af7f5 commit 25c0cb9
Show file tree
Hide file tree
Showing 17 changed files with 213 additions and 197 deletions.
14 changes: 14 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
Wed Nov 14 00:33:49 2007 Koichi Sasada <[email protected]>

* 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.

Wed Nov 14 00:15:37 2007 Nobuyoshi Nakada <[email protected]>

* tool/ytab.sed: get rid of GNU sed feature. a patch from Laurent
Expand Down
26 changes: 13 additions & 13 deletions bignum.c
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ rb_big2dbl(VALUE x)
static VALUE
rb_big_to_f(VALUE x)
{
return rb_float_new(rb_big2dbl(x));
return DOUBLE2NUM(rb_big2dbl(x));
}

/*
Expand All @@ -1174,7 +1174,7 @@ rb_big_cmp(VALUE x, VALUE y)
break;

case T_FLOAT:
return rb_dbl_cmp(rb_big2dbl(x), RFLOAT(y)->value);
return rb_dbl_cmp(rb_big2dbl(x), RFLOAT_VALUE(y));

default:
return rb_num_coerce_cmp(x, y);
Expand Down Expand Up @@ -1218,7 +1218,7 @@ rb_big_eq(VALUE x, VALUE y)
{
volatile double a, b;

a = RFLOAT(y)->value;
a = RFLOAT_VALUE(y);
if (isnan(a)) return Qfalse;
b = rb_big2dbl(x);
return (a == b)?Qtrue:Qfalse;
Expand Down Expand Up @@ -1409,7 +1409,7 @@ rb_big_plus(VALUE x, VALUE y)
return bignorm(bigadd(x, y, 1));

case T_FLOAT:
return rb_float_new(rb_big2dbl(x) + RFLOAT(y)->value);
return DOUBLE2NUM(rb_big2dbl(x) + RFLOAT_VALUE(y));

default:
return rb_num_coerce_bin(x, y);
Expand All @@ -1434,7 +1434,7 @@ rb_big_minus(VALUE x, VALUE y)
return bignorm(bigadd(x, y, 0));

case T_FLOAT:
return rb_float_new(rb_big2dbl(x) - RFLOAT(y)->value);
return DOUBLE2NUM(rb_big2dbl(x) - RFLOAT_VALUE(y));

default:
return rb_num_coerce_bin(x, y);
Expand All @@ -1458,7 +1458,7 @@ rb_big_mul0(VALUE x, VALUE y)
break;

case T_FLOAT:
return rb_float_new(rb_big2dbl(x) * RFLOAT(y)->value);
return DOUBLE2NUM(rb_big2dbl(x) * RFLOAT_VALUE(y));

default:
return rb_num_coerce_bin(x, y);
Expand Down Expand Up @@ -1664,7 +1664,7 @@ rb_big_div(VALUE x, VALUE y)
break;

case T_FLOAT:
return rb_float_new(rb_big2dbl(x) / RFLOAT(y)->value);
return DOUBLE2NUM(rb_big2dbl(x) / RFLOAT_VALUE(y));

default:
return rb_num_coerce_bin(x, y);
Expand Down Expand Up @@ -1834,10 +1834,10 @@ rb_big_quo(VALUE x, VALUE y)
if (ey) y = big_shift(y, ey);
bignum:
bigdivrem(x, y, &z, 0);
return rb_float_new(ldexp(big2dbl(z), ex - ey));
return DOUBLE2NUM(ldexp(big2dbl(z), ex - ey));
}
case T_FLOAT:
y = dbl2big(ldexp(frexp(RFLOAT(y)->value, &ey), DBL_MANT_DIG));
y = dbl2big(ldexp(frexp(RFLOAT_VALUE(y), &ey), DBL_MANT_DIG));
ey -= DBL_MANT_DIG;
goto bignum;
}
Expand All @@ -1852,13 +1852,13 @@ rb_big_quo(VALUE x, VALUE y)
break;

case T_FLOAT:
dy = RFLOAT(y)->value;
dy = RFLOAT_VALUE(y);
break;

default:
return rb_num_coerce_bin(x, y);
}
return rb_float_new(dx / dy);
return DOUBLE2NUM(dx / dy);
}

static VALUE
Expand Down Expand Up @@ -1930,7 +1930,7 @@ rb_big_pow(VALUE x, VALUE y)
if (y == INT2FIX(0)) return INT2FIX(1);
switch (TYPE(y)) {
case T_FLOAT:
d = RFLOAT(y)->value;
d = RFLOAT_VALUE(y);
break;

case T_BIGNUM:
Expand Down Expand Up @@ -1965,7 +1965,7 @@ rb_big_pow(VALUE x, VALUE y)
default:
return rb_num_coerce_bin(x, y);
}
return rb_float_new(pow(rb_big2dbl(x), d));
return DOUBLE2NUM(pow(rb_big2dbl(x), d));
}

/*
Expand Down
4 changes: 2 additions & 2 deletions ext/dl/mkcallback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@
FLOAT => {
:name => 'float',
:type => 'float',
:conv => 'RFLOAT(%s)->value',
:conv => 'RFLOAT_VALUE(%s)',
},
DOUBLE => {
:name => 'double',
:type => 'double',
:conv => 'RFLOAT(%s)->value',
:conv => 'RFLOAT_VALUE(%s)',
},
VOIDP => {
:name => 'ptr',
Expand Down
2 changes: 1 addition & 1 deletion ext/json/ext/generator/generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ static VALUE mFloat_to_json(int argc, VALUE *argv, VALUE self)
{
JSON_Generator_State *state = NULL;
VALUE Vstate, rest, tmp;
double value = RFLOAT(self)->value;
double value = RFLOAT_VALUE(self);
rb_scan_args(argc, argv, "01*", &Vstate, &rest);
if (!NIL_P(Vstate)) Data_Get_Struct(Vstate, JSON_Generator_State, state);
if (isinf(value)) {
Expand Down
4 changes: 3 additions & 1 deletion include/ruby/ruby.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,10 @@ struct RClass {

struct RFloat {
struct RBasic basic;
double value;
double double_value;
};
#define RFLOAT_VALUE(v) (RFLOAT(v)->double_value)
#define DOUBLE2NUM(dbl) rb_float_new(dbl)

#define ELTS_SHARED FL_USER2

Expand Down
16 changes: 8 additions & 8 deletions insns.def
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,7 @@ opt_plus
else if (HEAP_CLASS_OF(recv) == rb_cFloat &&
HEAP_CLASS_OF(obj) == rb_cFloat &&
BASIC_OP_UNREDEFINED_P(BOP_PLUS)) {
val = rb_float_new(RFLOAT(recv)->value + RFLOAT(obj)->value);
val = DOUBLE2NUM(RFLOAT_VALUE(recv) + RFLOAT_VALUE(obj));
}
#endif

Expand Down Expand Up @@ -1492,7 +1492,7 @@ opt_mult
else if (HEAP_CLASS_OF(recv) == rb_cFloat &&
HEAP_CLASS_OF(obj) == rb_cFloat &&
BASIC_OP_UNREDEFINED_P(BOP_MULT)) {
val = rb_float_new(RFLOAT(recv)->value * RFLOAT(obj)->value);
val = DOUBLE2NUM(RFLOAT_VALUE(recv) * RFLOAT_VALUE(obj));
}
#endif
else {
Expand Down Expand Up @@ -1556,7 +1556,7 @@ opt_div
else if (HEAP_CLASS_OF(recv) == rb_cFloat &&
HEAP_CLASS_OF(obj) == rb_cFloat &&
BASIC_OP_UNREDEFINED_P(BOP_DIV)) {
val = rb_float_new(RFLOAT(recv)->value / RFLOAT(obj)->value);
val = DOUBLE2NUM(RFLOAT_VALUE(recv) / RFLOAT_VALUE(obj));
}
#endif
else {
Expand Down Expand Up @@ -1620,8 +1620,8 @@ opt_mod
else if (HEAP_CLASS_OF(recv) == rb_cFloat &&
HEAP_CLASS_OF(obj) == rb_cFloat &&
BASIC_OP_UNREDEFINED_P(BOP_MOD)) {
double x = RFLOAT(recv)->value;
double y = RFLOAT(obj)->value;
double x = RFLOAT_VALUE(recv);
double y = RFLOAT_VALUE(obj);
double div, mod;

{
Expand All @@ -1636,7 +1636,7 @@ opt_mod
mod += y;
div -= 1.0;
}
val = rb_float_new(mod);
val = DOUBLE2NUM(mod);
}
else {
goto INSN_LABEL(normal_dispatch);
Expand Down Expand Up @@ -1678,8 +1678,8 @@ opt_eq
else if (HEAP_CLASS_OF(recv) == rb_cFloat &&
HEAP_CLASS_OF(obj) == rb_cFloat &&
BASIC_OP_UNREDEFINED_P(BOP_EQ)) {
double a = RFLOAT(recv)->value;
double b = RFLOAT(obj)->value;
double a = RFLOAT_VALUE(recv);
double b = RFLOAT_VALUE(obj);

if (isnan(a) || isnan(b)) {
val = Qfalse;
Expand Down
4 changes: 2 additions & 2 deletions marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)

case T_FLOAT:
w_byte(TYPE_FLOAT, arg);
w_float(RFLOAT(obj)->value, arg);
w_float(RFLOAT_VALUE(obj), arg);
break;

case T_BIGNUM:
Expand Down Expand Up @@ -1239,7 +1239,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 = rb_float_new(d);
v = DOUBLE2NUM(d);
v = r_entry(v, arg);
v = r_leave(v, arg);
}
Expand Down
Loading

0 comments on commit 25c0cb9

Please sign in to comment.