summaryrefslogtreecommitdiff
path: root/lib/mathn.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mathn.rb')
-rw-r--r--lib/mathn.rb26
1 files changed, 13 insertions, 13 deletions
diff --git a/lib/mathn.rb b/lib/mathn.rb
index 0241f578e9..57eac113c7 100644
--- a/lib/mathn.rb
+++ b/lib/mathn.rb
@@ -1,12 +1,12 @@
#
-# mathn.rb -
+# mathn.rb -
# $Release Version: 0.5 $
# $Revision: 1.1.1.1.4.1 $
# by Keiju ISHITSUKA(SHL Japan Inc.)
#
# --
#
-#
+#
#
require "cmath.rb"
@@ -66,14 +66,14 @@ class Rational
elsif self == 1
return Rational(1,1)
end
-
+
npd = numerator.prime_division
dpd = denominator.prime_division
if other < 0
other = -other
npd, dpd = dpd, npd
end
-
+
for elm in npd
elm[1] = elm[1] * other
if !elm[1].kind_of?(Integer) and elm[1].denominator != 1
@@ -81,7 +81,7 @@ class Rational
end
elm[1] = elm[1].to_i
end
-
+
for elm in dpd
elm[1] = elm[1] * other
if !elm[1].kind_of?(Integer) and elm[1].denominator != 1
@@ -89,12 +89,12 @@ class Rational
end
elm[1] = elm[1].to_i
end
-
+
num = Integer.from_prime_division(npd)
den = Integer.from_prime_division(dpd)
-
+
Rational(num,den)
-
+
elsif other.kind_of?(Integer)
if other > 0
num = numerator ** other
@@ -129,7 +129,7 @@ module Math
# if !(x.kind_of?(Rational) and y.kind_of?(Rational))
# return a**Rational(1,2)
# end
- if a.imag >= 0
+ if a.imag >= 0
Complex(x, y)
else
Complex(x, -y)
@@ -142,7 +142,7 @@ module Math
Complex(0,rsqrt(-a))
end
end
-
+
def rsqrt(a)
if a.kind_of?(Float)
sqrt!(a)
@@ -156,7 +156,7 @@ module Math
while (src >= max) and (src >>= 32)
byte_a.unshift src & 0xffffffff
end
-
+
answer = 0
main = 0
side = 0
@@ -166,13 +166,13 @@ module Math
if answer != 0
if main * 4 < side * side
applo = main.div(side)
- else
+ else
applo = ((sqrt!(side * side + 4 * main) - side)/2.0).to_i + 1
end
else
applo = sqrt!(main).to_i + 1
end
-
+
while (x = (side + applo) * applo) > main
applo -= 1
end