Float#div and Float#divmod [AGAIN]


#1

e$B86$G$9!#e(B

e$B4{$K2?EY$+OCBj$K$J$C$F$$$F7+$jJV$7$_$?$$$G$9$,!"e(B
e$B0J2<$Oe(B 1.8.4 e$B$G$NDs0F$G$9!#e(B

e$B8=:_!Je(B1.8.4 snapshote$B!K$G!"e(B

-3.4.div(1.1) #=> -3

e$B$H$J$C$F$$$^$9$,!"$3$l$Oe(B -4 e$B$H$9$Y$-$@$H;W$$$^$9!#e(B
e$BM}M3$Oe(B
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/27674[ruby-dev:27674]
e$B$KB3$/?70f$5$s$N0U8+$d!“e(B
[ruby-dev:28509] e$B$KB3$/$U$J$P$5$s$N%K%e%”%s%9!J!)!Ke(B
e$B$NDL$j$G$9!#e(B1.9.0 e$B$G$b$=$&$J$C$F$$$k$7!"m4m0$9$kI,e(B
e$BMW$O$J$$$H;W$$$^$9!#e(B

e$B<!$K!"8=:_!Je(B1.8.4 snapshote$B!K$G!"e(B

-3.4.divmod(1.1) #=> [-4.0, 1.0]

e$B$H$J$C$F$$$^$9$,!"$3$l$Oe(B [-4, 1.0] e$B$H$9$Y$-$G$9!#e(B
e$BM}M3$O!"$3$NG[Ns$Oe(B div e$B$He(B % e$B$N7k2L$G$"$k$Y$-$@$+$ie(B
e$B$G$9!#e(B

e$B$I$A$i$b%P%007$$$Ge(B 1.8.4 e$B$GD>$7$F$b$$$$$H;W$$$^$9!#e(B

e$B$I$&$G$7$g$&!#e(B

e$B0JA0e(B aFloat.div(aFloat) e$B$J$s$FLGB?$K;H$o$J$$$N$G!“E,e(B
e$BEv$G$$$$$_$?$$$J;v$r8@$C$?3P$($,$”$j$^$9$,!"$I$&$be(B
rationalize e$B$r<BAu$7$F$$$k$&$A$K$-$A$s$H$7$F$*$$$?J}e(B
e$B$,$h$&$5$=$&$@$H$$$&5$$,$7$F$-$?$N$G$9!#e(B

e$B0x$_$K!":#:n$C$F$$$k3HD%%i%$%V%i%j$G$b!"e(B
aRational.div(aRational) e$B$N7k2L$Oe(B Rational e$B$G$O$J$/e(B
Integer e$B$K$7$F$$$^$9!#$b$A$m$se(B divmod e$B$b$=$l$HO"F0$7e(B
e$B$F$$$^$9!#e(B


#2

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

In message “Re: [ruby-dev:28589] Float#div and Float#divmod [AGAIN]”
on Mon, 24 Apr 2006 00:25:21 +0900, Shin-ichiro HARA
removed_email_address@domain.invalid writes:

|e$B4{$K2?EY$+OCBj$K$J$C$F$$$F7+$jJV$7$$?$$$G$9$,!"e(B
|e$B0J2<$Oe(B 1.8.4 e$B$G$NDs0F$G$9!#e(B
|
|e$B8=:
!Je(B1.8.4 snapshote$B!K$G!“e(B
|
| -3.4.div(1.1) #=> -3
|
|e$B$H$J$C$F$$$^$9$,!”$3$l$Oe(B -4 e$B$H$9$Y$-$@$H;W$$$^$9!#e(B
|e$BM}M3$Oe(B http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/27674[ruby-dev:27674] e$B$KB3$/?70f$5$s$N0U8+$d!“e(B
|[ruby-dev:28509] e$B$KB3$/$U$J$P$5$s$N%K%e%”%s%9!J!)!Ke(B
|e$B$NDL$j$G$9!#e(B1.9.0 e$B$G$b$=$&$J$C$F$$$k$7!"m4m0$9$kI,e(B
|e$BMW$O$J$$$H;W$$$^$9!#e(B

e$B$^$"!"$$$$$s$8$c$J$$$G$7$g$&$+!#e(B

|e$B<!$K!“8=:_!Je(B1.8.4 snapshote$B!K$G!“e(B
|
| -3.4.divmod(1.1) #=> [-4.0, 1.0]
|
|e$B$H$J$C$F$$$^$9$,!”$3$l$Oe(B [-4, 1.0] e$B$H$9$Y$-$G$9!#e(B
|e$BM}M3$O!”$3$NG[Ns$Oe(B div e$B$He(B % e$B$N7k2L$G$"$k$Y$-$@$+$ie(B
|e$B$G$9!#e(B

e$B$3$A$i$b$$$$$s$8$c$J$$$G$7$g$&$+!#e(B

|e$B$I$A$i$b%P%007$$$Ge(B 1.8.4 e$B$GD>$7$F$b$$$$$H;W$$$^$9!#e(B

e$B$H$$$&$o$1$G!“86$5$s$,%3%_%C%H$7$F2<$5$k$H$&$l$7$$$J$”!#e(B


#3

e$B$H$$$&$o$1$G!“86$5$s$,%3%_%C%H$7$F2<$5$k$H$&$l$7$$$J$”!#e(B

e$B$I$I$I!"$I!<$d$C$?$i$$$$$s$G$7$g$&!#e(B
CVS e$B$N;H$$J}$J$i>/$7$O$o$+$k$N$G$9$,!De(B
anonymous e$B$G<h$C$F$-$F!"$=$l$+$i$I$&$9$k$N!#e(B


#4

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

In message “Re: [ruby-dev:28591] Re: Float#div and Float#divmod [AGAIN]”
on Mon, 24 Apr 2006 00:34:09 +0900, Shin-ichiro HARA
removed_email_address@domain.invalid writes:

|>e$B$H$$$&$o$1$G!“86$5$s$,%3%_%C%H$7$F2<$5$k$H$&$l$7$$$J$”!#e(B
|
|e$B$I$I$I!"$I!<$d$C$?$i$$$$$s$G$7$g$&!#e(B
|CVS e$B$N;H$$J}$J$i>/$7$O$o$+$k$N$G$9$,!De(B
|anonymous e$B$G<h$C$F$-$F!"$=$l$+$i$I$&$9$k$N!#e(B

e$B$"$i!)e(B e$B$^$@%3%_%C%H8"$r$5$7$"$2$F$^$;$s$G$7$?$C$1!#e(B

e$B$^$:!"e(Bssh2e$B$N8x3+80$rMQ0U$7$Fe(removed_email_address@domain.invalide$B$^$G%a!<e(B
e$B%k$7$F2<$5$$!#$G$b!"A0ED$/$s$,K;$7$=$&$@$+$i$9$0$K$O$9$9$^$Je(B
e$B$$$+$J!#e(B

e$B$H$j$"$($:e(B1.8.4e$BMQ$N%Q%C%A$r:n$C$F$3$3$KEj$2$F2<$5$k$@$1$G9=e(B
e$B$$$^$;$s!#8e$O;d$G$d$j$^$9!#e(B


#5

e$B86$G$9!#e(B

e$B$^$:!"e(Bssh2e$B$N8x3+80$rMQ0U$7$Fe(removed_email_address@domain.invalide$B$^$G%a!<e(B
e$B%k$7$F2<$5$$!#$G$b!"A0ED$/$s$,K;$7$=$&$@$+$i$9$0$K$O$9$9$^$Je(B
e$B$$$+$J!#e(B

e$B$"!"$=$&$$$&CJ<h$j$G$7$?$+!#e(B

e$B$H$j$"$($:e(B1.8.4e$BMQ$N%Q%C%A$r:n$C$F$3$3$KEj$2$F2<$5$k$@$1$G9=e(B
e$B$$$^$;$s!#8e$O;d$G$d$j$^$9!#e(B

e$B0lEY$d$C$F$$?$+$C$?$N$G!"%3%%C%H$5$;$F$/$@$5$$!#e(B
e$BO"5Y$KF~$C$F$+$i!J$J$<$K$=$s$J$K@h!)!K$7$^$9!#e(B


#6

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

In message “Re: [ruby-dev:28593] Re: Float#div and Float#divmod [AGAIN]”
on Mon, 24 Apr 2006 00:50:28 +0900, Shin-ichiro HARA
removed_email_address@domain.invalid writes:

|>e$B$^$:!“e(Bssh2e$B$N8x3+80$rMQ0U$7$Fe(removed_email_address@domain.invalide$B$^$G%a!<e(B
|>e$B%k$7$F2<$5$$!#$G$b!“A0ED$/$s$,K;$7$=$&$@$+$i$9$0$K$O$9$9$^$Je(B
|>e$B$$$+$J!#e(B
|
|e$B$”!”$=$&$$$&CJ<h$j$G$7$?$+!#e(B

e$B$O$$!"$h$j@53N$K$O3+H/MQ%j%]%8%H%j$Ke(Bsshe$B$G%"%/%;%9$7$^$9!#Iae(B
e$BDL$N?M$,F?L>%"%/%;%9$7$F$$$k%j%]%8%H%j$O%3%T!<$G$9!#3+H/<T$Ke(B
e$B$Oe(Bsshe$B%"%+%&%s%H$rH/9T$7$^$9!#$=$N$?$a$Ke(Bssh2e$B$N8x3+80$,I,MW$Ke(B
e$B$J$k$H$$$&$o$1$G$9!#e(B

|>e$B$H$j$"$($:e(B1.8.4e$BMQ$N%Q%C%A$r:n$C$F$3$3$KEj$2$F2<$5$k$@$1$G9=e(B
|>e$B$$$^$;$s!#8e$O;d$G$d$j$^$9!#e(B
|
|e$B0lEY$d$C$F$$?$+$C$?$N$G!"%3%%C%H$5$;$F$/$@$5$$!#e(B
|e$BO"5Y$KF~$C$F$+$i!J$J$<$K$=$s$J$K@h!)!K$7$^$9!#e(B

e$B$=$l$^$G$K%"%+%&%s%H$,$G$-$l$P$h$$$N$G$9$,!#e(B


#7

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

In message “Re: [ruby-dev:28595] Re: Float#div and Float#divmod [AGAIN]”
on Mon, 24 Apr 2006 01:11:31 +0900, Shin-ichiro HARA
removed_email_address@domain.invalid writes:

|e$B$=$l$G!“3+H/<T$O?7$7$$%V%i%s%A$r:n$k$N$G$9$+!)$G!”$=$l$re(B
|e$B8+$F#O#K$J$i$^$D$b$H$5$s$,%a%$%s$N%V%i%s%A$K<h$j9~$`!"$He(B
|e$B$$$&46$8$J$N$+$J!#e(B

e$B$$$(!"$?$$$F$$$O$3$3e(B(ruby-dev)e$B$K%Q%C%A$rEj$2$F!";d$,!V$I$&$>!We(B
e$B$H8@$C$?$i3+H/<T$,<B:]$K%3%_%C%H$9$k$H$$$&N.$l$,B?$$$G$9!#e(B
Rubye$B$N3+H/$G$O%V%i%s%A$O$[$H$s$I;H$o$l$F$$$^$;$s$M!#e(B

|>e$B$=$l$^$G$K%"%+%&%s%H$,$G$-$l$P$h$$$N$G$9$,!#e(B
|
|e$B4V$K9g$o$J$1$l$P%Q%C%A$rAw$j$^$9!#e(B

e$B$h$m$7$/!#e(B


#8

e$B86$G$9!#e(B

|e$B$=$l$G!“3+H/<T$O?7$7$$%V%i%s%A$r:n$k$N$G$9$+!)$G!”$=$l$re(B
|e$B8+$F#O#K$J$i$^$D$b$H$5$s$,%a%$%s$N%V%i%s%A$K<h$j9~$`!"$He(B
|e$B$$$&46$8$J$N$+$J!#e(B

e$B$$$(!"$?$$$F$$$O$3$3e(B(ruby-dev)e$B$K%Q%C%A$rEj$2$F!";d$,!V$I$&$>!We(B
e$B$H8@$C$?$i3+H/<T$,<B:]$K%3%_%C%H$9$k$H$$$&N.$l$,B?$$$G$9!#e(B
Rubye$B$N3+H/$G$O%V%i%s%A$O$[$H$s$I;H$o$l$F$$$^$;$s$M!#e(B

e$B$=$&$@$C$?$N$+$"!##1#0G/$bD/$a$F$$$F5$$E$+$J$+$C$?!"!"!"e(B


#9

e$B86$G$9!#e(B

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

|>e$B$^$:!“e(Bssh2e$B$N8x3+80$rMQ0U$7$Fe(removed_email_address@domain.invalide$B$^$G%a!<e(B
|>e$B%k$7$F2<$5$$!#$G$b!“A0ED$/$s$,K;$7$=$&$@$+$i$9$0$K$O$9$9$^$Je(B
|>e$B$$$+$J!#e(B
|
|e$B$”!”$=$&$$$&CJ<h$j$G$7$?$+!#e(B

e$B$O$$!"$h$j@53N$K$O3+H/MQ%j%]%8%H%j$Ke(Bsshe$B$G%"%/%;%9$7$^$9!#Iae(B
e$BDL$N?M$,F?L>%"%/%;%9$7$F$$$k%j%]%8%H%j$O%3%T!<$G$9!#3+H/<T$Ke(B
e$B$Oe(Bsshe$B%"%+%&%s%H$rH/9T$7$^$9!#$=$N$?$a$Ke(Bssh2e$B$N8x3+80$,I,MW$Ke(B
e$B$J$k$H$$$&$o$1$G$9!#e(B

e$B$=$l$G!“3+H/<T$O?7$7$$%V%i%s%A$r:n$k$N$G$9$+!)$G!”$=$l$re(B
e$B8+$F#O#K$J$i$^$D$b$H$5$s$,%a%$%s$N%V%i%s%A$K<h$j9~$`!"$He(B
e$B$$$&46$8$J$N$+$J!#e(B

|e$B0lEY$d$C$F$$?$+$C$?$N$G!"%3%%C%H$5$;$F$/$@$5$$!#e(B
|e$BO"5Y$KF~$C$F$+$i!J$J$<$K$=$s$J$K@h!)!K$7$^$9!#e(B

e$B$=$l$^$G$K%"%+%&%s%H$,$G$-$l$P$h$$$N$G$9$,!#e(B

e$B4V$K9g$o$J$1$l$P%Q%C%A$rAw$j$^$9!#e(B


#10

e$B86$G$9!#e(B

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

|e$B$I$A$i$b%P%007$$$Ge(B 1.8.4 e$B$GD>$7$F$b$$$$$H;W$$$^$9!#e(B

e$B$H$$$&$o$1$G!“86$5$s$,%3%_%C%H$7$F2<$5$k$H$&$l$7$$$J$”!#e(B

e$B%3%_%C%H8"$N7o$O8e$K$7$F!"%Q%C%A$rN.$7$^$9!#$[$H$s$I%I%-%ee(B
e$B%a%s%H$N:9J,$G$9$,!#e(B

e$B$H$3$m$G!“8=:_$Ne(B 1.8.4 e$B0BDjHG%9%J%C%W%7%g%C%H$O!”$=$N$^$^e(B
e$B$Ge(B make test e$B$G%(%i!<$,#3$D=P$^$9!#860x$Oe(B util.c e$B$Ne(B
strtod
e$B$N%P%0$@$H;W$$$^$9!#e(B1.9.0 e$B$Ne(B util.c e$B$Ne(B strtod
e$B$K$4$C$=$jCVe(B
e$B$-49$($k$HD>$j$^$9!#e(B

e$B99$K!"e(Btest/ruby/test_float.rb e$B$K<!$N%3!<%I$rB-$9$H$$$$$+$b!'e(B

def test_divmod
assert_equal([2, 3.5], 11.5.divmod(4))
assert_equal([-3, -0.5], 11.5.divmod(-4))
assert_equal([-3, 0.5], (-11.5).divmod(4))
assert_equal([2, -3.5], (-11.5).divmod(-4))
end

def test_div
assert_equal(2, 11.5.div(4))
assert_equal(-3, 11.5.div(-4))
assert_equal(-3, (-11.5).div(4))
assert_equal(2, (-11.5).div(-4))
end

def test_modulo
assert_equal(3.5, 11.5.modulo(4))
assert_equal(-0.5, 11.5.modulo(-4))
assert_equal(0.5, (-11.5).modulo(4))
assert_equal(-3.5, (-11.5).modulo(-4))
end

def test_remainder
assert_equal(3.5, 11.5.remainder(4))
assert_equal(3.5, 11.5.remainder(-4))
assert_equal(-3.5, (-11.5).remainder(4))
assert_equal(-3.5, (-11.5).remainder(-4))
end

e$B0J2<%Q%C%A$G$9!#e(B

— numeric.c.orig 2006-02-05 21:09:31.000000000 +0900
+++ numeric.c 2006-04-30 22:00:43.265625000 +0900
@@ -256,6 +256,8 @@
}

+static VALUE num_floor(VALUE num);
+
/*

  • call-seq:
  • num.div(numeric)    => integer
    

@@ -269,7 +271,7 @@
num_div(x, y)
VALUE x, y;
{

  • return rb_Integer(rb_funcall(x, ‘/’, 1, y));
  • return num_floor(rb_funcall(x, ‘/’, 1, y));
    }

@@ -297,21 +299,21 @@
*
------±----±--------------±--------±------------±--------------

  • -13 | -4 | 3, -1 | 3 | -1 | -1

------±----±--------------±--------±------------±--------------

    • 11.5 |  4  |   2.0,  3.5   |   2.875 |    3.5      |     3.5
      
    • 11.5 |  4  |   2,    3.5   |   2.875 |    3.5      |     3.5
      

------±----±--------------±--------±------------±--------------

    • 11.5 | -4  |  -3.0, -0.5   |  -2.875 |   -0.5      |     3.5
      
    • 11.5 | -4  |  -3,   -0.5   |  -2.875 |   -0.5      |     3.5
      

------±----±--------------±--------±------------±--------------

    • -11.5 | 4 | -3.0 0.5 | -2.875 | 0.5 | -3.5
    • -11.5 | 4 | -3, 0.5 | -2.875 | 0.5 | -3.5

------±----±--------------±--------±------------±--------------

    • -11.5 | -4 | 2.0 -3.5 | 2.875 | -3.5 | -3.5
    • -11.5 | -4 | 2 -3.5 | 2.875 | -3.5 | -3.5
    • Examples
    • 11.divmod(3)         #=> [3, 2]
      
    • 11.divmod(-3)        #=> [-4, -1]
      
    • 11.divmod(3.5)       #=> [3.0, 0.5]
      
    • (-11).divmod(3.5)    #=> [-4.0, 3.0]
      
    • (11.5).divmod(3.5)   #=> [3.0, 1.0]
      
    • 11.divmod(3.5)       #=> [3, 0.5]
      
    • (-11).divmod(3.5)    #=> [-4, 3.0]
      
    • (11.5).divmod(3.5)   #=> [3, 1.0]
      
    */

static VALUE
@@ -715,7 +717,7 @@
flo_divmod(x, y)
VALUE x, y;
{

  • double fy, div, mod;
  • double fy, div, mod, val;
    volatile VALUE a, b;

    switch (TYPE(y)) {
    @@ -732,7 +734,13 @@
    return rb_num_coerce_bin(x, y);
    }
    flodivmod(RFLOAT(x)->value, fy, &div, &mod);

  • a = rb_float_new(div);
  • if (FIXABLE(div)) {
  •    val = div;
    
  •    a = LONG2FIX(val);
    
  • }
  • else {
  •    a = rb_dbl2big(div);
    
  • }
    b = rb_float_new(mod);
    return rb_assoc_new(a, b);
    }

#11

e$B86$G$9!#e(B

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

In message “Re: [ruby-dev:28609] Re: Float#div and Float#divmod [AGAIN]”
on Sun, 30 Apr 2006 22:22:20 +0900, Shin-ichiro HARA removed_email_address@domain.invalid writes:

|e$B%3%_%C%H8"$N7o$O8e$K$7$F!"%Q%C%A$rN.$7$^$9!#$[$H$s$I%I%-%ee(B
|e$B%a%s%H$N:9J,$G$9$,!#e(B

e$B<h$j9~$_$^$9!#e(BChangeLoge$B%(%s%H%j$bMQ0U$7$F$$$?$@$1$^$;$s$+!)e(B

e$B$G$O$3$s$J46$8$G!#e(B

Mon May 1 12:23:19 2006 removed_email_address@domain.invalid

    * numeric.c (num_div): use floor rather than rb_Integer().
      [ruby-dev:28589]

    * numeric.c (flo_divmod): the first element of Float#divmod 

should
be an integer. [ruby-dev:28589]

    * test/ruby/test_float.rb: add tests for divmod, div, modulo and 

remainder.

|e$B99$K!"e(Btest/ruby/test_float.rb e$B$K<!$N%3!<%I$rB-$9$H$$$$$+$b!'e(B

e$B$3$l$bDI2C$7$^$7$g$&$+!#e(B

divmod e$B4X78$N<BAu$O$b$&>/$7@0M}$9$kM>CO$,$"$k$h$&$K;W$&$N$G!JC1e(B
e$B$K;d$,M}2r$G$-$F$J$$$@$1$+$b$7$l$J$$$1$I!K:#8e$N$3$H$r9M$($k$He(B
e$BDI2C$r$*4j$$$7$?$$$G$9!#e(B


#12

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

In message “Re: [ruby-dev:28609] Re: Float#div and Float#divmod [AGAIN]”
on Sun, 30 Apr 2006 22:22:20 +0900, Shin-ichiro HARA
removed_email_address@domain.invalid writes:

|e$B%3%_%C%H8"$N7o$O8e$K$7$F!"%Q%C%A$rN.$7$^$9!#$[$H$s$I%I%-%ee(B
|e$B%a%s%H$N:9J,$G$9$,!#e(B

e$B<h$j9~$_$^$9!#e(BChangeLoge$B%(%s%H%j$bMQ0U$7$F$$$?$@$1$^$;$s$+!)e(B

|e$B$H$3$m$G!“8=:_$Ne(B 1.8.4 e$B0BDjHG%9%J%C%W%7%g%C%H$O!”$=$N$^$^e(B
|e$B$Ge(B make test e$B$G%(%i!<$,#3$D=P$^$9!#860x$Oe(B util.c e$B$Ne(B strtod
|e$B$N%P%0$@$H;W$$$^$9!#e(B1.9.0 e$B$Ne(B util.c e$B$Ne(B strtod e$B$K$4$C$=$jCVe(B
|e$B$-49$($k$HD>$j$^$9!#e(B

e$B<j85$G$OD>$7$F$$$^$7$?!#e(B

|e$B99$K!"e(Btest/ruby/test_float.rb e$B$K<!$N%3!<%I$rB-$9$H$$$$$+$b!'e(B

e$B$3$l$bDI2C$7$^$7$g$&$+!#e(B


#13

e$B$U$J$P$G$9!#e(B

e$B<!$K!"8=:_!Je(B1.8.4 snapshote$B!K$G!"e(B

-3.4.divmod(1.1) #=> [-4.0, 1.0]
e$B$H$J$C$F$$$^$9$,!"$3$l$Oe(B [-4, 1.0] e$B$H$9$Y$-$G$9!#e(B
e$BM}M3$O!"$3$NG[Ns$Oe(B div e$B$He(B % e$B$N7k2L$G$"$k$Y$-$@$+$ie(B
e$B$G$9!#e(B

e$B$_$?$H$3$me(B 1.9 e$B$G$O!"e(B[-4.0, 1.0] e$B$K$J$j$^$9$M!#e(B1.8
e$B$G$=$&$9$Y$-$J$i!"e(B
1.9 e$B$G$b$=$&$G$J$$$H$*$+$7$$$h$&$K;W$&$N$G$9$,!#e(B


#14

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

In message “Re: [ruby-dev:28612] Re: Float#div and Float#divmod [AGAIN]”
on Mon, 1 May 2006 12:39:21 +0900, Shin-ichiro HARA
removed_email_address@domain.invalid writes:

|>e$B<h$j9~$_$^$9!#e(BChangeLoge$B%(%s%H%j$bMQ0U$7$F$$$?$@$1$^$;$s$+!)e(B
|
|e$B$G$O$3$s$J46$8$G!#e(B

e$B%3%_%C%H$7$^$7$?!#e(B


#15

e$B86$G$9!#e(B

1.9 e$B$G$b$=$&$G$J$$$H$*$+$7$$$h$&$K;W$&$N$G$9$,!#e(B
e$B$=$NDL$j$G$9$M!#e(B

e$BKX$IA0$HF1$8$G$9$,!“0l1~%Q%C%A$N7A$K$7$F$*$-$^$9!#e(B
e$B$^$D$b$H$5$s!”$h$m$7$/$*4j$$$7$^$9!#e(B

Tue May 16 17:23:19 2006 removed_email_address@domain.invalid

    * numeric.c (flo_divmod): the first element of Float#divmod 

should
be an integer. [ruby-dev:28589]

    * test/ruby/test_float.rb: add tests for divmod, div, modulo and 

remainder.

— numeric.c.orig 2006-05-16 17:31:44.071989816 +0900
+++ numeric.c 2006-05-16 17:37:20.466850024 +0900
@@ -284,21 +284,21 @@
*
------±----±--------------±--------±------------±--------------

  • -13 | -4 | 3, -1 | 3 | -1 | -1

------±----±--------------±--------±------------±--------------

    • 11.5 |  4  |   2.0,  3.5   |   2.875 |    3.5      |     3.5
      
    • 11.5 |  4  |   2,    3.5   |   2.875 |    3.5      |     3.5
      

------±----±--------------±--------±------------±--------------

    • 11.5 | -4  |  -3.0, -0.5   |  -2.875 |   -0.5      |     3.5
      
    • 11.5 | -4  |  -3,   -0.5   |  -2.875 |   -0.5      |     3.5
      

------±----±--------------±--------±------------±--------------

    • -11.5 | 4 | -3.0 0.5 | -2.875 | 0.5 | -3.5
    • -11.5 | 4 | -3, 0.5 | -2.875 | 0.5 | -3.5

------±----±--------------±--------±------------±--------------

    • -11.5 | -4 | 2.0 -3.5 | 2.875 | -3.5 | -3.5
    • -11.5 | -4 | 2, -3.5 | 2.875 | -3.5 | -3.5
    • Examples
    • 11.divmod(3)         #=> [3, 2]
      
    • 11.divmod(-3)        #=> [-4, -1]
      
    • 11.divmod(3.5)       #=> [3.0, 0.5]
      
    • (-11).divmod(3.5)    #=> [-4.0, 3.0]
      
    • (11.5).divmod(3.5)   #=> [3.0, 1.0]
      
    • 11.divmod(3.5)       #=> [3, 0.5]
      
    • (-11).divmod(3.5)    #=> [-4, 3.0]
      
    • (11.5).divmod(3.5)   #=> [3, 1.0]
      
    */

static VALUE
@@ -696,7 +696,7 @@
static VALUE
flo_divmod(VALUE x, VALUE y)
{

  • double fy, div, mod;
  • double fy, div, mod, val;
    volatile VALUE a, b;

    switch (TYPE(y)) {
    @@ -713,7 +713,13 @@
    return rb_num_coerce_bin(x, y);
    }
    flodivmod(RFLOAT(x)->value, fy, &div, &mod);

  • a = rb_float_new(div);
  • if (FIXABLE(div)) {
  •    val = div;
    
  •    a = LONG2FIX(val);
    
  • }
  • else {
  •    a = rb_dbl2big(div);
    
  • }
    b = rb_float_new(mod);
    return rb_assoc_new(a, b);
    }

— test/ruby/test_float.rb.orig 2006-05-16 17:39:56.453136504
+0900
+++ test/ruby/test_float.rb 2006-05-16 17:40:33.460510528 +0900
@@ -87,4 +87,32 @@
assert_raise(ArgumentError){Float(“1e”)}
# add expected behaviour here.
end
+

  • def test_divmod
  • assert_equal([2, 3.5], 11.5.divmod(4))
  • assert_equal([-3, -0.5], 11.5.divmod(-4))
  • assert_equal([-3, 0.5], (-11.5).divmod(4))
  • assert_equal([2, -3.5], (-11.5).divmod(-4))
  • end
  • def test_div
  • assert_equal(2, 11.5.div(4))
  • assert_equal(-3, 11.5.div(-4))
  • assert_equal(-3, (-11.5).div(4))
  • assert_equal(2, (-11.5).div(-4))
  • end
  • def test_modulo
  • assert_equal(3.5, 11.5.modulo(4))
  • assert_equal(-0.5, 11.5.modulo(-4))
  • assert_equal(0.5, (-11.5).modulo(4))
  • assert_equal(-3.5, (-11.5).modulo(-4))
  • end
  • def test_remainder
  • assert_equal(3.5, 11.5.remainder(4))
  • assert_equal(3.5, 11.5.remainder(-4))
  • assert_equal(-3.5, (-11.5).remainder(4))
  • assert_equal(-3.5, (-11.5).remainder(-4))
  • end
    end

#16

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

In message “Re: [ruby-dev:28642] Re: Float#div and Float#divmod [AGAIN]”
on Tue, 16 May 2006 18:15:15 +0900, Shin-ichiro HARA
removed_email_address@domain.invalid writes:

|e$BKX$IA0$HF1$8$G$9$,!“0l1~%Q%C%A$N7A$K$7$F$*$-$^$9!#e(B
|e$B$^$D$b$H$5$s!”$h$m$7$/$*4j$$$7$^$9!#e(B

e$BE,MQ$7$F$*$-$^$9!#%3%_%C%H$O$A$g$C$H@h$K$J$j$=$&!#e(B