summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/mathn.rb7
-rw-r--r--lib/rational.rb6
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/mathn.rb b/lib/mathn.rb
index 19325f299..ddfca5768 100644
--- a/lib/mathn.rb
+++ b/lib/mathn.rb
@@ -116,17 +116,22 @@ class Prime
end
class Fixnum
+ remove_method :/
alias / quo
+ alias_method :/, :quo
+ p :fixdiv
+ p [[:fixdiv, 1.div(1)]]
end
class Bignum
+ remove_method :/
alias / quo
end
class Rational
Unify = true
- remove_method(:inspect)
+ remove_method :inspect
def inspect
format "%s/%s", numerator.inspect, denominator.inspect
end
diff --git a/lib/rational.rb b/lib/rational.rb
index 224100485..f4570bd30 100644
--- a/lib/rational.rb
+++ b/lib/rational.rb
@@ -37,6 +37,7 @@
#
def Rational(a, b = 1)
+ p [:Rational, a, b]
if a.kind_of?(Rational) && b == 1
a
else
@@ -54,9 +55,13 @@ class Rational < Numeric
num = -num
den = -den
end
+ p [:reduce, num, den]
gcd = num.gcd(den)
+ p [:div1, num, num.class, gcd]
num = num.div(gcd)
+ p [:div2, den, gcd]
den = den.div(gcd)
+ p [:gcd=, gcd]
if den == 1 && defined?(Unify)
num
else
@@ -333,6 +338,7 @@ end
class Fixnum
undef quo
def quo(other)
+ p [:quo, self, other]
Rational.new!(self,1) / other
end
alias rdiv quo