Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix the indent in bigdecimal.

  • Loading branch information...
commit 39f68e110f943b5f8a04cbed3c982783730987de 1 parent 5d497ad
@Watson1978 Watson1978 authored
View
22 ext/bigdecimal/lib/bigdecimal/jacobian.rb
@@ -26,13 +26,13 @@ def isEqual(a,b,zero=0.0,e=1.0e-8)
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 @@ def dfdxi(f,fx,x,i)
s = f.zero
deriv = []
if(nRetry>100) then
- raize "Singular Jacobian matrix. No change at x[" + i.to_s + "]"
+ raize "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 @@ def jacobian(f,fx,x)
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
dfdx
View
40 ext/bigdecimal/lib/bigdecimal/ludcmp.rb
@@ -12,24 +12,24 @@ def ludecomp(a,n,zero=0,one=1)
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)
- else
- raise "Singular matrix"
+ scales <<= one.div(nrmrow,prec)
+ else
+ 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 @@ def ludecomp(a,n,zero=0,one=1)
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 @@ def lusolve(a,b,ps,zero=0.0)
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
end
View
4 ext/bigdecimal/lib/bigdecimal/newton.rb
@@ -1,5 +1,5 @@
#
-# newton.rb
+# newton.rb
#
# Solves the nonlinear algebraic equation system f = 0 by Newton's method.
# This program is not dependent on BigDecimal.
@@ -28,7 +28,7 @@
module Newton
include LUSolve
include Jacobian
-
+
def norm(fv,zero=0.0)
s = zero
n = fv.size
View
42 ext/bigdecimal/lib/bigdecimal/util.rb
@@ -31,35 +31,35 @@ 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
# Converts a BigDecimal to a Rational.
- def to_r
- sign,digits,base,power = self.split
- numerator = sign*digits.to_i
- denomi_power = power - digits.size # base is always 10
- if denomi_power < 0
- Rational(numerator,base ** (-denomi_power))
- else
- Rational(numerator * (base ** denomi_power),1)
- end
+ def to_r
+ sign,digits,base,power = self.split
+ numerator = sign*digits.to_i
+ denomi_power = power - digits.size # base is always 10
+ if denomi_power < 0
+ Rational(numerator,base ** (-denomi_power))
+ else
+ Rational(numerator * (base ** denomi_power),1)
+ 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
Please sign in to comment.
Something went wrong with that request. Please try again.