summaryrefslogtreecommitdiff log msg author committer range
path: root/ext/bigdecimal/lib
diff options
 context: 12345678910152025303540 space: includeignore mode: unifiedssdiffstat only
Diffstat (limited to 'ext/bigdecimal/lib')
-rw-r--r--ext/bigdecimal/lib/bigdecimal/jacobian.rb22
-rw-r--r--ext/bigdecimal/lib/bigdecimal/ludcmp.rb38
-rw-r--r--ext/bigdecimal/lib/bigdecimal/util.rb24
3 files changed, 42 insertions, 42 deletions
 diff --git a/ext/bigdecimal/lib/bigdecimal/jacobian.rb b/ext/bigdecimal/lib/bigdecimal/jacobian.rbindex 8c36ad1..8d8d583 100644--- a/ext/bigdecimal/lib/bigdecimal/jacobian.rb+++ b/ext/bigdecimal/lib/bigdecimal/jacobian.rb@@ -26,13 +26,13 @@ module Jacobian aa = a.abs bb = b.abs if aa == zero && bb == zero then- true+ true else- if ((a-b)/(aa+bb)).abs < e then- true- else- false- end+ if ((a-b)/(aa+bb)).abs < e then+ true+ else+ false+ end end end #++@@ -52,17 +52,17 @@ module Jacobian s = f.zero deriv = [] if(nRetry>100) then- raise "Singular Jacobian matrix. No change at x[" + i.to_s + "]"+ raise "Singular Jacobian matrix. No change at x[" + i.to_s + "]" end dx = dx*f.two x[i] += dx fxNew = f.values(x) for j in 0...n do if !isEqual(fxNew[j],fx[j],f.zero,f.eps) then- ok += 1- deriv <<= (fxNew[j]-fx[j])/dx+ ok += 1+ deriv <<= (fxNew[j]-fx[j])/dx else- deriv <<= f.zero+ deriv <<= f.zero end end x[i] = xSave@@ -77,7 +77,7 @@ module Jacobian for i in 0...n do df = dfdxi(f,fx,x,i) for j in 0...n do- dfdx[j*n+i] = df[j]+ dfdx[j*n+i] = df[j] end end dfdxdiff --git a/ext/bigdecimal/lib/bigdecimal/ludcmp.rb b/ext/bigdecimal/lib/bigdecimal/ludcmp.rbindex 176ed84..e18446d 100644--- a/ext/bigdecimal/lib/bigdecimal/ludcmp.rb+++ b/ext/bigdecimal/lib/bigdecimal/ludcmp.rb@@ -12,24 +12,24 @@ module LUSolve nrmrow = zero ixn = i*n for j in 0...n do- biggst = a[ixn+j].abs- nrmrow = biggst if biggst>nrmrow+ biggst = a[ixn+j].abs+ nrmrow = biggst if biggst>nrmrow end if nrmrow>zero then- scales <<= one.div(nrmrow,prec)+ scales <<= one.div(nrmrow,prec) else- raise "Singular matrix"+ raise "Singular matrix" end end n1 = n - 1 for k in 0...n1 do # Gaussian elimination with partial pivoting. biggst = zero; for i in k...n do- size = a[ps[i]*n+k].abs*scales[ps[i]]- if size>biggst then- biggst = size- pividx = i- end+ size = a[ps[i]*n+k].abs*scales[ps[i]]+ if size>biggst then+ biggst = size+ pividx = i+ end end raise "Singular matrix" if biggst<=zero if pividx!=k then@@ -42,10 +42,10 @@ module LUSolve psin = ps[i]*n 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.mult(a[pskn+j],prec)- end+ pskn = ps[k]*n+ for j in (k+1)...n do+ a[psin+j] -= mult.mult(a[pskn+j],prec)+ end end end end@@ -72,12 +72,12 @@ module LUSolve x <<= b[ps[i]] - dot end (n-1).downto(0) do |i|- dot = zero- psin = ps[i]*n- for j in (i+1)...n do- dot = a[psin+j].mult(x[j],prec) + dot- end- x[i] = (x[i]-dot).div(a[psin+i],prec)+ dot = zero+ psin = ps[i]*n+ for j in (i+1)...n do+ dot = a[psin+j].mult(x[j],prec) + dot+ end+ x[i] = (x[i]-dot).div(a[psin+i],prec) end x enddiff --git a/ext/bigdecimal/lib/bigdecimal/util.rb b/ext/bigdecimal/lib/bigdecimal/util.rbindex 257781f..4742664 100644--- a/ext/bigdecimal/lib/bigdecimal/util.rb+++ b/ext/bigdecimal/lib/bigdecimal/util.rb@@ -31,23 +31,23 @@ class BigDecimal < Numeric # Converts a BigDecimal to a String of the form "nnnnnn.mmm". # This method is deprecated; use BigDecimal#to_s("F") instead. def to_digits- if self.nan? || self.infinite? || self.zero?- self.to_s- else- i = self.to_i.to_s- s,f,y,z = self.frac.split- i + "." + ("0"*(-z)) + f- end+ if self.nan? || self.infinite? || self.zero?+ self.to_s+ else+ i = self.to_i.to_s+ s,f,y,z = self.frac.split+ i + "." + ("0"*(-z)) + f+ end end end class Rational < Numeric # Converts a Rational to a BigDecimal def to_d(nFig=0)- num = self.numerator.to_s- if nFig<=0- nFig = BigDecimal.double_fig*2+1- end- BigDecimal.new(num).div(self.denominator,nFig)+ num = self.numerator.to_s+ if nFig<=0+ nFig = BigDecimal.double_fig*2+1+ end+ BigDecimal.new(num).div(self.denominator,nFig) end end