bigdecimal 3.3.0-java → 3.3.1-java
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.
- checksums.yaml +4 -4
- data/lib/bigdecimal/math.rb +7 -7
- data/lib/bigdecimal.rb +22 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 538c9295198cb9f2ca1a0e96735dc2d99f65d9217f224d581ca8030fd5d27630
|
4
|
+
data.tar.gz: d69f66f81b160cfe8aa9c613d59bdfec0a4a22655eb3c47fb431893c72e1c927
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8900815e635a380751c0cd8567e8a2d494178eb982456fd3f86dcccc295b47b3d0220b2c6c12e46548782f05834f305407f421d53683931591bdd5d3daf22af
|
7
|
+
data.tar.gz: 826fa286abb8bdd09ad628e9545b765ae3f267756d8cc8b9a4c64f118fe4dda2ac61304bea1c10ad903a7457c0577fdbd39c6ddfc5a94b0346b438efcabb280a
|
data/lib/bigdecimal/math.rb
CHANGED
@@ -41,7 +41,7 @@ module BigMath
|
|
41
41
|
# #=> "0.14142135623730950488016887242097e1"
|
42
42
|
#
|
43
43
|
def sqrt(x, prec)
|
44
|
-
BigDecimal::Internal.
|
44
|
+
prec = BigDecimal::Internal.coerce_validate_prec(prec, :sqrt)
|
45
45
|
x = BigDecimal::Internal.coerce_to_bigdecimal(x, prec, :sqrt)
|
46
46
|
x.sqrt(prec)
|
47
47
|
end
|
@@ -85,7 +85,7 @@ module BigMath
|
|
85
85
|
# #=> "0.70710807985947359435812921837984e0"
|
86
86
|
#
|
87
87
|
def sin(x, prec)
|
88
|
-
BigDecimal::Internal.
|
88
|
+
prec = BigDecimal::Internal.coerce_validate_prec(prec, :sin)
|
89
89
|
x = BigDecimal::Internal.coerce_to_bigdecimal(x, prec, :sin)
|
90
90
|
return BigDecimal::Internal.nan_computation_result if x.infinite? || x.nan?
|
91
91
|
n = prec + BigDecimal.double_fig
|
@@ -122,7 +122,7 @@ module BigMath
|
|
122
122
|
# #=> "-0.99999999999999999999999999999997e0"
|
123
123
|
#
|
124
124
|
def cos(x, prec)
|
125
|
-
BigDecimal::Internal.
|
125
|
+
prec = BigDecimal::Internal.coerce_validate_prec(prec, :cos)
|
126
126
|
x = BigDecimal::Internal.coerce_to_bigdecimal(x, prec, :cos)
|
127
127
|
return BigDecimal::Internal.nan_computation_result if x.infinite? || x.nan?
|
128
128
|
sign, x = _sin_periodic_reduction(x, prec + BigDecimal.double_fig, add_half_pi: true)
|
@@ -144,7 +144,7 @@ module BigMath
|
|
144
144
|
# #=> "0.99999999999999999999999830836025e0"
|
145
145
|
#
|
146
146
|
def tan(x, prec)
|
147
|
-
BigDecimal::Internal.
|
147
|
+
prec = BigDecimal::Internal.coerce_validate_prec(prec, :tan)
|
148
148
|
sin(x, prec + BigDecimal.double_fig).div(cos(x, prec + BigDecimal.double_fig), prec)
|
149
149
|
end
|
150
150
|
|
@@ -160,7 +160,7 @@ module BigMath
|
|
160
160
|
# #=> "-0.78539816339744830961566084581988e0"
|
161
161
|
#
|
162
162
|
def atan(x, prec)
|
163
|
-
BigDecimal::Internal.
|
163
|
+
prec = BigDecimal::Internal.coerce_validate_prec(prec, :atan)
|
164
164
|
x = BigDecimal::Internal.coerce_to_bigdecimal(x, prec, :atan)
|
165
165
|
return BigDecimal::Internal.nan_computation_result if x.nan?
|
166
166
|
n = prec + BigDecimal.double_fig
|
@@ -198,7 +198,7 @@ module BigMath
|
|
198
198
|
# #=> "0.31415926535897932384626433832795e1"
|
199
199
|
#
|
200
200
|
def PI(prec)
|
201
|
-
BigDecimal::Internal.
|
201
|
+
prec = BigDecimal::Internal.coerce_validate_prec(prec, :PI)
|
202
202
|
n = prec + BigDecimal.double_fig
|
203
203
|
zero = BigDecimal("0")
|
204
204
|
one = BigDecimal("1")
|
@@ -243,7 +243,7 @@ module BigMath
|
|
243
243
|
# #=> "0.27182818284590452353602874713527e1"
|
244
244
|
#
|
245
245
|
def E(prec)
|
246
|
-
BigDecimal::Internal.
|
246
|
+
prec = BigDecimal::Internal.coerce_validate_prec(prec, :E)
|
247
247
|
BigMath.exp(1, prec)
|
248
248
|
end
|
249
249
|
end
|
data/lib/bigdecimal.rb
CHANGED
@@ -27,13 +27,24 @@ class BigDecimal
|
|
27
27
|
raise ArgumentError, "#{x.inspect} can't be coerced into BigDecimal"
|
28
28
|
end
|
29
29
|
|
30
|
-
def self.
|
31
|
-
|
30
|
+
def self.coerce_validate_prec(prec, method_name, accept_zero: false) # :nodoc:
|
31
|
+
unless Integer === prec
|
32
|
+
original = prec
|
33
|
+
# Emulate Integer.try_convert for ruby < 3.1
|
34
|
+
if prec.respond_to?(:to_int)
|
35
|
+
prec = prec.to_int
|
36
|
+
else
|
37
|
+
raise TypeError, "no implicit conversion of #{original.class} into Integer"
|
38
|
+
end
|
39
|
+
raise TypeError, "can't convert #{original.class} to Integer" unless Integer === prec
|
40
|
+
end
|
41
|
+
|
32
42
|
if accept_zero
|
33
43
|
raise ArgumentError, "Negative precision for #{method_name}" if prec < 0
|
34
44
|
else
|
35
45
|
raise ArgumentError, "Zero or negative precision for #{method_name}" if prec <= 0
|
36
46
|
end
|
47
|
+
prec
|
37
48
|
end
|
38
49
|
|
39
50
|
def self.infinity_computation_result # :nodoc:
|
@@ -83,10 +94,10 @@ class BigDecimal
|
|
83
94
|
#
|
84
95
|
# Also available as the operator **.
|
85
96
|
#
|
86
|
-
def power(y, prec =
|
87
|
-
Internal.
|
97
|
+
def power(y, prec = 0)
|
98
|
+
prec = Internal.coerce_validate_prec(prec, :power, accept_zero: true)
|
88
99
|
x = self
|
89
|
-
y = Internal.coerce_to_bigdecimal(y, prec || n_significant_digits, :power)
|
100
|
+
y = Internal.coerce_to_bigdecimal(y, prec.nonzero? || n_significant_digits, :power)
|
90
101
|
|
91
102
|
return Internal.nan_computation_result if x.nan? || y.nan?
|
92
103
|
return BigDecimal(1) if y.zero?
|
@@ -133,10 +144,10 @@ class BigDecimal
|
|
133
144
|
return BigDecimal(1)
|
134
145
|
end
|
135
146
|
|
136
|
-
prec
|
147
|
+
prec = BigDecimal.limit if prec.zero?
|
137
148
|
frac_part = y.frac
|
138
149
|
|
139
|
-
if frac_part.zero? &&
|
150
|
+
if frac_part.zero? && prec.zero?
|
140
151
|
# Infinite precision calculation for `x ** int` and `x.power(int)`
|
141
152
|
int_part = y.fix.to_i
|
142
153
|
int_part = -int_part if (neg = int_part < 0)
|
@@ -156,7 +167,7 @@ class BigDecimal
|
|
156
167
|
return neg ? BigDecimal(1) / ans : ans
|
157
168
|
end
|
158
169
|
|
159
|
-
prec
|
170
|
+
prec = [x.n_significant_digits, y.n_significant_digits, BigDecimal.double_fig].max + BigDecimal.double_fig if prec.zero?
|
160
171
|
|
161
172
|
if y < 0
|
162
173
|
inv = x.power(-y, prec)
|
@@ -198,7 +209,7 @@ class BigDecimal
|
|
198
209
|
# Result has at least prec significant digits.
|
199
210
|
#
|
200
211
|
def sqrt(prec)
|
201
|
-
Internal.
|
212
|
+
prec = Internal.coerce_validate_prec(prec, :sqrt, accept_zero: true)
|
202
213
|
return Internal.infinity_computation_result if infinite? == 1
|
203
214
|
|
204
215
|
raise FloatDomainError, 'sqrt of negative value' if self < 0
|
@@ -238,7 +249,7 @@ module BigMath
|
|
238
249
|
# If +decimal+ is NaN, returns NaN.
|
239
250
|
#
|
240
251
|
def self.log(x, prec)
|
241
|
-
BigDecimal::Internal.
|
252
|
+
prec = BigDecimal::Internal.coerce_validate_prec(prec, :log)
|
242
253
|
raise Math::DomainError, 'Complex argument for BigMath.log' if Complex === x
|
243
254
|
|
244
255
|
x = BigDecimal::Internal.coerce_to_bigdecimal(x, prec, :log)
|
@@ -315,7 +326,7 @@ module BigMath
|
|
315
326
|
# If +decimal+ is NaN, returns NaN.
|
316
327
|
#
|
317
328
|
def self.exp(x, prec)
|
318
|
-
BigDecimal::Internal.
|
329
|
+
prec = BigDecimal::Internal.coerce_validate_prec(prec, :exp)
|
319
330
|
x = BigDecimal::Internal.coerce_to_bigdecimal(x, prec, :exp)
|
320
331
|
return BigDecimal::Internal.nan_computation_result if x.nan?
|
321
332
|
return x.positive? ? BigDecimal::Internal.infinity_computation_result : BigDecimal(0) if x.infinite?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bigdecimal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
4
|
+
version: 3.3.1
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Kenta Murata
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
- Shigeo Kobayashi
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2025-10-
|
12
|
+
date: 2025-10-09 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: This library provides arbitrary-precision decimal floating-point number
|
15
15
|
class.
|