bigdecimal 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,15 @@
1
1
  # -*- ruby -*-
2
- _VERSION = "1.1.0"
2
+ _VERSION = "1.2.0"
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "bigdecimal"
6
6
  s.version = _VERSION
7
- s.date = "2011-07-30"
7
+ s.date = "2012-02-19"
8
8
  s.summary = "Arbitrary-precision decimal floating-point number library."
9
9
  s.homepage = "http://www.ruby-lang.org"
10
10
  s.email = "mrkn@mrkn.jp"
11
11
  s.description = "This library provides arbitrary-precision decimal floating-point number class."
12
- s.authors = ["Kenta Murata", "Shigeo Kobayashi"]
12
+ s.authors = ["Kenta Murata", "Zachary Scott", "Shigeo Kobayashi"]
13
13
  s.require_path = %[.]
14
14
  s.files = %w[
15
15
  bigdecimal.gemspec
@@ -97,7 +97,7 @@ extern VALUE rb_cBigDecimal;
97
97
  #define VP_EXCEPTION_OVERFLOW ((unsigned short)0x0001) /* 0x0008) */
98
98
  #define VP_EXCEPTION_ZERODIVIDE ((unsigned short)0x0010)
99
99
 
100
- /* Following 2 exceptions cann't controlled by user */
100
+ /* Following 2 exceptions can't controlled by user */
101
101
  #define VP_EXCEPTION_OP ((unsigned short)0x0020)
102
102
  #define VP_EXCEPTION_MEMORY ((unsigned short)0x0040)
103
103
 
data/depend CHANGED
@@ -1 +1 @@
1
- bigdecimal.o: bigdecimal.c bigdecimal.h $(hdrdir)/ruby.h
1
+ bigdecimal.o: bigdecimal.c bigdecimal.h $(HDRS) $(ruby_headers)
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # f.zero:: returns 0.0
13
13
  # f.one:: returns 1.0
14
- # f.two:: returns 1.0
14
+ # f.two:: returns 2.0
15
15
  # f.ten:: returns 10.0
16
16
  #
17
17
  # f.eps:: returns the convergence criterion (epsilon value) used to determine whether two values are considered equal. If |a-b| < epsilon, the two values are considered equal.
@@ -51,9 +51,9 @@ module Jacobian
51
51
  dx = fx[i].abs/ratio if isEqual(dx,f.zero,f.zero,f.eps)
52
52
  dx = f.one/f.ten if isEqual(dx,f.zero,f.zero,f.eps)
53
53
  until ok>0 do
54
- s = f.zero
55
54
  deriv = []
56
- if(nRetry>100) then
55
+ nRetry += 1
56
+ if nRetry > 100
57
57
  raise "Singular Jacobian matrix. No change at x[" + i.to_s + "]"
58
58
  end
59
59
  dx = dx*f.two
@@ -7,7 +7,6 @@ require 'bigdecimal'
7
7
  # sin (x, prec)
8
8
  # cos (x, prec)
9
9
  # atan(x, prec) Note: |x|<1, x=0.9999 may not converge.
10
- # log (x, prec)
11
10
  # PI (prec)
12
11
  # E (prec) == exp(1.0,prec)
13
12
  #
@@ -21,30 +20,40 @@ require 'bigdecimal'
21
20
  #
22
21
  # Example:
23
22
  #
24
- # require "bigdecimal"
25
23
  # require "bigdecimal/math"
26
24
  #
27
25
  # include BigMath
28
26
  #
29
27
  # a = BigDecimal((PI(100)/2).to_s)
30
- # puts sin(a,100) # -> 0.10000000000000000000......E1
28
+ # puts sin(a,100) # => 0.10000000000000000000......E1
31
29
  #
32
30
  module BigMath
33
31
  module_function
34
32
 
35
- # Computes the square root of x to the specified number of digits of
36
- # precision.
33
+ # call-seq:
34
+ # sqrt(decimal, numeric) -> BigDecimal
37
35
  #
38
- # BigDecimal.new('2').sqrt(16).to_s
39
- # -> "0.14142135623730950488016887242096975E1"
36
+ # Computes the square root of +decimal+ to the specified number of digits of
37
+ # precision, +numeric+.
40
38
  #
41
- def sqrt(x,prec)
39
+ # BigMath::sqrt(BigDecimal.new('2'), 16).to_s
40
+ # #=> "0.14142135623730950488016887242096975E1"
41
+ #
42
+ def sqrt(x, prec)
42
43
  x.sqrt(prec)
43
44
  end
44
45
 
45
- # Computes the sine of x to the specified number of digits of precision.
46
+ # call-seq:
47
+ # sin(decimal, numeric) -> BigDecimal
48
+ #
49
+ # Computes the sine of +decimal+ to the specified number of digits of
50
+ # precision, +numeric+.
51
+ #
52
+ # If +decimal+ is Infinity or NaN, returns NaN.
53
+ #
54
+ # BigMath::sin(BigMath::PI(5)/4, 5).to_s
55
+ # #=> "0.70710678118654752440082036563292800375E0"
46
56
  #
47
- # If x is infinite or NaN, returns NaN.
48
57
  def sin(x, prec)
49
58
  raise ArgumentError, "Zero or negative precision for sin" if prec <= 0
50
59
  return BigDecimal("NaN") if x.infinite? || x.nan?
@@ -78,9 +87,17 @@ module BigMath
78
87
  neg ? -y : y
79
88
  end
80
89
 
81
- # Computes the cosine of x to the specified number of digits of precision.
90
+ # call-seq:
91
+ # cos(decimal, numeric) -> BigDecimal
92
+ #
93
+ # Computes the cosine of +decimal+ to the specified number of digits of
94
+ # precision, +numeric+.
95
+ #
96
+ # If +decimal+ is Infinity or NaN, returns NaN.
97
+ #
98
+ # BigMath::cos(BigMath::PI(4), 16).to_s
99
+ # #=> "-0.999999999999999999999999999999856613163740061349E0"
82
100
  #
83
- # If x is infinite or NaN, returns NaN.
84
101
  def cos(x, prec)
85
102
  raise ArgumentError, "Zero or negative precision for cos" if prec <= 0
86
103
  return BigDecimal("NaN") if x.infinite? || x.nan?
@@ -114,9 +131,17 @@ module BigMath
114
131
  y
115
132
  end
116
133
 
117
- # Computes the arctangent of x to the specified number of digits of precision.
134
+ # call-seq:
135
+ # atan(decimal, numeric) -> BigDecimal
136
+ #
137
+ # Computes the arctangent of +decimal+ to the specified number of digits of
138
+ # precision, +numeric+.
139
+ #
140
+ # If +decimal+ is NaN, returns NaN.
141
+ #
142
+ # BigMath::atan(BigDecimal.new('-1'), 16).to_s
143
+ # #=> "-0.785398163397448309615660845819878471907514682065E0"
118
144
  #
119
- # If x is NaN, returns NaN.
120
145
  def atan(x, prec)
121
146
  raise ArgumentError, "Zero or negative precision for atan" if prec <= 0
122
147
  return BigDecimal("NaN") if x.nan?
@@ -145,7 +170,15 @@ module BigMath
145
170
  y
146
171
  end
147
172
 
148
- # Computes the value of pi to the specified number of digits of precision.
173
+ # call-seq:
174
+ # PI(numeric) -> BigDecimal
175
+ #
176
+ # Computes the value of pi to the specified number of digits of precision,
177
+ # +numeric+.
178
+ #
179
+ # BigMath::PI(10).to_s
180
+ # #=> "0.3141592653589793238462643388813853786957412E1"
181
+ #
149
182
  def PI(prec)
150
183
  raise ArgumentError, "Zero or negative argument for PI" if prec <= 0
151
184
  n = prec + BigDecimal.double_fig
@@ -160,7 +193,6 @@ module BigMath
160
193
 
161
194
  d = one
162
195
  k = one
163
- w = one
164
196
  t = BigDecimal("-80")
165
197
  while d.nonzero? && ((m = n - (pi.exponent - d.exponent).abs) > 0)
166
198
  m = BigDecimal.double_fig if m < BigDecimal.double_fig
@@ -172,7 +204,6 @@ module BigMath
172
204
 
173
205
  d = one
174
206
  k = one
175
- w = one
176
207
  t = BigDecimal("956")
177
208
  while d.nonzero? && ((m = n - (pi.exponent - d.exponent).abs) > 0)
178
209
  m = BigDecimal.double_fig if m < BigDecimal.double_fig
@@ -184,8 +215,15 @@ module BigMath
184
215
  pi
185
216
  end
186
217
 
218
+ # call-seq:
219
+ # E(numeric) -> BigDecimal
220
+ #
187
221
  # Computes e (the base of natural logarithms) to the specified number of
188
- # digits of precision.
222
+ # digits of precision, +numeric+.
223
+ #
224
+ # BigMath::E(10).to_s
225
+ # #=> "0.271828182845904523536028752390026306410273E1"
226
+ #
189
227
  def E(prec)
190
228
  raise ArgumentError, "Zero or negative precision for E" if prec <= 0
191
229
  n = prec + BigDecimal.double_fig
@@ -18,7 +18,7 @@ require "bigdecimal/jacobian"
18
18
  #
19
19
  # f.zero:: returns 0.0
20
20
  # f.one:: returns 1.0
21
- # f.two:: returns 1.0
21
+ # f.two:: returns 2.0
22
22
  # f.ten:: returns 10.0
23
23
  #
24
24
  # f.eps:: returns the convergence criterion (epsilon value) used to determine whether two values are considered equal. If |a-b| < epsilon, the two values are considered equal.
@@ -30,7 +30,7 @@ module Newton
30
30
  include Jacobian
31
31
  module_function
32
32
 
33
- def norm(fv,zero=0.0)
33
+ def norm(fv,zero=0.0) # :nodoc:
34
34
  s = zero
35
35
  n = fv.size
36
36
  for i in 0...n do
@@ -39,6 +39,7 @@ module Newton
39
39
  s
40
40
  end
41
41
 
42
+ # See also Newton
42
43
  def nlsolve(f,x)
43
44
  nRetry = 0
44
45
  n = x.size
@@ -28,7 +28,7 @@ class Float < Numeric
28
28
  # # => #<BigDecimal:1dc69e0,'0.5E0',9(18)>
29
29
  #
30
30
  def to_d(precision=nil)
31
- BigDecimal(self, precision || Float::DIG+1)
31
+ BigDecimal(self, precision || Float::DIG)
32
32
  end
33
33
  end
34
34
 
@@ -10,6 +10,7 @@
10
10
  # ruby linear.rb [input file solved]
11
11
  #
12
12
 
13
+ # :stopdoc:
13
14
  require "bigdecimal"
14
15
  require "bigdecimal/ludcmp"
15
16
 
@@ -9,7 +9,7 @@ require "bigdecimal"
9
9
  require "bigdecimal/newton"
10
10
  include Newton
11
11
 
12
- class Function
12
+ class Function # :nodoc: all
13
13
  def initialize()
14
14
  @zero = BigDecimal::new("0.0")
15
15
  @one = BigDecimal::new("1.0")
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigdecimal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kenta Murata
8
+ - Zachary Scott
9
9
  - Shigeo Kobayashi
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-07-30 00:00:00.000000000 Z
13
+ date: 2012-02-19 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: This library provides arbitrary-precision decimal floating-point number
16
16
  class.
@@ -36,26 +36,25 @@ files:
36
36
  - sample/pi.rb
37
37
  homepage: http://www.ruby-lang.org
38
38
  licenses: []
39
+ metadata: {}
39
40
  post_install_message:
40
41
  rdoc_options: []
41
42
  require_paths:
42
43
  - .
43
44
  required_ruby_version: !ruby/object:Gem::Requirement
44
- none: false
45
45
  requirements:
46
46
  - - ! '>='
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  required_rubygems_version: !ruby/object:Gem::Requirement
50
- none: false
51
50
  requirements:
52
51
  - - ! '>='
53
52
  - !ruby/object:Gem::Version
54
53
  version: '0'
55
54
  requirements: []
56
55
  rubyforge_project:
57
- rubygems_version: 1.8.15
56
+ rubygems_version: 2.0.3
58
57
  signing_key:
59
- specification_version: 3
58
+ specification_version: 4
60
59
  summary: Arbitrary-precision decimal floating-point number library.
61
60
  test_files: []