# Rational 1.12

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

e\$B86\$5\$s\$Ne(B rational 1.12 e\$B\$G!"\$D\$.\$N\$h\$&\$K%(%i!<\$K\$J\$j\$^\$9!#e(B

\$ ruby -v -r rational -e ‘p “13.0/4”.to_r’
ruby 1.8.4 (2005-12-24) [i386-freebsd5.4]
-e:1:in `to_r’: Error of Implementation (rb_rat_eval_str). (fatal)
from -e:1

e\$B;X?tI=8=\$G2r<a\$r4V0c\$(\$^\$9!#e(B

‘9e0’.to_r #=> 9/1
‘-9e0’.to_r #=> 9/1

e\$B%9%i%C%7%e\$,\$i\$_\$GHyL/\$J2r<a\$r\$7\$^\$9!#e(B

‘9/’.to_r # ZeroDivisionError

e\$B>[email protected]\$G=*\$k\$H%(%i!<\$K\$J\$j\$^\$9!#e(B

Float(‘9.’) #=> 9.0
Rational(‘9.’) # ArgumentError

[email protected]\$G\$9!#e(B

At Mon, 17 Jul 2006 20:34:42 +0900,

e\$B>[email protected]\$G=*\$k\$H%(%i!<\$K\$J\$j\$^\$9!#e(B

Float(‘9.’) #=> 9.0
Rational(‘9.’) # ArgumentError

e\$B\$3\$l\$Oe(BFloate\$B\$N\$[\$&\$,\$*\$+\$7\$\$\$h\$&\$J!#e(B

# Index: util.c

RCS file: /cvs/ruby/src/ruby/util.c,v
retrieving revision 1.52
diff -p -U 2 -r1.52 util.c
— util.c 9 Jun 2006 23:17:59 -0000 1.52
+++ util.c 17 Jul 2006 14:11:12 -0000
@@ -768,7 +768,7 @@ ruby_strtod(
*/

• for ( ; c = *p; p++) {
• for ( ; (c = *p) != ‘\0’; p++) {
•   if (c != '.' || hasPoint) {

•   if (c != '.' || hasPoint || ISDIGIT(p[1])) {
break;
}

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

In message “Re: [ruby-dev:29036] Re: rational 1.12”
on Mon, 17 Jul 2006 23:15:01 +0900, [email protected] writes:

|At Mon, 17 Jul 2006 20:34:42 +0900,
|> e\$B>[email protected]\$G=\$k\$H%(%i!<\$K\$J\$j\$^\$9!#e(B
|>
|> Float(‘9.’) #=> 9.0
|> Rational(‘9.’) # ArgumentError
|
|e\$B\$3\$l\$Oe(BFloate\$B\$N\$[\$&\$,\$
\$+\$7\$\$\$h\$&\$J!#e(B

e\$B\$G\$9\$M!#%3%_%C%H\$7\$F\$/[email protected]\$5\$\$!#e(B

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

Float(‘9.’) #=> 9.0
Rational(‘9.’) # ArgumentError

e\$B\$3\$l\$Oe(BFloate\$B\$N\$[\$&\$,\$*\$+\$7\$\$\$h\$&\$J!#e(B

e\$BJ}?K\$,\$h\$/\$o\$+\$i\$J\$/\$J\$C\$F\$-\$?\$s\$G\$9\$,!"e(Bruby
e\$B\$N;[email protected]\$K9g\$;\$k\$H\$+e(B?

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

In message “Re: [ruby-dev:29040] Re: rational 1.12”
on Tue, 18 Jul 2006 00:24:24 +0900, Tadayoshi F.
[email protected] writes:

|> > Float(‘9.’) #=> 9.0
|> > Rational(‘9.’) # ArgumentError
|>
|> e\$B\$3\$l\$Oe(BFloate\$B\$N\$[\$&\$,\$*\$+\$7\$\$\$h\$&\$J!#e(B
|
|e\$BJ}?K\$,\$h\$/\$o\$+\$i\$J\$/\$J\$C\$F\$-\$?\$s\$G\$9\$,!"e(Bruby e\$B\$N;[email protected]\$K9g\$;\$k\$H\$+e(B?

e\$B\$=\$&\$G\$9!#e(B

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

|> > Float(‘9.’) #=> 9.0
|> > Rational(‘9.’) # ArgumentError
|>
|> e\$B\$3\$l\$Oe(BFloate\$B\$N\$[\$&\$,\$*\$+\$7\$\$\$h\$&\$J!#e(B
|
|e\$BJ}?K\$,\$h\$/\$o\$+\$i\$J\$/\$J\$C\$F\$-\$?\$s\$G\$9\$,!"e(Bruby e\$B\$N;[email protected]\$K9g\$;\$k\$H\$+e(B?

e\$B\$=\$&\$G\$9!#e(B

e\$B\$G\$"\$l\$P!"e(B.9 e\$B\$b%@%a\$G\$7\$g\$&\$+!#e(B

Float(’.9’) #=> 0.9
Rational(’.9’) #=> 9/10
BigDecimal(’.9’) #=> #BigDecimal:8236934,‘0.9E0’,4(8)

e\$BJ8L.\$N0c\$\$\$r9M\$(\$:\$K!"\$H\$K\$+\$/F1\$8\$K\$9\$k\$H\$\$\$&\$J\$i!"e(BFloat(‘080’)
e\$B\$,DL\$Ce(B
e\$B\$F\$7\$^\$&\$N\$b\$*\$+\$7\$\$\$H\$\$\$(\$J\$/\$b\$J\$\$\$+\$b!#e(B

e\$B:#!"5\$\$,\$D\$\$\$?\$1\$I!“e(BRational(nil)
e\$B\$,DL\$k\$N\$O\$*\$+\$7\$\$\$+\$b!”\$H;W\$C\$?\$i!"e(B
Float(nil) e\$B\$O%@%a\$G!"e(BInteger(nil)
e\$B\$O\$\$\$\$\$N\$+!#[email protected][email protected]\$s2r\$i\$J\$/\$J\$C\$F\$-e(B
e\$B\$?e(B…e\$B!#e(B

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

String#to_r e\$B\$r:#=q\$-49\$(\$F\$\$\$k\$N\$G\$9\$,!"\$J\$+\$J\$+e(B
e\$B;EMM\$,GD0.\$G\$-\$^\$;\$s!#e(B

[ruby-dev:28868] e\$B\$G!"\$^\$D\$b\$H\$5\$s\$O!"e(B

“9e+_9”.to_f #=> 9000000000.0

[email protected][email protected]\$C\$F\$\$\$^\$9\$,!“e(B_e\$B\$,e(Bee\$B\$ND>A0\$K\$”\$k>l9g\$O\$I\$&\$G\$7\$g\$&!#e(B

“9_e+9”.to_f #=> 9000000000.0

e\$B\$G\$7\$g\$&\$+!)e(B

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

In message “Re: [ruby-dev:29050] Re: rational 1.12”
on Tue, 18 Jul 2006 12:46:52 +0900, Tadayoshi F.
[email protected] writes:

|e\$B\$G\$"\$l\$P!"e(B.9 e\$B\$b%@%a\$G\$7\$g\$&\$+!#e(B

e\$B\$=\$3\$^\$G87L)\$K\$9\$k\$H:#EY\$O5U\$K;H\$\$\$K\$/\$\$\$s\$G!"!Ve(B.9e\$B!W\$O5v\$=\$&e(B
e\$B\$H;W\$\$\$^\$9!#e(B

|e\$B:#!"5\$\$,\$D\$\$\$?\$1\$I!“e(BRational(nil) e\$B\$,DL\$k\$N\$O\$*\$+\$7\$\$\$+\$b!”\$H;W\$C\$?\$i!"e(B
|Float(nil) e\$B\$O%@%a\$G!"e(BInteger(nil) e\$B\$O\$\$\$\$\$N\$+!#[email protected][email protected]\$s2r\$i\$J\$/\$J\$C\$F\$-e(B
|e\$B\$?e(B…e\$B!#e(B

e\$BItJ,:GE,2=\$N=8\$^\$j\$G\$9\$+\$i\$M\$(!#e(B

e\$B2~\$a\$F9M\$(\$^\$7\$?\$,!"e(BInteger(nil)e\$B0J30\$ODL\$i\$J\$/\$F\$h\$\$\$H;W\$\$\$^e(B
e\$B\$9!#e(B1.9e\$B\$G\$Oe(BInteger(nil)e\$B\$b6X;_\$7\$h\$&\$+\$J!#e(B

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

In message “Re: [ruby-dev:29088] Re: rational 1.12”
on Thu, 20 Jul 2006 21:29:14 +0900, Shin-ichiro HARA
[email protected] writes:

|[ruby-dev:28868] e\$B\$G!"\$^\$D\$b\$H\$5\$s\$O!"e(B
|
|“9e+_9”.to_f #=> 9000000000.0
|
|[email protected][email protected]\$C\$F\$\$\$^\$9\$,!"e(B

[email protected]\$C\$F\$^\$;\$se(B(e\$B3N\$+\$K!VBP=h\$7\$^[email protected]\$C\$F\$J\$\$e(B)e\$B!#e(B1.9e\$B\$G;ne(B
e\$B\$7\$F\$b\$i\$&\$H\$o\$+\$j\$^\$9\$,!"e(B

“9e+_9”.to_f #=> 9.0

e\$B\$G\$9!#\$D\$^\$j!"!Ve(Be+9e\$B!W\$O!Ve(B9e\$B\$N8e\$m\$K\$D\$\$\$?%4%!W\$G\$9!#e(B

|_e\$B\$,e(Bee\$B\$ND>A0\$K\$"\$k>l9g\$O\$I\$&\$G\$7\$g\$&!#e(B
|
|“9_e+9”.to_f #=> 9000000000.0
|
|e\$B\$G\$7\$g\$&\$+!)e(B

e\$B;d\$N%\$%a!<%[email protected]\$He(B"e+9"e\$B\$,!Ve(B9e\$B\$N8e\$m\$K\$D\$\$\$?%4%!W\$G!“e(B9.0e\$B\$K\$J\$ke(B
e\$B\$O\$:\$G\$9\$,!”\$J\$<\$+e(B1.9e\$B\$G\$be(B9000000000.0e\$B\$K\$J\$j\$^\$9\$M!#e(BFloat()e\$B\$Ge(B
e\$B\$O%(%i!<[email protected]\$1\$I\$J!#\$3\$l\$be(B9.0e\$B\$K\$9\$k\$h\$&\$KD>\$7\$^\$9!#e(B

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

[email protected]\$C\$F\$^\$;\$se(B(e\$B3N\$+\$K!VBP=h\$7\$^[email protected]\$C\$F\$J\$\$e(B)e\$B!#e(B1.9e\$B\$G;ne(B
e\$B\$7\$F\$b\$i\$&\$H\$o\$+\$j\$^\$9\$,!"e(B

“9e+_9”.to_f #=> 9.0

e\$B\$G\$9!#\$D\$^\$j!"!Ve(Be+9e\$B!W\$O!Ve(B9e\$B\$N8e\$m\$K\$D\$\$\$?%4%!W\$G\$9!#e(B

[email protected]\$C\$F\$^\$9!#e(B[ruby-dev:28872] e\$B\$G!"!J\$"!";2>HHV9f4V0c\$(\$?\$C!Ke(B

e\$B\$h\$C\$F!“e(B(e\$B\$H\$j\$”\$(\$:e(B1.9e\$B\$Ge(B)[email protected]\$7\$^\$9!#JQ998e\$N7k2L\$O0J2<\$NDLe(B
e\$B\$j\$G\$9!#e(B

“9e+_9”.to_i #=> 9
“9e+_9”.to_f #=> 9000000000.0

BigDecimale\$B\$de(BRationale\$B\$K\$D\$\$\$F\$O\$3\$l\$K=`\$:[email protected]\$H;W\$\$\$^\$9!#e(B

e\$B\$H!#e(B

[email protected]\$C\$F\$^\$;\$se(B(e\$B3N\$+\$K!VBP=h\$7\$^[email protected]\$C\$F\$J\$\$e(B)e\$B!#e(B1.9e\$B\$G;ne(B
e\$B\$7\$F\$b\$i\$&\$H\$o\$+\$j\$^\$9\$,!"e(B

“9e+_9”.to_f #=> 9.0

e\$B\$G\$9!#\$D\$^\$j!"!Ve(Be+9e\$B!W\$O!Ve(B9e\$B\$N8e\$m\$K\$D\$\$\$?%4%!W\$G\$9!#e(B

e\$B\$=\$A\$i\$NJ}\$,<u\$1F~\$l\$d\$9\$\$\$+\$J!#e(B

|_e\$B\$,e(Bee\$B\$ND>A0\$K\$"\$k>l9g\$O\$I\$&\$G\$7\$g\$&!#e(B
|
|“9_e+9”.to_f #=> 9000000000.0
|
|e\$B\$G\$7\$g\$&\$+!)e(B

e\$B;d\$N%\$%a!<%[email protected]\$He(B"e+9"e\$B\$,!Ve(B9e\$B\$N8e\$m\$K\$D\$\$\$?%4%!W\$G!“e(B9.0e\$B\$K\$J\$ke(B
e\$B\$O\$:\$G\$9\$,!”\$J\$<\$+e(B1.9e\$B\$G\$be(B9000000000.0e\$B\$K\$J\$j\$^\$9\$M!#e(BFloat()e\$B\$Ge(B
e\$B\$O%(%i!<[email protected]\$1\$I\$J!#\$3\$l\$be(B9.0e\$B\$K\$9\$k\$h\$&\$KD>\$7\$^\$9!#e(B

e\$BN;2r\$7\$^\$7\$?!#\$=\$l\$G\$O\$=\$&\$\$\$&\$3\$H\$G!#e(B

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

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

e\$B86\$5\$s\$Ne(B rational 1.12 e\$B\$G!"\$D\$.\$N\$h\$&\$K%(%i!<\$K\$J\$j\$^\$9!#e(B

\$ ruby -v -r rational -e ‘p “13.0/4”.to_r’
ruby 1.8.4 (2005-12-24) [i386-freebsd5.4]
-e:1:in `to_r’: Error of Implementation (rb_rat_eval_str). (fatal)
from -e:1

e\$B\$&\$&!"\$3\$l\$+\$i\$O!“e(B"13.0/4”.to_r e\$B\$Oe(B “13.0”.to_r
e\$B\$H2r<a\$9\$k\$3\$H\$K\$7\$^\$9!#e(B

e\$B;X?tI=8=\$G2r<a\$r4V0c\$(\$^\$9!#e(B

‘9e0’.to_r #=> 9/1
‘-9e0’.to_r #=> 9/1

e\$B%_%9\$G\$7\$?!#e(B

e\$B%9%i%C%7%e\$,\$i\$_\$GHyL/\$J2r<a\$r\$7\$^\$9!#e(B

‘9/’.to_r # ZeroDivisionError

‘9/’.to_r e\$B\$Oe(B ‘9’.to_r e\$B\$H\$\$\$&2r<a\$r\$9\$Y\$-\$G\$7\$?!#e(B

e\$B>[email protected]\$G=*\$k\$H%(%i!<\$K\$J\$j\$^\$9!#e(B

Float(‘9.’) #=> 9.0
Rational(‘9.’) # ArgumentError

e\$B\$3\$l\$O%(%i!<\$K\$9\$k\$3\$H\$K\$J\$C\$?\$N\$G\$9\$M!#e(B

e\$BJ8;zNs\$N2r<a\$N%k!<%F%#%s\$re(Brubye\$BK\BN\$N\$H6&MQ\$7\$h\$&\$H\$\$\$&e(B
e\$BLnK>\$O<N\$F\$FFH<+O)@~\$G9T\$/\$3\$H\$K\$7\$^\$7\$?!#e(B

e\$B8=>ue(B(rational-1.13)e\$B\$O\$3\$&\$J\$C\$F\$\$\$^\$9e(B:

“”.to_r => 0 Rational("") => ArgumentError
“+7 7”.to_r => 7 Rational("+7 7") => ArgumentError
“+7_”.to_r => 7 Rational("+7_") => ArgumentError
“+7".to_r => 0 Rational("+7") => ArgumentError
“-7 7”.to_r => -7 Rational("-7 7") => ArgumentError
"7
".to_r => 7 Rational("7
”) => ArgumentError
“7_7”.to_r => 77 Rational(“7_7”) => 77
".to_r => 0 Rational("”) => ArgumentError
+7".to_r => 0 Rational("+7”) => ArgumentError
“_7”.to_r => 0 Rational("_7") => ArgumentError

“+7E 1”.to_r => 7 Rational("+7E 1") => ArgumentError
“+7E1”.to_r => 70 Rational("+7E1") => 70
“+7_7.7_7E-0_1”.to_r => 7777/1000 Rational("+7_7.7_7E-0_1") =>
7777/1000
“- 7.7”.to_r => -77/10 Rational("- 7.7") => -77/10
“-7.7”.to_r => -77/10 Rational("-7.7") => -77/10
“-7.7E-2”.to_r => -77/1000 Rational("-7.7E-2") => -77/1000
“-7.7E_1”.to_r => -77/10 Rational("-7.7E_1") => ArgumentError
“-7E+1".to_r => -7 Rational("-7E+1") => ArgumentError
"-7E-1
".to_r => -7/10 Rational("-7E-1
”) => ArgumentError
“-7E1”.to_r => -70 Rational("-7E1") => -70
“-7E1_”.to_r => -70 Rational("-7E1_") => ArgumentError
“-7E_1”.to_r => -7 Rational("-7E_1") => ArgumentError
“-7_7.7_”.to_r => -777/10 Rational("-7_7.7_") => ArgumentError
“.”.to_r => 0 Rational(".") => ArgumentError
“.7”.to_r => 7/10 Rational(".7") => 7/10
“0.7”.to_r => 7/10 Rational(“0.7”) => 7/10
“7.”.to_r => 7 Rational(“7.”) => ArgumentError
“7.1E_1”.to_r => 71/10 Rational(“7.1E_1”) => ArgumentError
“7.7”.to_r => 77/10 Rational(“7.7”) => 77/10
“7.7/3”.to_r => 77/10 Rational(“7.7/3”) => ArgumentError
“7.7E-2”.to_r => 77/1000 Rational(“7.7E-2”) => 77/1000
“7.7_”.to_r => 77/10 Rational(“7.7_”) => ArgumentError
“7.E_1”.to_r => 7 Rational(“7.E_1”) => ArgumentError
“7.".to_r => 7 Rational("7.”) => ArgumentError
“7.7".to_r => 7 Rational("7.7") => ArgumentError
“7.E1".to_r => 7 Rational(“7.E1") => ArgumentError
“7.E_1".to_r => 7 Rational(“7.E_1") => ArgumentError
"77.7
”.to_r => 777/10 Rational("77.7
”) => ArgumentError
“7E”.to_r => 7 Rational(“7E”) => ArgumentError
“7E+1".to_r => 7 Rational(“7E+1") => ArgumentError
“7E-1”.to_r => 7/10 Rational(“7E-1”) => 7/10
“7E0”.to_r => 7 Rational(“7E0”) => 7
“7E1”.to_r => 70 Rational(“7E1”) => 70
"7E1
”.to_r => 70 Rational("7E1
”) => ArgumentError
“7E_1”.to_r => 7 Rational(“7E_1”) => ArgumentError
"7
.”.to_r => 7 Rational("7
.”) => ArgumentError
"7
.7
”.to_r => 7 Rational(“7_.7_”) => ArgumentError
“7_.7".to_r => 7 Rational("7.7") => ArgumentError
“7_E+1”.to_r => 7 Rational(“7_E+1”) => ArgumentError
“7_E1”.to_r => 7 Rational(“7_E1”) => ArgumentError
“7_E_1”.to_r => 7 Rational(“7_E_1”) => ArgumentError
“E1”.to_r => 0 Rational(“E1”) => ArgumentError
"
.7”.to_r => 0 Rational(".7") => ArgumentError
"
.7".to_r => 0 Rational("._7") => ArgumentError
“_7.”.to_r => 0 Rational("_7.") => ArgumentError

“-7 / 3_”.to_r => -7/3 Rational("-7 / 3_") => ArgumentError
“-7/”.to_r => -7 Rational("-7/") => ArgumentError
“-7/-3_”.to_r => 7/3 Rational("-7/-3_") => ArgumentError
“-7/3_”.to_r => -7/3 Rational("-7/3_") => ArgumentError
“7 / - 3”.to_r => -7/3 Rational(“7 / - 3”) => -7/3
“7 / 3”.to_r => 7/3 Rational(“7 / 3”) => 7/3
“7 / 3_”.to_r => 7/3 Rational(“7 / 3_”) => ArgumentError
“7/”.to_r => 7 Rational(“7/”) => ArgumentError
“7/-3_”.to_r => -7/3 Rational(“7/-3_”) => ArgumentError
“7/3_”.to_r => 7/3 Rational(“7/3_”) => ArgumentError

e\$B5!3#E*\$KLVMe\$7\$h\$&\$H\$7\$?\$1\$I!"\$J\$+\$J\$+Fq\$7\$/\$F;[email protected]\$1!#e(B

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

|e\$BJ}?K\$,\$h\$/\$o\$+\$i\$J\$/\$J\$C\$F\$-\$?\$s\$G\$9\$,!"e(Bruby e\$B\$N;[email protected]\$K9g\$;\$k\$H\$+e(B?

e\$B\$=\$&\$G\$9!#e(B

e\$B0l1~3NG’\$7\$^\$9!#e(BFloat(“9.e1”) e\$B\$b%(%i!<\$G\$9\$h\$M!)e(B

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

In message “Re: [ruby-dev:29110] Re: rational 1.12”
on Sat, 22 Jul 2006 07:47:48 +0900, Shin-ichiro HARA
[email protected] writes:

|e\$B0l1~3NG’\$7\$^\$9!#e(BFloat(“9.e1”) e\$B\$b%(%i!<\$G\$9\$h\$M!)e(B

e\$B\$=\$&\$G\$9!#e(B