[Bug #793] BigDecimal('Infinity').to_r $B$,Nm$K$J$k(B


#1

Bug #793: BigDecimal(‘Infinity’).to_r e$B$,Nm$K$J$ke(B
http://redmine.ruby-lang.org/issues/show/793

e$B5/I<<Te(B: tadayoshi funaba
e$B%9%F!<%?%9e(B: Open, e$BM%@hEYe(B: Normal

$ ./ruby -rbigdecimal -e “p BigDecimal(‘Infinity’).to_r”
(0/1)

1.8 e$B$G$bF1$8$G$9!#e(B

$ ruby18 -rbigdecimal -rbigdecimal/util -rrational -e “p
BigDecimal(‘Infinity’).to_r”
Rational(0, 1)

e$B0JA0!"?V$M$?$H;W$&$N$G$9$,!“e(Bto_i e$B$,e(B nil
e$B$K$J$k$N$bLdBj$,$”$k$H;W$$$^$9!#e(B

$ ./ruby -rbigdecimal -e “p BigDecimal(‘Infinity’).to_i”
nil


#2

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

In message “Re: [ruby-dev:37187] [Bug #793] BigDecimal(‘Infinity’).to_r
e$B$,Nm$K$J$ke(B”
on Tue, 25 Nov 2008 23:29:59 +0900, tadayoshi funaba
removed_email_address@domain.invalid writes:

|$ ./ruby -rbigdecimal -e “p BigDecimal(‘Infinity’).to_r”
|(0/1)

|e$B0JA0!"?V$M$?$H;W$&$N$G$9$,!“e(Bto_i e$B$,e(B nil e$B$K$J$k$N$bLdBj$,$”$k$H;W$$$^$9!#e(B
|
|$ ./ruby -rbigdecimal -e “p BigDecimal(‘Infinity’).to_i”
|nil

e$B$I$&$be(BBigDecimale$B$N;EMM$r8+$F$k$He(B

  • BigDecimal.modee$B$H$$$&B0@-$,$"$j!"$I$N$h$&$J;~$KNc30$,H/e(B
    e$B@8$9$k$+%0%m!<%P%k$J>uBV$H$7$F@_Dj$G$-$ke(B

  • e$B%G%U%)%k%H$G$O$"$i$f$kNc30$rH/@8$5$;$J$$e(B

e$B$H$$$&0U;W$,$"$k$h$&$G$9!#8D?ME*$K$O%0%m!<%P%k$J>uBV$b!"$^$:e(B
e$B$$>u67$G$bNc30$r5/$3$5$:7QB3$9$k$N$b!"$"$^$jNI$/$J$$@_7W$G$Oe(B
e$B$J$$$+$H46$8$J$$$G$b$J$$$G$9!#e(B

e$B$?$@!“e(BBigDecimale$B$GJD$8$F$k$&$A$O$&$l$7$$$3$H$b$”$k$N$+$b$7$le(B
e$B$J$$$N$G!"!Ve(BRubye$B$N@$3&!W$KF~$C$F$/$ke(Bto_e$B$G$OL@<(E$KNc30$rH/e(B
e$B@8$5$;$k$3$H$K$7$^$9!#e(B

e$B$^$"!"?t3XCN$i$:$N;d$NH=CG$G$9$+$i!“4V0c$C$F$$$k2DG=@-$O$$$De(B
e$B$b9b$$$N$G$9$,!”$=$N>l9g$O$I$J$?$+;XE&$7$F$/$@$5$$!#e(B

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

#3

e$B$I$&$be(BBigDecimale$B$N;EMM$r8+$F$k$He(B

  • BigDecimal.modee$B$H$$$&B0@-$,$"$j!"$I$N$h$&$J;~$KNc30$,H/e(B
    e$B@8$9$k$+%0%m!<%P%k$J>uBV$H$7$F@_Dj$G$-$ke(B

  • e$B%G%U%)%k%H$G$O$"$i$f$kNc30$rH/@8$5$;$J$$e(B

e$B$=$N%b!<%I$Ge(B EXCEPTION_ZERODIVIDE e$B$rM-8z$K$9$k$He(B Infinity
e$B<+BN$r:n$l$Je(B
e$B$/$J$k$s$G$9$M!#Nm3d$Ge(B Infinity e$B$r@8$8$k$N$H!"e(BInfinity
e$B$r:n$k$3$H$OJL$Ne(B
e$B$h$&$K;W$&$N$G$9$,!"e(BMarshal.load
e$B$b=PMh$J$/$J$j$^$9$M!#$3$&$$$&$b$N$J$Ne(B
e$B$+$J!#e(B

$ ./irb-test -rbigdecimal
main@190-20081126> b = BigDecimal(‘Infinity’)
#=> #BigDecimal:827a9a4,‘Infinity’,4(4)
main@190-20081126>
BigDecimal::mode(BigDecimal::EXCEPTION_ZERODIVIDE,true)
#=> 1
main@190-20081126> BigDecimal(‘Infinity’)
FloatDomainError: Computation results to ‘Infinity’
from (irb):3:in BigDecimal' from (irb):3 from ./bin/irb:12:in
main@190-20081126> Marshal.load(Marshal.dump(b))
FloatDomainError: Computation results to ‘Infinity’
from (irb):5:in _load' from (irb):5:inload’
from (irb):5
from ./bin/irb:12:in `’


#4

EXCEPTION_ZERODIVIDE(e$B$He(BEXCEPTION_OVERFLOW)e$B$,!"$I$&$$$&$o$1$@e(B
e$B$+e(BEXCEPTION_INFINITYe$B$NJLL>$K$J$C$F$^$9$M!#K\Mh$O;H$$J,$1$k$Ye(B
e$B$-$@$H;W$&$N$G$9$,!#e(B

e$B$"$"!"$J$k$[$I!#85$N;EMM$@$He(B BigDecimal(‘Infinity’).to_i
e$B$GNc30$r>e$2$ke(B
e$B$K$Oe(B EXCEPTION_INFINITY
e$B$r@_Dj$7$J$1$l$P$J$i$J$$!"$G$b!"$=$&$9$k$He(B
BigDecimal(‘Infinity’) e$B<+BN$GNc30$H$J$C$F$7$^$&$o$1$G$9$M!#e(B


#5

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

In message “Re: [ruby-dev:37204] Re: [Bug #793]
BigDecimal(‘Infinity’).to_r e$B$,Nm$K$J$ke(B”
on Wed, 26 Nov 2008 22:01:52 +0900, Tadayoshi F.
removed_email_address@domain.invalid writes:

|e$B$=$N%b!<%I$Ge(B EXCEPTION_ZERODIVIDE e$B$rM-8z$K$9$k$He(B Infinity e$B<+BN$r:n$l$Je(B
|e$B$/$J$k$s$G$9$M!#Nm3d$Ge(B Infinity e$B$r@8$8$k$N$H!"e(BInfinity e$B$r:n$k$3$H$OJL$Ne(B
|e$B$h$&$K;W$&$N$G$9$,!"e(BMarshal.load e$B$b=PMh$J$/$J$j$^$9$M!#$3$&$$$&$b$N$J$Ne(B
|e$B$+$J!#e(B

EXCEPTION_ZERODIVIDE(e$B$He(BEXCEPTION_OVERFLOW)e$B$,!"$I$&$$$&$o$1$@e(B
e$B$+e(BEXCEPTION_INFINITYe$B$NJLL>$K$J$C$F$^$9$M!#K\Mh$O;H$$J,$1$k$Ye(B
e$B$-$@$H;W$&$N$G$9$,!#e(B


#6

EXCEPTION_ZERODIVIDE e$B$r@_Dj$7$?>l9g!"e(BBigDecimal#/
e$B$GNc30$K$J$j$^$9e(B
e$B$,!"e(Bdiv e$B$de(B divmod e$B$G$O$J$j$^$;$s!#e(BFloat
e$B$G$b!"e(Bdiv e$B$ONc30$G$9$,!"e(B
divmod e$B$G$ONc30$K$J$j$^$;$s!#e(BInteger e$B$G$O!"e(Bdive$B!"e(Bdivmod
e$B$H$b$KNc30e(B
e$B$K$J$j$^$9!#e(B

e$B0c$$$,$"$j$^$9$,!"$3$N$"$?$j$I$&$J$s$G$7$g$&!#$=$l$>$l$K$D$$$Fe(B
divmod
e$B$He(B modulo e$B$N4X78$K$OL7=b$O$J$$$h$&$G$9!#e(B

$ ./irb-test -rbigdecimal
main@190-20081126>
BigDecimal::mode(BigDecimal::EXCEPTION_ZERODIVIDE,true)
#=> 16
main@190-20081126> BigDecimal(‘1’) / 0
FloatDomainError: (VpDivd) Divide by zero
from (irb):2:in /' from (irb):2 from ./bin/irb:12:in
main@190-20081126> BigDecimal(‘1’).div(0)
#=> #BigDecimal:826d998,‘NaN’,4(4)
main@190-20081126> BigDecimal(‘1’).divmod(0)
#=> [#BigDecimal:82259e0,‘NaN’,4(4), #BigDecimal:8225a58,‘NaN’,4(4)]

main@190-20081126> 1.0.div(0)
ZeroDivisionError: divided by 0
from (irb):5:in div' from (irb):5 from ./bin/irb:12:in
main@190-20081126> 1.0.divmod(0)
#=> [NaN, NaN]