summaryrefslogtreecommitdiff
path: root/ext/bigdecimal/lib
diff options
context:
space:
mode:
authorshigek <shigek@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-08-29 13:33:37 +0000
committershigek <shigek@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-08-29 13:33:37 +0000
commit38b9eb1674afbff4517f082413ba6c7acbf8beff (patch)
treea17ad832429fe1842666ff905db6bcb35caa6c5c /ext/bigdecimal/lib
parent1ea6c0aa9bb66b5876cb3a74f49f0cd2759ba493 (diff)
mult & div instead of * & /.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4459 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal/lib')
-rw-r--r--ext/bigdecimal/lib/bigdecimal/ludcmp.rb16
1 files changed, 9 insertions, 7 deletions
diff --git a/ext/bigdecimal/lib/bigdecimal/ludcmp.rb b/ext/bigdecimal/lib/bigdecimal/ludcmp.rb
index c36f0de..1d5d317 100644
--- a/ext/bigdecimal/lib/bigdecimal/ludcmp.rb
+++ b/ext/bigdecimal/lib/bigdecimal/ludcmp.rb
@@ -2,7 +2,8 @@
# ludcmp.rb
#
module LUSolve
- def ludecomp(a,n,zero=0.0,one=1.0)
+ def ludecomp(a,n,zero=0,one=1)
+ prec = BigDecimal.limit(nil)
ps = []
scales = []
for i in 0...n do # pick up largest(abs. val.) element in each row.
@@ -14,7 +15,7 @@ module LUSolve
nrmrow = biggst if biggst>nrmrow
end
if nrmrow>zero then
- scales <<= one/nrmrow
+ scales <<= one.div(nrmrow,prec)
else
raise "Singular matrix"
end
@@ -38,11 +39,11 @@ module LUSolve
pivot = a[ps[k]*n+k]
for i in (k+1)...n do
psin = ps[i]*n
- a[psin+k] = mult = a[psin+k]/pivot
+ a[psin+k] = mult = a[psin+k].div(pivot,prec)
if mult!=zero then
pskn = ps[k]*n
for j in (k+1)...n do
- a[psin+j] -= mult*a[pskn+j]
+ a[psin+j] -= mult.mult(a[pskn+j],prec)
end
end
end
@@ -52,13 +53,14 @@ module LUSolve
end
def lusolve(a,b,ps,zero=0.0)
+ prec = BigDecimal.limit(nil)
n = ps.size
x = []
for i in 0...n do
dot = zero
psin = ps[i]*n
for j in 0...i do
- dot = a[psin+j]*x[j] + dot
+ dot = a[psin+j].mult(x[j],prec) + dot
end
x <<= b[ps[i]] - dot
end
@@ -66,9 +68,9 @@ module LUSolve
dot = zero
psin = ps[i]*n
for j in (i+1)...n do
- dot = a[psin+j]*x[j] + dot
+ dot = a[psin+j].mult(x[j],prec) + dot
end
- x[i] = (x[i]-dot)/a[psin+i]
+ x[i] = (x[i]-dot).div(a[psin+i],prec)
end
x
end