e$B$(!<$H!"@7W<T$O!Ve(Bfdive$B$O7k2L$,e(Bfloate$B$K$J$ke(Bdive$B!W$/$i$$$7$+9M$(e(B
e$B$F$$$^$;$s$G$7$?$7!"Dj5A$H$7$F$O!Ve(BFloat(x)/Float(y)e$B!W$rA[Dje(B
e$B$7$F$$$?$O$:$G$9!#$J$s$Ge(BBignume$B$,8=:$N$h$&$K$J$C$F$$$k$N$+==e(B
e$BJ,$KGD0.$7$F$$$J$$$N$G$9$,!#e(B
e$BKM$b$=$l$/$i$$$K$7$+9M$($F$$$^$;$s$G$7$?!#:G6a$K$J$C$Fe(B fdiv
e$B$N0UL#$Ke(Be$B5$e(B
e$B$,IU$$$?e(Be$B$N$G$9$,!"$h$/8+$k$H$H$F$bCfESH>C<$J$s$G$9$M!#e(B
[ruby-dev:38636]e$B$N%Q%C%A$G$O!Ve(BFloat(x/y)e$B!W$r:NMQ$7$F$*$i$l$ke(B
e$B$h$&$G$9$,!"$=$l$O$3$A$i$NJ}$,JXMx$J$3$H$,$"$k$H8@$&0UL#$G$7$ge(B
e$B$&$+!#e(B
e$B:#$O$=$&;W$C$F$$$^$9!#e(BFloat(x)/Float(y)
e$B$H$$$&2r<a$@$HN,5-K!$H$$$&0UL#e(B
e$B$7$+$J$$$G$9$,!"e(BFloat(x/y) e$B$O$=$&$8$c$J$$$N$G!#e(B
e$B8=>u$G$Oe(B
1.fdiv(Float::MAX.to_i2) #=> 0.0
Float::MAX.to_i.fdiv(Float::MAX.to_i2) #=> 0.0
Rational(Float::MAX.to_i*2).fdiv(2) #=> Infinity
e$B$G$9$,!"e(B
1.fdiv(Float::MAX.to_i2) #=> 2.781342323134002e-309
Float::MAX.to_i.fdiv(Float::MAX.to_i2) #=> 0.5
Rational(Float::MAX.to_i*2).fdiv(2) #=> 1.7976931348623157e+308
e$B$H$J$k$N$G!#e(B
e$B@hDx$N%Q%C%A$O!"$J$<$+e(B numeric.c
e$B$N=$@5$,<:$J$o$l$F$$$?$N$G!"$H$j$"$($:!"e(B
e$B$b$&0lEYAw$j$J$*$7$^$9!#e(B
Index: complex.c
— complex.c (revision 23694)
+++ complex.c (working copy)
@@ -660,6 +660,7 @@
static VALUE
nucomp_fdiv(VALUE self, VALUE other)
{
- rb_warning(“Complex#fdiv will be deprecated in the future”);
return nucomp_divide(self, other, f_fdiv, id_fdiv);
}
Index: numeric.c
— numeric.c (revision 23694)
+++ numeric.c (working copy)
@@ -2269,6 +2269,8 @@
*
*/
+VALUE rb_big_fdiv(VALUE x, VALUE y);
+
static VALUE
fix_fdiv(VALUE x, VALUE y)
{
@@ -2277,7 +2279,7 @@
}
switch (TYPE(y)) {
case T_BIGNUM:
- return DBL2NUM((double)FIX2LONG(x) / rb_big2dbl(y));
- return rb_big_fdiv(rb_int2big(FIX2LONG(x)), y);
case T_FLOAT:
return DBL2NUM((double)FIX2LONG(x) / RFLOAT_VALUE(y));
default:
Index: bignum.c
===================================================================
— bignum.c (revision 23695)
+++ bignum.c (working copy)
@@ -2385,6 +2385,53 @@
return x;
}
+static VALUE
+big_fdiv(VALUE x, VALUE y)
+{
+#define DBL_BIGDIG ((DBL_MANT_DIG + BITSPERDIG) / BITSPERDIG)
- VALUE z;
- long l, ex, ey;
- int i;
-
- bigtrunc(x);
- l = RBIGNUM_LEN(x) - 1;
- ex = l * BITSPERDIG;
- ex += bdigbitsize(BDIGITS(x)[l]);
- ex -= 2 * DBL_BIGDIG * BITSPERDIG;
- if (ex) x = big_shift(x, ex);
-
- switch (TYPE(y)) {
-
case T_FIXNUM:
- y = rb_int2big(FIX2LONG(y));
-
case T_BIGNUM: {
- bigtrunc(y);
- l = RBIGNUM_LEN(y) - 1;
- ey = l * BITSPERDIG;
- ey += bdigbitsize(BDIGITS(y)[l]);
- ey -= DBL_BIGDIG * BITSPERDIG;
- if (ey) y = big_shift(y, ey);
- bignum:
- bigdivrem(x, y, &z, 0);
- l = ex - ey;
+#if SIZEOF_LONG > SIZEOF_INT
- {
-
/* Visual C++ can't be here */
-
if (l > INT_MAX) return DBL2NUM(ruby_div0(1.0));
-
if (l < INT_MIN) return DBL2NUM(0.0);
- }
+#endif
- return DBL2NUM(ldexp(big2dbl(z), (int)l));
-
}
-
case T_FLOAT:
- y = dbl2big(ldexp(frexp(RFLOAT_VALUE(y), &i), DBL_MANT_DIG));
- ey = i - DBL_MANT_DIG;
- goto bignum;
- }
- /* NOTREACHED */
- abort();
- return Qnil;
+}
-
/*
@@ -2397,65 +2444,32 @@
*
*/
-static VALUE
+
+VALUE
rb_big_fdiv(VALUE x, VALUE y)
{
- double dx = big2dbl(x);
- double dy;
- if (isinf(dx)) {
-#define DBL_BIGDIG ((DBL_MANT_DIG + BITSPERDIG) / BITSPERDIG)
- VALUE z;
- long l, ex, ey;
- int i;
-
- bigtrunc(x);
- l = RBIGNUM_LEN(x) - 1;
- ex = l * BITSPERDIG;
- ex += bdigbitsize(BDIGITS(x)[l]);
- ex -= 2 * DBL_BIGDIG * BITSPERDIG;
- if (ex) x = big_shift(x, ex);
-
- switch (TYPE(y)) {
- case T_FIXNUM:
-
y = rb_int2big(FIX2LONG(y));
- case T_BIGNUM: {
-
bigtrunc(y);
-
l = RBIGNUM_LEN(y) - 1;
-
ey = l * BITSPERDIG;
-
ey += bdigbitsize(BDIGITS(y)[l]);
-
ey -= DBL_BIGDIG * BITSPERDIG;
-
if (ey) y = big_shift(y, ey);
- bignum:
-
bigdivrem(x, y, &z, 0);
-
l = ex - ey;
-#if SIZEOF_LONG > SIZEOF_INT
-
{
- /* Visual C++ can’t be here */
- if (l > INT_MAX) return DBL2NUM(ruby_div0(1.0));
- if (l < INT_MIN) return DBL2NUM(0.0);
-
}
-#endif
-
return DBL2NUM(ldexp(big2dbl(z), (int)l));
- }
- case T_FLOAT:
-
if (isnan(RFLOAT_VALUE(y))) return y;
-
y = dbl2big(ldexp(frexp(RFLOAT_VALUE(y), &i), DBL_MANT_DIG));
-
ey = i - DBL_MANT_DIG;
-
goto bignum;
- }
- }
Index: rational.c
— rational.c (revision 23694)
+++ rational.c (working copy)
@@ -769,7 +769,7 @@
static VALUE
nurat_fdiv(VALUE self, VALUE other)
{
- return f_div(f_to_f(self), other);
- return f_to_f(f_div(self, other));
}
static VALUE