BigDecimal#to_i/to_int の挙動について

e$B$+$/$?$K$G$9!#e(B

rubyspec
e$B$re(B1.8e$B%?!<%2%C%H$GF0$+$7$F$$$F!"I85-$Ne(Bspece$B$,<j85$G$ODL$i$J$$$3$H$K5$$E$-$^$7$?!#e(B
e$B2?$,@5$7$$$N$+<+J,$G$O$o$+$i$J$$$N$G65$($F$b$i$($k$H$&$l$7$$$G$9!#e(B

BigDecimale$B$Ge(B Infinitye$B$He(BNaN e$B$re(B to_i/to_int
e$B$9$k$H!"e(B
e$B<j85$N4D6-$G$O<!$N$h$&$K$J$j$^$7$?e(B:
(e$BF0$+$7$F$$$k%P!<%8%g%s$,>/$7A0$N$b$N$G62=L$G$9e(B)

$ /usr/bin/ruby -v -rbigdecimal -e %w[Infinity NaN].each{|s| v =
BigDecimal.new(s); i = v.to_i rescue $!.class; print #{v}:;p i}
ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]
Infinity:nil
NaN:nil

$ ruby -v -rbigdecimal -e %w[Infinity NaN].each{|s| v =
BigDecimal.new(s); i = v.to_i rescue $!.class; print #{v}:;p i}
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9]
Infinity:FloatDomainError
NaN:FloatDomainError

$ ruby19 -v -rbigdecimal -e %w[Infinity NaN].each{|s| v =
BigDecimal.new(s); i = v.to_i rescue $!.class; print #{v}:;p i}
ruby 1.9.2dev (2009-10-05 trunk 25235) [i386-darwin9.8.0]
Infinity:FloatDomainError
NaN:FloatDomainError

e$B$k$j$^$N5-=R$Oe(B1.8e$B$be(B1.9e$B$b!Ve(BInfinity e$B$de(B NaN
e$B$N$H$-!"e(Bi e$B$Oe(B nil e$B$K$J$j$^$9!W$G$7$?!#e(B
http://doc.okkez.net/187/view/method/BigDecimal/i/to_i
http://doc.okkez.net/192/view/method/BigDecimal/i/to_i

e$B<j85$G<:GT$7$?e(Bspece$B$O!"e(B
http://github.com/rubyspec/rubyspec/blob/master/library/bigdecimal/shared/to_int.rb
e$B$Ne(B5e$B9TL$He(B6e$B9TL$G$9!#e(B

e$B:XF#$H?=$7$^$9!#e(B

On Tue, 13 Oct 2009 16:43:24 +0900
KAKUTANI Shintaro [email protected] wrote:

rubyspec e$B$re(B1.8e$B%?!<%2%C%H$GF0$+$7$F$$$F!"I85-$Ne(Bspece$B$,<j85$G$ODL$i$J$$$3$H$K5$$E$-$^$7$?!#e(B
e$B2?$,@5$7$$$N$+<+J,$G$O$o$+$i$J$$$N$G65$($F$b$i$($k$H$&$l$7$$$G$9!#e(B

e$BKM$b$A$c$s$H$OJ,$+$C$F$$$J$$$N$G$9$,!";29M$K$J$j$=$&$J>pJs$rJB$Y$F$_$^$9!#e(B

ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9]
Infinity:FloatDomainError
NaN:FloatDomainError

e$B$^$:e(B1.8e$B$K4X$7$F$G$9$,!"e(B1.8.7e$B$G%3%%C%H%%9$,5/$-$F!"0U?^$7$J$$;EMMJQ99$K$J$C$F$7$^$C$Fe(B
e$B$$$k$h$&$J5$$,$7$^$9!#e(B

1.8.6e$B$be(B1.8.7e$B$b!":G=i$N%j%j!<%9;~e(B(pl0)e$B$O!"Nc30$,5/$3$j$^$;$s$G$7$?!#%=!<%9$rAL$k$H!"e(B
e$BNc30$,5/$-$k$h$&$K$J$C$?$N$Oe(B1.8.7-pl173e$B$+$i$N$h$&$G$9!#e(B160e$B$G$Oe(Bnile$B$,JV$k$O$:$G$9!#e(B

1.8.7e$B%V%i%s%A$r8+$k$H!"e(Br23645e$B$GNc30$,>e$,$k$h$&$K$J$C$F$$$^$9!#$3$NItJ,$N%m%0$r8+$k$H!"e(B

r23645 | shyouhei | 2009-06-08 08:37:55 +0900 (Mon, 08 Jun 2009) | 10
lines

merge revision(s) 23610:23613:
* ext/bigdecimal/bigdecimal.c (VpAlloc): avoid ALLOCA_N() to
avoid
segmentation fault caused by (insanely) long decimal values.
backported from 1.9.
* ext/bigdecimal/bigdecimal.c (BigDecimal_dump, BigDecimal_to_i,
BigDecimal_to_f, BigDecimal_to_s, BigDecimal_split,
BigDecimal_inspect): ditto.
* ext/bigdecimal/bigdecimal.c (BigDecimal_to_f): returns Inf if
exp is bigger than DBL_MANT_DIG.

e$B$H$J$C$F$$$F!"Nc30$r5s$2$k$h$&;EMMJQ99$9$k;][email protected]+$i$l$^$;$s!#e(B

e$B$=$7$F$5$i$K%^!<%885$H;W$7$-e(B1.8e$B%V%i%s%A$N%m%0$r8+$k$H!e(Br23613e$B$GNc30$,>e$,$k$h$&$Ke(B
e$B;EMMJQ99$7$F$$$k$N$K!$^$D$b$H$5$s$,$=$N;]$r%m%0$K;D$7$F$$$J$$;v$b$o$+$j$^$9!#e(B

r23613 | matz | 2009-06-01 09:14:25 +0900 (e$B7ne(B, 01 6e$B7ne(B 2009)
| 6 lines

  • ext/bigdecimal/bigdecimal.c (VpAlloc): avoid ALLOCA_N() to avoid
    segmentation fault caused by (insanely) long decimal values.
    backported from 1.9.
  • ext/bigdecimal/bigdecimal.c (BigDecimal_dump, BigDecimal_to_i,
    BigDecimal_to_f, BigDecimal_to_s, BigDecimal_split,
    BigDecimal_inspect): ditto.

e$B$J$N$G!";d$N?dM}$H$7$Fe(B

e$BKNIt$5$s$O85!9!e(B1.8e$B%V%i%s%A$N%P%0%U%#%/%9ItJ,[email protected]$1$re(B1.8.7e$B%V%i%s%A$K%^!<%8$7$?$+$C$?e(B
2.
e$B$^$D$b$H$5$s$,=q$$$?e(B1.8e$B%V%i%s%A$N%m%0$K$O%P%0%U%#%/%9$K4X$9$k5-=R$7$+$J$+$C$?e(B(e$BIT9,e(B1)
e$B$N$G!KNIt$5$s$O$=$l$r?.$8$F$7$^$C$?!#e(B
3.
e$BKNIt$5$s$b%m%0$O3NG$7$?$,!%m%0$HL54X78$JJQ99$,<B:]$N%3!<%I$K$$j!";EMMJQ99$5$l$Fe(B
e$B$$$k;v$K5$$E$/$^$G$K$O;j$i$J$+$C$?e(B(e$BIT9,e(B2)e$B!#e(B
4.
e$B7k2L!"%P%0%U%#%/%9$N$_$N%^!<%8$N$D$b$j$,!"e(B1.8.7e$BCf$N;EMMJQ99$K$J$C$F$7$^$C$?!#e(B
5. e$B$=$N$^$^<!$Ne(B1.8.7e$B%Q%C%A%l%Y%k%j%j!<%9e(B

e$B$H$$$&N.$l$rA[A|$9$k$N$G$9$,!"$I$&$G$7$g$&$+e(B > e$BKNIt$5$se(B

e$B$"$k$$$O?dM}e(BBe$B$H$7$F$Oe(B

3.
e$BKNIt$5$s$O%m%0$K:$C$F$$$J$$;EMMJQ99$r3NG$7$?$,!"$b$H$b$H$N;EMM$,!V%P%0$G$"$k!We(B
e$B$HH=CG$7$?$?$a%^!<%8$7$?!#$7$+$7%m%0$K:$;$J$$$N$O$=$N$^$^[email protected]$C$?!#e(B

e$B$H$$$&9bEY$JJ*$b$"$j$($^$9$,!"[email protected]$ODc$$5$$,$7$^$9!#e(B

e$B$H$j$"$($:!"%3%_%C%H%m%0$H%A%%C%/%$%s$NFbMF$O$A$c$s$HBP1~$5$;$F$/[email protected]$5$$e(B

e$B$^$D$b$H$5$se(B

$ ruby19 -v -rbigdecimal -e %w[Infinity NaN].each{|s| v = BigDecimal.new(s); i = v.to_i rescue $!.class; print #{v}:;p i}
ruby 1.9.2dev (2009-10-05 trunk 25235) [i386-darwin9.8.0]
Infinity:FloatDomainError
NaN:FloatDomainError

1.9e$B$K4X$7$F$O!e(B
e$B$^$D$b$H$5$s$,e(B[ruby-dev:37195]e$B$G$3$l$r!V$$^$jNI$/[email protected]_7W!W$HH=CGe(B
e$B$5$l$?$?$a!"Nc30$,H/@8$9$k$h$&$K$J$C$?$h$&$G$9!#e(Btrunke$B$Ne(Br20359e$B$G$9!#e(B
e$B$3$l$Oe(B1.9.1e$B$NA0$Ne(Btrunke$B$J$N$G!e(B1.8e$B$+$ie([email protected]<(E*$K;EMMJQ99$5$l$?!$H$$$&[email protected]$H;W$C$Fe(B
e$B$$$^$9!#e(B

e$B0J>e!";29M$K$J$l$P9,$$$G$9!#e(B

Tadashi S. e$B$5$s$O=q$-$^$7$?e(B:

  1. e$BKNIt$5$s$O85!9!"e(B1.8e$B%V%i%s%A$N%P%0%U%#%/%9ItJ,[email protected]$1$re(B1.8.7e$B%V%i%s%A$K%^!<%8$7$?$+$C$?e(B
  2. e$B$^$D$b$H$5$s$,=q$$$?e(B1.8e$B%V%i%s%A$N%m%0$K$O%P%0%U%#%/%9$K4X$9$k5-=R$7$+$J$+$C$?e(B(e$BIT9,e(B1)
    e$B$N$G!"KNIt$5$s$O$=$l$r?.$8$F$7$^$C$?!#e(B
  3. e$BKNIt$5$s$b%m%0$O3NG$7$?$,!"%m%0$HL54X78$JJQ99$,<B:]$N%3!<%I$K$"$j!";EMMJQ99$5$l$Fe(B
    e$B$$$k;v$K5$$E$/$^$G$K$O;j$i$J$+$C$?e(B(e$BIT9,e(B2)e$B!#e(B
  4. e$B7k2L!"%P%0%U%#%/%9$N$_$N%^!<%8$N$D$b$j$,!"e(B1.8.7e$BCf$N;EMMJQ99$K$J$C$F$7$^$C$?!#e(B
  5. e$B$=$N$^$^<!$Ne(B1.8.7e$B%Q%C%A%l%Y%k%j%j!<%9e(B

e$B$H$$$&N.$l$rA[A|$9$k$N$G$9$,!"$I$&$G$7$g$&$+e(B > e$BKNIt$5$se(B

e$B$"$C$F$^$9!#$"$($FDI2C$9$l$Pe(B

1.8.7e$B$K$Oe(Btest/bigdecimale$B$,$J$$$N$G%j%0%l%C%7%g%s$K5$$E$+$J$+$C$?e(B

e$B$b860x$KF~$l$F$b$$$$$+$b$7$l$^$;$s!#$4$a$s$J$5$$!#e(B1.8.7e$B$K4X$7$F$O0U?^$7$J$$;EMMe(B
e$BJQ99$J$N$G!"La$7$F$*$3$&$H;W$$$^$9!#e(B

e$B<B:]!"$I$&$$$&5sF0$,K>$^[email protected]$,I,MW$+!#e(B

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs