diff options
| author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-03-06 03:56:38 +0000 |
|---|---|---|
| committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-03-06 03:56:38 +0000 |
| commit | d17d1b111341f2c8979cf8fbd63ec7ec9db7c3ad (patch) | |
| tree | 5e35d5b41aae961b37cf6632f60c42f51c7aa775 /lib/mathn.rb | |
| parent | 101e79d7b434c01c0e6f4bcc480003858ab8e1a4 (diff) | |
| download | ruby-d17d1b111341f2c8979cf8fbd63ec7ec9db7c3ad.tar.gz ruby-d17d1b111341f2c8979cf8fbd63ec7ec9db7c3ad.tar.xz ruby-d17d1b111341f2c8979cf8fbd63ec7ec9db7c3ad.zip | |
* {ext,lib,test}/**/*.rb: removed trailing spaces.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@22784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/mathn.rb')
| -rw-r--r-- | lib/mathn.rb | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/lib/mathn.rb b/lib/mathn.rb index 0241f578e..57eac113c 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 |
