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p$$$F=$@5$7$F$_$^$7$?!#e(B

Inf.fdiv(Float::MAX.to_i*2)
e$B$J$I$N>l9g$bBP=h$7$J$$$H$$$1$J$$$H;W$$$^$9$,!"$H$j$"$($:!#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: bignum.c

— bignum.c (revision 23694)
+++ bignum.c (working copy)
@@ -2382,6 +2382,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;
    +}

/*

  • call-seq:
  • big.fdiv(numeric) -> float
    

@@ -2394,65 +2441,32 @@
*
*/

-static VALUE
+
+VALUE
rb_big_fdiv(VALUE x, VALUE y)
{

  • double dx = big2dbl(x);
  • double dy;
  • double dx, 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;
    
  • }
  • }
  • dx = big2dbl(x);
    switch (TYPE(y)) {
    case T_FIXNUM:
    dy = (double)FIX2LONG(y);

  • if (isinf(dx))

  •  return big_fdiv(x, y);
    

    break;

     case T_BIGNUM:
    

    dy = rb_big2dbl(y);

  • if (isinf(dx) || isinf(dy))

  •  return big_fdiv(x, y);
    

    break;

     case T_FLOAT:
    

    dy = RFLOAT_VALUE(y);

  • if (isnan(dy))

  •  return y;
    
  • if (isinf(dx))

  •  return big_fdiv(x, y);
    

    break;

     default:
    

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

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:38636] Re: Fixnum#fdiv”
on Mon, 15 Jun 2009 21:09:56 +0900, Tadayoshi F.
[email protected] writes:

|fdiv e$B$G$Oe(B2e$B$D$N0[$k2r<a$,:.:_$7$F$$$k$h$&$K8+$($^$9!#e(B
|
|Fixnum e$B$G$O7W;;BP>]$rIbF0>.?tE@?t$K$7$F3d$k$@$1$G$G$9!#$@$+$i!“Bg$-$J?te(B
|e$B$r07$&$HNm$dL58BBg$,=P$F$/$k$3$H$,$”$j$^$9!#0lJ}!“e(BBignum e$B$G$O!“e(B2e$B$D$N<Be(B
|e$B?te(B (e$BK\Ev$OJ#AG?t$b$”$k$,e(B) e$B$NHf$r>l9g$K$h$C$F$OHsF;$/OD$s$G$bIbF0>.?tE@e(B
|e$B?t$H$7$FI=8=$9$k$3$H$rA@$C$F$$$k$h$&$K8+$($^$9!#e(B
|
|e$BA0<T$Oe(B Float(x)/Float(y)e$B!“8e<T$O$`$7$me(B Float(x/y) e$B$G$”$k$+$b$7$l$^$;$s!#e(B
|e$B8e<T$@$H$9$k$H!”$$$m$$$m8+D>$7$,I,MW$G!“e(BComplex e$B$Ke(B fdiv e$B$,$”$k$N$b$*$+e(B
|e$B$7$$!"$H$$$&$3$H$K$J$k$+$b$7$l$^$;$s!#e(B

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

[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$^$D$b$He(B e$B$f$-$R$me(B /:|)

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:38639] Re: Fixnum#fdiv”
on Mon, 15 Jun 2009 23:04:21 +0900, Tadayoshi F.
[email protected] writes:

|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(B
e$B$N$G$9$,!"$h$/8+$k$H$H$F$bCfESH>C<$J$s$G$9$M!#e(B

e$B$U$`!#!VCfESH>C<!W$H$$$&$N$Oe(Bfixnume$B$He(Bbignume$B$G?)$$0c$&$H8@$&0Ue(B
e$BL#$G$9$h$M!#0l4S@-$r;}$?$;$k$?$aE}0l$9$k$3$H$KH?BP$G$O$"$j$^e(B
e$B$;$s!#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

Float(x/y)e$B$NJ}$,>pJs$,Mn$A$F$$$J$$$N$OJ,$+$j$^$9!#e(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fdiv(Float::MAX.to_i
2) #=> 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;
    +}

/*

  • call-seq:
  • big.fdiv(numeric) -> float
    

@@ -2397,65 +2444,32 @@
*
*/

-static VALUE
+
+VALUE
rb_big_fdiv(VALUE x, VALUE y)
{

  • double dx = big2dbl(x);
  • double dy;
  • double dx, 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;
    
  • }
  • }
  • dx = big2dbl(x);
    switch (TYPE(y)) {
    case T_FIXNUM:
    dy = (double)FIX2LONG(y);

  • if (isinf(dx))

  •  return big_fdiv(x, y);
    

    break;

     case T_BIGNUM:
    

    dy = rb_big2dbl(y);

  • if (isinf(dx) || isinf(dy))

  •  return big_fdiv(x, y);
    

    break;

     case T_FLOAT:
    

    dy = RFLOAT_VALUE(y);

  • if (isnan(dy))

  •  return y;
    
  • if (isinf(dx))

  •  return big_fdiv(x, y);
    

    break;

     default:
    

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

e$B$U$`!#!VCfESH>C<!W$H$$$&$N$Oe(Bfixnume$B$He(Bbignume$B$G?)$$0c$&$H8@$&0Ue(B
e$BL#$G$9$h$M!#0l4S@-$r;}$?$;$k$?$aE}0l$9$k$3$H$KH?BP$G$O$"$j$^e(B
e$B$;$s!#e(B

e$B$$$E$l$K$7$F$b!"$3$N:]$O$C$-$j$5$;$F=$@5$9$k$3$H$K$J$k$G$7$g$&$M!#e(B

Float(x/y)e$B$NJ}$,>pJs$,Mn$A$F$$$J$$$N$OJ,$+$j$^$9!#e(B
e$B$=$l$,K>$^$7$$$N$+$I$&$+$O!";d$K$OH=CG$G$-$J$$$N$G$9$,!#e(B

e$BK>$^$7$$$H$$$&$3$H$K$J$l$P!"%3%_%C%H$7$F$$$?$@$/$N$K$d$V$5$+e(B
e$B$G$O$"$j$^$;$s!#e(B

e$B2?$,K>$^$7$$$+$OFq$7$$$G$9$+$i$M!#$H$3$m$G!"e(Bpython 3 e$B$Ne(B true
division
e$B$G$O!"7k2L$,IbF0>.?tE@?t$K$J$j$^$9$,!"e(B

import sys
1 / (int(sys.float_info.max)*2)
2.7813423231340017e-309

int(sys.float_info.max) / (int(sys.float_info.max)*2)
0.5

(int(sys.float_info.max)*2) / 2
1.7976931348623157e+308

ruby e$B$G$be(B / e$B$re(B quo e$B$7$h$&$H$$$&<gD%$,$"$j$^$9$,e(B
(e$BKM$G$9$,e(B)e$B!“e(BRational e$B$,e(B
e$B$J$$>l9g$Ne(B quo e$B$,e(B fdiv
e$B$N0UL#$G$”$k$3$H$r9M$($l$P!"@0?t$r4^$`G$0U$N?t$re(B
e$B$"$D$+$&Am>NE*$Je(B fdiv e$B$H$7$F$"$jF@$kA*Br$@$H;W$$$^$9!#e(B

e$B5U$K8=>u$G$O$3$N$h$&$J7k2L$rF@$k$3$H$O4JC1$H$O8@$($J$$$N$G!“B8:_$9$k2Ae(B
e$BCM$O$”$k$H;W$$$^$9!#e(B

e$B$U$`!#!VCfESH>C<!W$H$$$&$N$Oe(Bfixnume$B$He(Bbignume$B$G?)$$0c$&$H8@$&0Ue(B
e$BL#$G$9$h$M!#0l4S@-$r;}$?$;$k$?$aE}0l$9$k$3$H$KH?BP$G$O$"$j$^e(B
e$B$;$s!#e(B

e$B$$$E$l$K$7$F$b!"$3$N:]$O$C$-$j$5$;$F=$@5$9$k$3$H$K$J$k$G$7$g$&$M!#e(B

e$B7k2L$H$7$F$NK>$^$7$5!"$H$$$&$3$H$G$O!"e(B[ruby-dev:38640] e$B$Ne(B

Float(x/y)e$B$NJ}$,>pJs$,Mn$A$F$$$J$$$N$OJ,$+$j$^$9!#e(B

e$B$H$$$&$3$H$K$D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C$?$h$&$K8+$($^$9!#e(B

e$B$?$@!"$^$@e(B Complex#fdiv e$B$N0UL#$K$D$$$F$O5?Ld$,$"$j$^$9$M!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:38657] Re: Fixnum#fdiv”
on Tue, 16 Jun 2009 21:23:57 +0900, Tadayoshi F.
[email protected] writes:

|e$B7k2L$H$7$F$NK>$^$7$5!“$H$$$&$3$H$G$O!“e(B[ruby-dev:38640] e$B$Ne(B
|
|> Float(x/y)e$B$NJ}$,>pJs$,Mn$A$F$$$J$$$N$OJ,$+$j$^$9!#e(B
|
|e$B$H$$$&$3$H$K$D$-$k$h$&$K;W$$$^$9$,!“e(Bruby e$B$H$7$F!”$”$k$$$Oe(B fdiv e$B$H$7$F$Ne(B
|e$BJ}?K$,$h$/$o$+$i$J$$!”$H$$$&$3$H$G$7$g$&$+!#e(B

e$B;d$,5$$K$7$F$$$k$N$O!V5sF0$NM}2r$7$d$9$5!W$G$9$M!#e(B

Float(x)/Float(y)

e$B$O8=:_$Ne(BRubye$B$G$bDj5A$5$l$F$$$k?6Iq$$$G$“$j!”$I$N$h$&$JF0:n$re(B
e$B$9$k$+M}2r$9$k$N$O4JC1$G$9!#$^$?!"e(Bfloate$B$J$i$G$O$N8B3&$d8m:9e(B
e$B$be(B(e$BCN$C$F$$$l$Pe(B)e$BL@Gr$G$9!#$b$C$H$b!"e(B[ruby-core:11069]e$B$NLdBje(B
e$B$O2r7h$G$-$J$$$o$1$G$9$,!#0lJ}!"e(B

Float(x/y)

e$B$Oe(B(x/y)e$B$NItJ,$,!“$$$^$$$AITL@NF$G$9!#$$$d!”;d$,M}2r$7$F$J$$e(B
e$B$@$1$G$9$,!#$3$Ne(B(x/y)e$B$NItJ,$O!VM-M}?t$H$7$F>&$r5a$a$k!W$HM}e(B
e$B2r$9$l$P$h$$$N$G$7$g$&$+!#$D$^$j!"e(B

Float(Rational(x,y))

e$B$HF1$87k2L$rJV$9!“$H!#$=$&$$$&$3$H$G$”$l$P!“;d$K$H$C$F$9$C$-e(B
e$B$j$7$^$9$7!”%3%9%H$,<c435$$K$J$j$^$9$,!“$=$l0J30$KH?BP$9$k$he(B
e$B$&$JM}M3$O$I$3$K$b$”$j$^$;$s!#e(B

e$B<B:]$N$H$3$m$I$&$J$s$G$7$g$&!)e(B

|e$B8=>u$G$Oe(B fdiv e$B$be(B Complex e$B$K$J$k$3$H$b$“$j!“e(Brdiv e$B$HF1MM$K9M$($l$P$3$l$be(B
|e$B$*$+$7$$!”$H$$$&2DG=@-$,$”$k$H;W$$$^$9!#e(B

fdive$B$,e(Bcomplexe$B$rJV$9>l9g!“e(Bfe$B$O<BIt$H5uIt$,e(Bfloate$B$G$”$k$3$H$r<($9!"e(B
e$B$H;d$OM}2r$7$F$$$^$9!#e(B

                            e$B$^$D$b$He(B e$B$f$-$R$me(B /:|)

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:38660] Re: Fixnum#fdiv”
on Tue, 16 Jun 2009 23:52:39 +0900, Tadayoshi F.
[email protected] writes:

|> Float(Rational(x,y))
|>
|> e$B$HF1$87k2L$rJV$9!“$H!#$=$&$$$&$3$H$G$”$l$P!“;d$K$H$C$F$9$C$-e(B
|> e$B$j$7$^$9$7!”%3%9%H$,<c435$$K$J$j$^$9$,!“$=$l0J30$KH?BP$9$k$he(B
|> e$B$&$JM}M3$O$I$3$K$b$”$j$^$;$s!#e(B

|e$B$=$&9M$($F$$$$$H;W$$$^$9!#$,!"<B:]$KM-M}?t$K$9$k$3$H$O$J$$$H;W$$$^$9!#e(B

e$B$=$l$J$iG<F@$G$9!#;d$N7|G0$O!"MW$9$k$K5sF0$,@bL@$G$-$k$+$I$&e(B
e$B$+$@$1$G$9$+$i!#e(B

|> fdive$B$,e(Bcomplexe$B$rJV$9>l9g!“e(Bfe$B$O<BIt$H5uIt$,e(Bfloate$B$G$”$k$3$H$r<($9!“e(B
|> e$B$H;d$OM}2r$7$F$$$^$9!#e(B
|
|e$B7W;;BP>]$rIbF0>.?tE@?t$K$9$k$N$+!“7W;;7k2L$rIbF0>.?tE@?t$K$9$k$N$+!”$3e(B
|e$B$3$O=EMW$J46$8$,$9$k$s$G$9$,!”$=$&$@$H$9$k$H!“e(BFloat(x)/Float(y) e$B$K6a$$e(B
|e$B46$8$,$7$^$9!#e(B
|
|e$B$d$O$j!”$^$D$b$H$5$s$H$7$F$O!“e(BFloat(x)/Float(y) e$B$G$”$k$Y$-$H$$$&9M$($Ke(B
|e$B79$`$$$F$k46$8$G$9$M!#e(B

e$B$$$d$“!“e(B[ruby-core:11069]e$B$N$h$&$JLdBj$,$”$k0J>e!“e(B
Float(x)/Float(y) e$B$NJ}$,M%$l$F$$$k$H$O9M$($F$$$^$;$s!#$`$7$me(B
e$B!V$”$k$Y$-$G$J$$!W$s$8$c$J$$$+$J!#$b$C$H$b!”;d<+?H$O>-Mh$K$oe(B
e$B$?$C$F$3$NE@$G$R$C$+$+$i$k$h$&$J;H$$J}$O$7$J$$$@$m$&$H;W$$$^e(B
e$B$9$+$i!";d$N9M$($O$3$N:]=EMW$G$O$J$$$h$&$J5$$,$7$^$9!#e(B

e$B7+$jJV$7$K$J$j$^$9$,!"!V$h$j@53N$J=|;;!W$H$+$@$HFHN)$7$?<BAue(B
e$B$r:n$C$?>l9g8!>Z$G$-$^$;$s$,!“e(BFloat(Rational(x,y))
e$B$He(B(e$B7W;;2ae(B
e$BDx$OJL$H$7$Fe(B)e$BF1$87k2L$rJV$9!”$J$i8!>Z2DG=$G$9!#;d$,5a$a$F$$e(B
e$B$k$N$O$=$l$@$1$G$9!#e(B

e$B$G!“$U$J$P$5$s$,>e$G!V$=$&9M$($F$$$$!W$H$*$C$7$c$C$?$N$G!”;de(B
e$B$K$OH?BP$9$kM}M3$O$J$/$J$j$^$7$?!#%Q%C%A$r%3%_%C%H$7$F$/$@$5$Ce(B
e$B$F9=$$$^$;$s!#e(B

                            e$B$^$D$b$He(B e$B$f$-$R$me(B /:|)

e$B7+$jJV$7$K$J$j$^$9$,!"!V$h$j@53N$J=|;;!W$H$+$@$HFHN)$7$?<BAue(B
e$B$r:n$C$?>l9g8!>Z$G$-$^$;$s$,!“e(BFloat(Rational(x,y)) e$B$He(B(e$B7W;;2ae(B
e$BDx$OJL$H$7$Fe(B)e$BF1$87k2L$rJV$9!”$J$i8!>Z2DG=$G$9!#;d$,5a$a$F$$e(B

e$B8m2r$N$J$$$h$&$K3NG’$7$^$9$,!"$"$/$^$G35G0E*$JOC$G$9!#e(B
Rational(Inf,Inf) e$B$H$+IT2DG=$G$9$+$i!#e(B

xe$B!"e(By
e$B$,@0?t$N>l9g$OF1MM$K$J$k$H;W$$$^$9!#$I$&$7$F$+$H$$$&$H!"e(B
Rational#to_f e$B$O!"e(Bnumerator.fdiv.denominator
e$B$K$J$k$+$i$G$9!#e(B

e$B$b$H$b$H!“e(BRational#to_f
e$B$O86$5$s$,=q$$$F$/$l$?$b$N$r$[$H$s$I$=$N$^$^$De(B
e$B$+$C$F$$$F!“FHN)$7$Fe(B fdiv
e$B$,$d$C$F$$$k$h$&$J$3$H$r$7$F$$$?$N$G$9$,!”$&e(B
e$B$^$/5!G=$7$J$$>l9g$rH/8+$7$F!”$=$l$Ge(B fdiv
e$B$G$$$$$8$c$J$$$+!"$H$$$&$H$3e(B
e$B$m$+$i;O$^$C$F$$$?$N$G$9!#e(B

Complex#fdiv e$B$O$3$N$^$^$J$s$G$9$+$M!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:38662] Re: Fixnum#fdiv”
on Wed, 17 Jun 2009 00:37:29 +0900, Tadayoshi F.
[email protected] writes:

|e$B8m2r$N$J$$$h$&$K3NG’$7$^$9$,!“$”$/$^$G35G0E*$JOC$G$9!#e(B
|Rational(Inf,Inf) e$B$H$+IT2DG=$G$9$+$i!#e(B

e$BM}2r$7$F$^$9!#e(B

|Complex#fdiv e$B$O$3$N$^$^$J$s$G$9$+$M!#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$N$J$$e(B Scheme e$B=hM}7O$G$Oe(B /
e$B$G$=$&$$$&G[N8$r$9$k$b$N$,$”$k$he(B
e$B$&$G$9$7!“e(Bpython e$B$N>l9g$bM-M}?t$r%5%]!<%H$7$?$ie(B true
division e$B$OM-M}?te(B
e$B$rJV$9$h$&$K$J$k$H$$$&$3$G$9$,!”:#$O$=$&$G$O$J$$$G$9!#e(B

|e$B8=>u$G$Oe(B fdiv e$B$be(B Complex e$B$K$J$k$3$H$b$"$j!“e(Brdiv e$B$HF1MM$K9M$($l$P$3$l$be(B
|e$B$*$+$7$$!”$H$$$&2DG=@-$,$"$k$H;W$$$^$9!#e(B

fdive$B$,e(Bcomplexe$B$rJV$9>l9g!“e(Bfe$B$O<BIt$H5uIt$,e(Bfloate$B$G$”$k$3$H$r<($9!"e(B
e$B$H;d$OM}2r$7$F$$$^$9!#e(B

e$B7W;;BP>]$rIbF0>.?tE@?t$K$9$k$N$+!“7W;;7k2L$rIbF0>.?tE@?t$K$9$k$N$+!”$3e(B
e$B$3$O=EMW$J46$8$,$9$k$s$G$9$,!"$=$&$@$H$9$k$H!"e(BFloat(x)/Float(y)
e$B$K6a$$e(B
e$B46$8$,$7$^$9!#e(B

e$B$d$O$j!"$^$D$b$H$5$s$H$7$F$O!“e(BFloat(x)/Float(y)
e$B$G$”$k$Y$-$H$$$&9M$($Ke(B
e$B79$`$$$F$k46$8$G$9$M!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:38664] Re: Fixnum#fdiv”
on Wed, 17 Jun 2009 01:21:42 +0900, Tadayoshi F.
[email protected] writes:

|> [ruby-core:23869]e$B$Ne(BRationale$B%I%-%e%a%s%H%Q%C%A$K$D$$$F$I$&;We(B
|> e$B$o$l$^$9$+!)e(B
|
|e$BLdBj$,$J$5$=$&$J$iKM$,<h$j$3$a$P$$$$$G$9$h$M!#8+$F$*$-$^$9!#e(B

e$B$*4j$$$7$^$9!#e(B

e$B$3$N7o$r=$@5$7$h$&$H$7$F$$$^$9$,!"e(B

Inf.fdiv(Float::MAX.to_i*2)

e$B$N$h$&$J>l9g$r$I$&$9$k$+G:$s$G$$$^$9!#e(B

e$B$3$l$^$G$Ne(B ruby e$B$G$Oe(B NaN
e$B$K$J$k$H;W$$$^$9!#$G$b!“e(BBignum e$B$OL58BBg$h$j>.e(B
e$B$5$$$N$OL@$+$G$9!#$3$l$NBP=h$,$”$^$j$-$l$$$K=q$1$=$&$K$"$j$^$;$s!#e(B

e$B$7$+$b;w$?$h$&$JLdBj$,e(B fdiv e$B0J30$K$b$"$j$^$9!#e(B

Inf <=> (Float::MAX.to_i*2)

e$B$H$$$C$?Hf3S$G$9!#e(B

e$B$3$l$OJL$K9M$($?$[$&$,$h$5$=$&$J$N$G!":#2s$N7o$H$O@ZN%$7$F$7$^$*$&$+$He(B
e$B;W$$$^$9!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:38669] Re: Fixnum#fdiv”
on Wed, 17 Jun 2009 20:11:20 +0900, Tadayoshi F.
[email protected] writes:

|Inf.fdiv(Float::MAX.to_i*2)
|
|e$B$N$h$&$J>l9g$r$I$&$9$k$+G:$s$G$$$^$9!#e(B
|
|e$B$3$l$^$G$Ne(B ruby e$B$G$Oe(B NaN e$B$K$J$k$H;W$$$^$9!#$G$b!“e(BBignum e$B$OL58BBg$h$j>.e(B
|e$B$5$$$N$OL@$+$G$9!#$3$l$NBP=h$,$”$^$j$-$l$$$K=q$1$=$&$K$"$j$^$;$s!#e(B

Bignume$B$Oe(BFloat::MAXe$B$h$jBg$-$$?t$,I=8=$G$-$A$c$$$^$9$+$i$M$(!#e(B

e$B$=$l$G$b!"L58B$rM-8B$G3d$C$?$iL58B$K$J$k$N$G$O$J$$$G$9$+!#e(B
e$B!Ve(BFloat(x/y)e$B!W$H$$$&Dj5A$r:NMQ$7$?$H$$$&$3$H$O$=$&$$$&$3$H$Je(B
e$B$s$@$H;W$$$^$7$?!#e(B

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