# Rational 1.01

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

rational 1.01 e\$B\$r%Q%C%1!<%8\$7\$^\$7\$?!#e(B

e\$B\$KCV\$\$\$F\$"\$j\$^\$9!#e(B

e\$B:#;W\$\$=P\$7\$?\$N\$G\$9\$,!"e(Brational.c e\$B\$O!"85!9\$ON)@P\$5\$s\$Ne(B
frac ([ruby-list:11907],1999) e\$B\$r;29M\$K\$7\$F:n\$C\$?\$H\$\$\$&\$3\$He(B
e\$B\$G\$9!#\$40U8+\$rJ9\$/\$Y\$-\$G\$7\$?\$M!#\$9\$\$\$^\$;\$s!dN)@P\$5\$s!#e(B

rational.c e\$B\$N<g\$JJQ99E@!Je(B1.00 → 1.01e\$B!K\$O!'e(B

• Rational#to_f e\$B\$N%P%0e(B([ruby-dev:28530])e\$B\$rD>\$7\$?!#e(B
• Float#to_r e\$B\$r!Ve(BRATIONALe\$B4X?t!W\$H\$7\$F<BAu\$7\$?!#e(B
• Float#rationalize e\$B\$r!Ve(BRATIONALIZEe\$B4X?t!W\$H\$7\$F<BAu\$7\$?!#e(B
• Float.decode e\$B\$r<BAu\$7\$?!#e(B
• e\$B@0?t\$G\$"\$ke(B Rational e\$B\$Ne(B inspect e\$B\$KJ,Jle(B 1
e\$B\$r\$D\$1\$?!#e(B

e\$B\$3\$3\$G8@\$&!J\$3\$3\$G\$7\$+8@\$o\$J\$\$!)!K!Ve(BRATIONALe\$B4X?t!W\$H\$O!">.?te(B
e\$B!J\$NFbItI=8=!K\$NM-M}?t2=\$rI=\$9!J35G0>e\$N!K4X?t\$G!"e(B
RATIONAL(1.1) e\$B\$O!"5!3#\$K0MB8\$7\$^\$9\$,!"Nc\$(\$Pe(B
2476979795053773/2251799813685248 e\$B\$K\$J\$j\$^\$9!#e(B

e\$B\$^\$?!“!Ve(BRATIONALIZEe\$B4X?t!W\$H\$O!”\$=\$NCM\$re(B to_f
e\$B\$7\$F85\$N>.?t\$Ke(B
e\$BLa\$kCf\$G:G\$bJ,;RJ,Jl\$N>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~\$l\$kI,MW\$,\$"\$C\$FLLE]!#e(B

(3)e\$B\$O!“e(B1.1.to_r e\$B\$,e(B rational(1.1)
e\$B\$G\$”\$k\$J\$i!"L5\$\$\$+\$J!#e(B

e\$B\$I\$&;W\$\$\$^\$9!)e(B

e\$B\$A\$J\$\$Ke(B Rationalize() e\$B4X?t\$bMQ0U\$7\$F\$\$\$F!“e(BRatinalize(“1.1”)
e\$B\$O!”\$b\$A\$m\$se(B 11/10 e\$B\$J\$N\$G\$9\$,!"\$3\$l\$O!“e(BRATIONALIZE(1.1)
e\$B\$r7We(B
e\$B;;\$7\$F\$\$\$k\$N\$+!“FH<+\$N%Q!<%:\$r\$7\$F\$=\$&\$J\$C\$F\$\$\$k\$N\$+!”\$I\$C\$Ae(B
e\$B\$J\$s\$@\$H\$\$\$&LdBj\$b\$”\$j\$^\$9!#8=:
\$O8e<T\$G\$9!#e(B

e\$B\$d\$d\$3\$7\$\$\$J\$"!#e(B

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

rational.c e\$B\$N<g\$JJQ99E@!Je(B1.00 -> 1.01e\$B!K\$O!'e(B

e\$B<c43\$N:.Mp\$HM}2r\$NAj0c\$,\$"\$k\$h\$&\$G\$9!#e(B[ruby-dev:28509]
e\$B\$G8@\$C\$?\$3\$H\$Ge(B
e\$B\$9\$,!"e(B

e\$B86\$5\$s\$Ne(B rational e\$B\$O!"e(Br.divmod(1) e\$B\$,e(B [-3, -1/4] e\$B\$K\$J\$j\$^\$9e(B (div e\$B\$He(B %e\$B\$be(B)e\$B!#e(B

e\$B\$H\$\$\$&\$N\$O!"KM\$O%P%0\$@\$HG’<1\$7\$F\$\$\$?\$N\$G\$9\$,!#e(B

e\$B\$G!"e(BRational(aFloat) e\$B\$N%P%0!“e(BFloat#decode
e\$B\$N<BAu!”\$G\$9\$+\$M!#e(B

e\$B\$=\$l\$+\$i!“EAE}E*\$Je(B C
e\$B9=J8\$G\$J\$\$\$H\$3\$m\$,\$”\$k\$N\$G!"\$&\$A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G\$9!#!Ke(B

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

Rationalize(Rational(0.3), 0.1) => 5404319552844595/18014398509481984

e\$B\$3\$l\$,\$*\$+\$7\$\$\$H;W\$\$\$^\$9!#e(B

e\$BJdB-\$G\$9!#e(BRationalize e\$B\$O!"e(BCommon Lisp e\$B\$Ne(B rationalize
e\$B\$He(B Scheme e\$B\$N\$=\$le(B
e\$B\$r9g\$;\$?\$h\$&\$J46\$8\$K\$J\$C\$F\$\$\$k\$H;W\$\$\$^\$9!#e(B

e\$B8=>u\$NB’\$7\$F\$\$\$(\$P!“e(BaRational.rationalize
e\$B\$,0z?t\$r<h\$l\$J\$\$\$N\$G\$”\$l\$P!“e(B
Rationalize e\$B\$bF1MM\$G\$”\$k\$Y\$-\$G!"e(BRationalize(aRational…)
e\$B\$N>l9g!“BhFse(B
e\$B0z?t\$r\$H\$l\$k\$N\$O\$*\$+\$7\$\$!”\$H\$\$\$&\$3\$H\$K\$J\$k\$H;W\$\$\$^\$9!#e(B

e\$B\$?\$@!“BhFs0z?t\$r<u\$1\$H\$k\$3\$H\$,\$G\$-\$F!”\$=\$l\$K4p\$\$\$FC1=c2=\$G\$-\$k\$N\$G!“Bhe(B
e\$BFs0z?t\$,\$”\$k>l9g\$O!"\$=\$&\$7\$F\$h\$\$\$H;W\$\$\$^\$9!#e(BaRational.rationalize
e\$B\$b0ze(B
e\$B?t\$r<h\$C\$F\$h\$\$\$H;W\$\$\$^\$9!#KM\$H\$7\$F\$O!"\$=\$&\$\$\$&\$b\$N\$@\$m\$&!"\$H;W\$C\$F\$\$\$?e(B
e\$B\$N\$G\$9\$,!"\$I\$&\$G\$7\$g\$&!#e(B

e\$B\$"\$H!"\$D\$\$\$G\$G\$9\$,!"e(B Rational#- e\$B\$N7k2L\$,\$*\$+\$7\$\$\$G\$9!#e(B

Rational(1,2) - 0.5 => 1.0

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

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

e\$B;n\$7\$^\$7\$?!#Nc\$N%P%0\$OD>\$C\$?\$h\$&\$G\$9\$,!"\$^\$@J8\$N\$J\$+\$K@k8@\$,:.\$C\$F\$k\$se(B
e\$B\$G!"\$3\$l\$,\$^\$:\$\$\$H;W\$\$\$^\$9e(B (e\$B%G%P%C%0MQ\$N%3!<%I\$be(B)e\$B!#e(B

e\$B\$9\$\$\$^\$;\$s!#\$;\$C\$+\$/%Q%C%A\$G;XE&\$7\$F\$\$\$?\$@\$\$\$?\$N\$K!"8eH>H>J,\$re(B
e\$B8+Mn\$H\$7\$^\$7\$?!#e(B

e\$B\$=\$l\$H!"e(B

Rationalize(Rational(0.3), 0.1) => 5404319552844595/18014398509481984

e\$B\$3\$l\$,\$*\$+\$7\$\$\$H;W\$\$\$^\$9!#e(B

e\$BM-M}?t\$re(B Rationalize
e\$B\$9\$k\$N\$O\$*\$+\$7\$\$\$H;W\$C\$?\$N\$G!"AGDL\$7\$5\$;\$?\$N\$Ge(B
e\$B\$9\$,!“Bh#20z?t\$K@:EY\$r;XDj\$9\$l\$P0UL#\$,\$”\$k\$N\$G!"e(B

Rational(0.3).rationalize(0.1) => 1/3

e\$B\$H\$J\$k\$h\$&\$K\$7\$^\$7\$?!#\$?\$@\$70z?t\$,\$J\$\$\$H!"e(B

Rational(0.3).rationalize => 5404319552844595/18014398509481984

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

e\$B\$5\$i\$K!"e(B0.3.rationalize(0.1) e\$B\$,2DG=\$J\$i!“e(B0.3.to_r.rationalize(0.1) e\$B\$be(B
e\$B2DG=\$G\$”\$C\$F\$h\$\$5\$\$,\$7\$^\$9\$7!“e(B"3e-33”.rationalize(0.1) e\$B\$H\$G\$-\$F\$b\$\$\$\$e(B
e\$B\$N\$+\$b\$7\$l\$^\$;\$s!#e(B

e\$B\$=\$&\$G\$9\$M!#A4\$F\$Ne(B rationalize
e\$B%a%=%C%I\$O!"0z?t\$r;}\$D\$h\$&\$K\$7\$^\$7\$?!#e(B

e\$B0J>e\$rA0Ds\$K!“4X?t\$H\$7\$F\$Ne(B Rationalize e\$B\$O\$J\$/\$7\$F\$b\$\$\$\$!”\$H;W\$\$\$^\$9!#e(B
e\$B\$3\$N\$?\$a\$K!"e(BKernel e\$B6u4V\$r\$D\$+\$o\$J\$/\$F\$b\$\$\$\$\$h\$&\$J5\$\$,\$9\$k\$o\$1\$G\$9!#e(B

e\$B3N\$+\$Ke(B Rationalize e\$B\$H\$\$\$&%/%i%9\$,\$J\$\$\$N\$Ke(B Rationalize()
e\$B4X?t\$,\$“e(B
e\$B\$k\$H\$\$\$&\$N\$bJQ\$J\$N\$G!”\$J\$/\$7\$^\$7\$?!#e(B

e\$BJdB-\$G\$9!#e(BRationalize e\$B\$O!"e(BCommon Lisp e\$B\$Ne(B rationalize e\$B\$He(B Scheme e\$B\$N\$=\$le(B
e\$B\$r9g\$;\$?\$h\$&\$J46\$8\$K\$J\$C\$F\$\$\$k\$H;W\$\$\$^\$9!#e(B

Scheme e\$B\$K\$Oe(B rationalize->exact
e\$B\$H\$\$\$&\$N\$b\$"\$j\$^\$9\$M!#\$\$\$:\$l\$K\$7\$Fe(B
e\$B\$bM-M}?t\$re(B rationalize
approxRational e\$B\$H\$\$\$&L>A0\$,E,Ev\$+\$b\$7\$l\$J\$\$!#Bh#20z?t\$r<h\$i\$J\$\$e(B
Common Lisp e\$B\$Ne(B rationalize e\$B\$OG<F@\$G\$-\$^\$9!#e(B

e\$B8=>u\$NB’\$7\$F\$\$\$(\$P!“e(BaRational.rationalize e\$B\$,0z?t\$r<h\$l\$J\$\$\$N\$G\$”\$l\$P!“e(B
Rationalize e\$B\$bF1MM\$G\$”\$k\$Y\$-\$G!"e(BRationalize(aRational…) e\$B\$N>l9g!“BhFse(B
e\$B0z?t\$r\$H\$l\$k\$N\$O\$*\$+\$7\$\$!”\$H\$\$\$&\$3\$H\$K\$J\$k\$H;W\$\$\$^\$9!#e(B

e\$B\$?\$@!“BhFs0z?t\$r<u\$1\$H\$k\$3\$H\$,\$G\$-\$F!”\$=\$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F!"e(BHaskell e\$B\$Ne(B
approxRational e\$B\$H\$\$\$&L>A0\$,E,Ev\$+\$b\$7\$l\$J\$\$!#Bh#20z?t\$r<h\$i\$J\$\$e(B
Common Lisp e\$B\$Ne(B rationalize e\$B\$OG<F@\$G\$-\$^\$9!#e(B

rationalize->exact e\$B\$O!“e(BMIT Scheme
e\$B\$N3HD%\$_\$?\$\$\$G\$9\$,!”\$I\$A\$i\$+\$H\$\$\$&\$H!"e(B
e\$B\$3\$C\$A\$K6a\$\$\$s\$G\$7\$g\$&\$M!#e(B

e\$BL>A0\$,%X%s\$8\$c\$J\$\$\$+\$H\$\$\$&\$N\$O!"\$=\$&\$J\$N\$+\$J!"\$H\$\$\$&\$N\$O\$"\$j\$^\$9\$,!"e(B
Common Lisp e\$B\$K\$7\$F\$b!"M-M}?t\$r<u\$1\$H\$j\$^\$9\$7!"e(BScheme
e\$B\$G\$O!"Hs87L)?t\$re(B
e\$B\$D\$+\$C\$?7W;;\$O86B’E*\$KHs87L)?t\$rJV\$9\$3\$H\$K\$J\$k\$N\$G!“M-M}?t\$,JV\$k\$H\$O8Be(B
e\$B\$i\$J\$\$\$o\$1\$G!#\$7\$+\$7!”\$d\$C\$Q\$je(B approxRational
e\$B\$_\$?\$\$\$J\$N\$,\$\$\$\$\$s\$G\$9\$+e(B
e\$B\$M!#e(B

e\$B\$H\$3\$m\$G!"e(BScheme e\$B\$Ne(B inexact->exact e\$B\$be(B Haskell e\$B\$Ne(B
approxRational e\$B\$bBhFse(B
e\$B0z?t\$OIi?t\$G\$b9=\$o\$J\$\$\$h\$&\$G\$9!#\$J\$N\$G!“FCJL\$JM}M3\$,\$J\$1\$l\$P!”\$=\$&\$7\$Fe(B
e\$B\$b\$\$\$\$\$+\$J\$H;W\$\$\$^\$7\$?!#e(B

e\$B\$"\$H!"e(Brationalize
e\$BCf\$NF1CMH=Dj\$,\$*\$+\$7\$\$\$h\$&\$K;W\$&\$N\$G\$9\$,!"3NG’\$r\$*4je(B
e\$B\$\$\$7\$^\$9!#e(B

— rational.c.orig Tue Apr 18 20:28:12 2006
+++ rational.c Sat Apr 22 23:56:21 2006
@@ -478,5 +478,5 @@
return RT_NEW2(RT_MINUS(snum, RT_MUL(other, sden)), sden);
case T_FLOAT:

• ``````   return RT_PLUS(rb_rat_to_f(self), RT_UMINUS(other));
``````
• ``````   return RT_MINUS(rb_rat_to_f(self), other);
``````

default:
@@ -942,5 +942,5 @@

`````` if (RT_NEG(eps)) {
``````
• ``````   rb_raise(rb_eArgError, "precision is negative.");
``````
• eps = RT_UMINUS(eps);
}

@@ -962,5 +962,5 @@

• `````` if (RT_EQ(xn, xd) && RT_EQ(yn, yd)) {
``````
• `````` if (RT_EQ(xn, yn) && RT_EQ(xd, yd)) {
return x;
}
``````

@@ -1359,5 +1359,5 @@

``````   if (RT_NEG(eps)) {
``````
• ``````   rb_raise(rb_eArgError, "precision is negative.");
``````
• eps = RT_UMINUS(eps);
}

@@ -1601,5 +1601,5 @@

``````   if (RT_NEG(eps)) {
``````
• ``````   rb_raise(rb_eArgError, "precision is negative.");
``````
• eps = RT_UMINUS(eps);
}

@@ -1614,5 +1614,5 @@

• `````` if (RT_EQ(xn, xd) && RT_EQ(yn, yd)) {
``````
• `````` if (RT_EQ(xn, yn) && RT_EQ(xd, yd)) {
return x;
}``````

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

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

e\$B\$\$\$m\$\$\$m\$HDs0F\$,<u\$1\$\$\$l\$i\$l\$F\$&\$l\$7\$\$\$G\$9!#e(B

e\$B\$\$\$(\$\$\$(!"\$3\$A\$i\$3\$=L5NA\$GE::o\$5\$;\$F\$7\$^\$C\$F62=L\$G\$9!#\$"\$j\$,\$H\$&e(B
e\$B\$4\$6\$\$\$^\$9!#e(B

rationalize->exact e\$B\$O!“e(BMIT Scheme e\$B\$N3HD%\$_\$?\$\$\$G\$9\$,!”\$I\$A\$i\$+\$H\$\$\$&\$H!"e(B
e\$B\$3\$C\$A\$K6a\$\$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}\$^\$C\$?\$h\$&\$G\$9!#B>\$N4D6-\$G\$O!"%a%b%je(B
e\$B\$,B-\$j\$J\$/\$F;`\$L\$@\$1\$J\$N\$G!"\$?\$V\$s!"e(B(e\$B\$&\$A\$Ne(B?) FreeBSD e\$B\$,\$
\$+\$7\$\$\$N\$@\$He(B
e\$B;W\$\$\$^\$9\$,!#e(B

e\$B2DG=\$J\$i\$P\$=\$N:9J,\$rAw\$C\$F\$\$\$?\$@\$1\$k\$H=u\$+\$k\$N\$G\$9\$,!#e(B(^^;;

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

``````rat = Data_Make_Struct(klass, struct RRational,
``````
• ``````                      rb_rat_mark, rb_rat_finalizer, r);
``````
• ``````                      rb_rat_mark, -1, r);
``````
r->num = num;
r->den = den;

e\$B\$"\$j\$,\$H\$&\$4\$6\$\$\$^\$7\$?!#\$=\$N\$^\$^e(B1.0.8e\$B\$K<h\$j9~\$^\$;\$F\$b\$i\$\$\$^\$7e(B
e\$B\$?!#e(B

In article 6.2.3.4.2.20060516180507.05621c90@localhost,
Shin-ichiro HARA [email protected] writes:

``````rat = Data_Make_Struct(klass, struct RRational,
``````
• ``````                      rb_rat_mark, rb_rat_finalizer, r);
``````
• ``````                      rb_rat_mark, -1, r);
``````
r->num = num;
r->den = den;

e\$B\$”\$j\$,\$H\$&\$4\$6\$\$\$^\$7\$?!#\$=\$N\$^\$^e(B1.0.8e\$B\$K<h\$j9~\$^\$;\$F\$b\$i\$\$\$^\$7e(B
e\$B\$?!#e(B

e\$B;W\$C\$?\$s\$G\$9\$,!“J,;R\$HJ,Jl\$H\$\$\$&\$U\$?\$D\$N%U%#!<%k%I\$7\$+\$J\$\$\$Ne(B
e\$B\$G\$”\$l\$P!"e(BRObject e\$B\$KKd\$a9~\$a\$k\$O\$:\$G!"3+J|\$9\$kI,MW@-\$H\$\$\$&0Je(B
e\$BA0\$K30\$KNN0h\$r3NJ]\$9\$k\$N\$O%a%b\$j\$NL5BL\$@\$H;W\$\$\$^\$9!#e(B

e\$B\$=\$l\$r9M\$(\$k\$H!"e(BStruct e\$B\$r;H\$&\$He(B (1.9 e\$B\$G\$Oe(B)
e\$B%a%b%j\$r@aLs\$G\$-e(B
e\$B\$k\$N\$G\$O\$J\$\$\$+\$H\$\$\$&5\$\$,\$7\$^\$9!#e(B

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

e\$B\$&\$A\$G\$O\$3\$&\$7\$?\$@\$1\$G\$9\$1\$I!#e(B

— rational.c.orig Sun Apr 23 03:14:07 2006
+++ rational.c Sat May 13 14:30:31 2006
@@ -138,7 +138,7 @@
struct RRational *r;

`````` rat = Data_Make_Struct(klass, struct RRational,
``````
• ``````                      rb_rat_mark, rb_rat_finalizer, r);
``````
• ``````                      rb_rat_mark, -1, r);
``````
r->num = num;
r->den = den;