Skip to content

Commit 82e11ad

Browse files
authored
Merge pull request #2758 from ksss/bigdecimal-4
Support BigDecimal v4
2 parents 6612142 + 618aed2 commit 82e11ad

File tree

5 files changed

+362
-32
lines changed

5 files changed

+362
-32
lines changed

Gemfile.lock

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ GEM
3333
base64 (0.3.0)
3434
benchmark (0.5.0)
3535
benchmark-ips (2.14.0)
36-
bigdecimal (3.3.1)
36+
bigdecimal (4.0.0)
3737
concurrent-ruby (1.3.6)
3838
connection_pool (3.0.2)
3939
csv (3.3.5)
@@ -58,9 +58,8 @@ GEM
5858
rdoc (>= 4.0.0)
5959
reline (>= 0.4.2)
6060
json (2.18.0)
61-
json-schema (6.0.0)
61+
json-schema (5.1.0)
6262
addressable (~> 2.8)
63-
bigdecimal (~> 3.1)
6463
language_server-protocol (3.17.0.5)
6564
lint_roller (1.1.0)
6665
listen (3.9.0)

stdlib/bigdecimal-math/0/big_math.rbs

Lines changed: 169 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,46 @@ module BigMath
3535
#
3636
def self?.PI: (Numeric prec) -> BigDecimal
3737

38+
# Computes the arccosine of `decimal` to the specified number of digits of
39+
# precision, `numeric`.
40+
#
41+
# If `decimal` is NaN, returns NaN.
42+
#
43+
# BigMath.acos(BigDecimal('0.5'), 32).to_s
44+
# #=> "0.10471975511965977461542144610932e1"
45+
#
46+
def self?.acos: (BigDecimal, Numeric) -> BigDecimal
47+
48+
# Computes the inverse hyperbolic cosine of `decimal` to the specified number of
49+
# digits of precision, `numeric`.
50+
#
51+
# If `decimal` is NaN, returns NaN.
52+
#
53+
# BigMath.acosh(BigDecimal('2'), 32).to_s
54+
# #=> "0.1316957896924816708625046347308e1"
55+
#
56+
def self?.acosh: (BigDecimal, Numeric) -> BigDecimal
57+
58+
# Computes the arcsine of `decimal` to the specified number of digits of
59+
# precision, `numeric`.
60+
#
61+
# If `decimal` is NaN, returns NaN.
62+
#
63+
# BigMath.asin(BigDecimal('0.5'), 32).to_s
64+
# #=> "0.52359877559829887307710723054658e0"
65+
#
66+
def self?.asin: (BigDecimal, Numeric) -> BigDecimal
67+
68+
# Computes the inverse hyperbolic sine of `decimal` to the specified number of
69+
# digits of precision, `numeric`.
70+
#
71+
# If `decimal` is NaN, returns NaN.
72+
#
73+
# BigMath.asinh(BigDecimal('1'), 32).to_s
74+
# #=> "0.88137358701954302523260932497979e0"
75+
#
76+
def self?.asinh: (BigDecimal, Numeric) -> BigDecimal
77+
3878
# <!--
3979
# rdoc-file=ext/bigdecimal/lib/bigdecimal/math.rb
4080
# - atan(decimal, numeric) -> BigDecimal
@@ -49,6 +89,32 @@ module BigMath
4989
#
5090
def self?.atan: (BigDecimal x, Numeric prec) -> BigDecimal
5191

92+
# Computes the arctangent of y and x to the specified number of digits of
93+
# precision, `numeric`.
94+
#
95+
# BigMath.atan2(BigDecimal('-1'), BigDecimal('1'), 32).to_s
96+
# #=> "-0.78539816339744830961566084581988e0"
97+
#
98+
def self?.atan2: (BigDecimal, BigDecimal, Numeric) -> BigDecimal
99+
100+
# Computes the inverse hyperbolic tangent of `decimal` to the specified number
101+
# of digits of precision, `numeric`.
102+
#
103+
# If `decimal` is NaN, returns NaN.
104+
#
105+
# BigMath.atanh(BigDecimal('0.5'), 32).to_s
106+
# #=> "0.54930614433405484569762261846126e0"
107+
#
108+
def self?.atanh: (BigDecimal, Numeric) -> BigDecimal
109+
110+
# Computes the cube root of `decimal` to the specified number of digits of
111+
# precision, `numeric`.
112+
#
113+
# BigMath.cbrt(BigDecimal('2'), 32).to_s
114+
# #=> "0.12599210498948731647672106072782e1"
115+
#
116+
def self?.cbrt: (BigDecimal, Numeric) -> BigDecimal
117+
52118
# <!--
53119
# rdoc-file=ext/bigdecimal/lib/bigdecimal/math.rb
54120
# - cos(decimal, numeric) -> BigDecimal
@@ -63,10 +129,36 @@ module BigMath
63129
#
64130
def self?.cos: (BigDecimal x, Numeric prec) -> BigDecimal
65131

66-
# <!--
67-
# rdoc-file=ext/bigdecimal/bigdecimal.c
68-
# - BigMath.exp(decimal, numeric) -> BigDecimal
69-
# -->
132+
# Computes the hyperbolic cosine of `decimal` to the specified number of digits
133+
# of precision, `numeric`.
134+
#
135+
# If `decimal` is NaN, returns NaN.
136+
#
137+
# BigMath.cosh(BigDecimal('1'), 32).to_s
138+
# #=> "0.15430806348152437784779056207571e1"
139+
#
140+
def self?.cosh: (BigDecimal, Numeric) -> BigDecimal
141+
142+
# Computes the error function of +decimal+ to the specified number of digits of
143+
# precision, +numeric+.
144+
#
145+
# If +decimal+ is NaN, returns NaN.
146+
#
147+
# BigMath.erf(BigDecimal('1'), 32).to_s
148+
# #=> "0.84270079294971486934122063508261e0"
149+
#
150+
def self?.erf: (BigDecimal, Numeric) -> BigDecimal
151+
152+
# Computes the complementary error function of +decimal+ to the specified number of digits of
153+
# precision, +numeric+.
154+
#
155+
# If +decimal+ is NaN, returns NaN.
156+
#
157+
# BigMath.erfc(BigDecimal('10'), 32).to_s
158+
# #=> "0.20884875837625447570007862949578e-44"
159+
#
160+
def self?.erfc: (BigDecimal, Numeric) -> BigDecimal
161+
70162
# Computes the value of e (the base of natural logarithms) raised to the power
71163
# of `decimal`, to the specified number of digits of precision.
72164
#
@@ -76,10 +168,45 @@ module BigMath
76168
#
77169
def self?.exp: (BigDecimal, Numeric prec) -> BigDecimal
78170

79-
# <!--
80-
# rdoc-file=ext/bigdecimal/bigdecimal.c
81-
# - BigMath.log(decimal, numeric) -> BigDecimal
82-
# -->
171+
# Decomposes +x+ into a normalized fraction and an integral power of ten.
172+
#
173+
# BigMath.frexp(BigDecimal(123.456))
174+
# #=> [0.123456e0, 3]
175+
#
176+
def self?.frexp: (BigDecimal) -> [ BigDecimal, Integer ]
177+
178+
# Computes the gamma function of +decimal+ to the specified number of
179+
# digits of precision, +numeric+.
180+
#
181+
# BigMath.gamma(BigDecimal('0.5'), 32).to_s
182+
# #=> "0.17724538509055160272981674833411e1"
183+
#
184+
def self?.gamma: (BigDecimal, Numeric) -> BigDecimal
185+
186+
# Returns sqrt(x**2 + y**2) to the specified number of digits of precision,
187+
# `numeric`.
188+
#
189+
# BigMath.hypot(BigDecimal('1'), BigDecimal('2'), 32).to_s
190+
# #=> "0.22360679774997896964091736687313e1"
191+
#
192+
def self?.hypot: (BigDecimal, BigDecimal, Numeric) -> BigDecimal
193+
194+
# Inverse of +frexp+.
195+
# Returns the value of fraction * 10**exponent.
196+
#
197+
# BigMath.ldexp(BigDecimal("0.123456e0"), 3)
198+
# #=> 0.123456e3
199+
#
200+
def self?.ldexp: (BigDecimal, Integer) -> BigDecimal
201+
202+
# Computes the natural logarithm of the absolute value of the gamma function
203+
# of +decimal+ to the specified number of digits of precision, +numeric+ and its sign.
204+
#
205+
# BigMath.lgamma(BigDecimal('0.5'), 32)
206+
# #=> [0.57236494292470008707171367567653e0, 1]
207+
#
208+
def self?.lgamma: (BigDecimal, Numeric) -> [BigDecimal, Integer]
209+
83210
# Computes the natural logarithm of `decimal` to the specified number of digits
84211
# of precision, `numeric`.
85212
#
@@ -91,6 +218,20 @@ module BigMath
91218
#
92219
def self?.log: (BigDecimal, Numeric prec) -> BigDecimal
93220

221+
# Computes the base 2 logarithm of `decimal` to the specified number of digits
222+
# of precision, `numeric`.
223+
#
224+
# If `decimal` is zero or negative, raises Math::DomainError.
225+
#
226+
# If `decimal` is positive infinity, returns Infinity.
227+
#
228+
# If `decimal` is NaN, returns NaN.
229+
#
230+
# BigMath.log2(BigDecimal('3'), 32).to_s
231+
# #=> "0.15849625007211561814537389439478e1"
232+
#
233+
def self?.log2: (BigDecimal, Numeric) -> BigDecimal
234+
94235
# <!--
95236
# rdoc-file=ext/bigdecimal/lib/bigdecimal/math.rb
96237
# - sin(decimal, numeric) -> BigDecimal
@@ -105,6 +246,16 @@ module BigMath
105246
#
106247
def self?.sin: (BigDecimal x, Numeric prec) -> BigDecimal
107248

249+
# Computes the hyperbolic sine of `decimal` to the specified number of digits of
250+
# precision, `numeric`.
251+
#
252+
# If `decimal` is NaN, returns NaN.
253+
#
254+
# BigMath.sinh(BigDecimal('1'), 32).to_s
255+
# #=> "0.11752011936438014568823818505956e1"
256+
#
257+
def self?.sinh: (BigDecimal, Numeric) -> BigDecimal
258+
108259
# <!--
109260
# rdoc-file=ext/bigdecimal/lib/bigdecimal/math.rb
110261
# - sqrt(decimal, numeric) -> BigDecimal
@@ -116,4 +267,14 @@ module BigMath
116267
# #=> "0.1414213562373095048801688724e1"
117268
#
118269
def self?.sqrt: (BigDecimal x, Numeric prec) -> BigDecimal
270+
271+
# Computes the hyperbolic tangent of `decimal` to the specified number of digits
272+
# of precision, `numeric`.
273+
#
274+
# If `decimal` is NaN, returns NaN.
275+
#
276+
# BigMath.tanh(BigDecimal('1'), 32).to_s
277+
# #=> "0.76159415595576488811945828260479e0"
278+
#
279+
def self?.tanh: (BigDecimal, Numeric) -> BigDecimal
119280
end

stdlib/bigdecimal/0/big_decimal.rbs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ class BigDecimal < Numeric
609609
# The quotient q is (a/b).floor, and the modulus is the amount that must be
610610
# added to q * b to get a.
611611
#
612-
def divmod: (Numeric) -> [ BigDecimal, BigDecimal ]
612+
def divmod: (Numeric) -> [ Integer, BigDecimal ]
613613

614614
# <!--
615615
# rdoc-file=ext/bigdecimal/bigdecimal.c
@@ -783,20 +783,6 @@ class BigDecimal < Numeric
783783
#
784784
def power: (Numeric n, int prec) -> BigDecimal
785785

786-
# <!--
787-
# rdoc-file=ext/bigdecimal/bigdecimal.c
788-
# - precs -> array
789-
# -->
790-
# Returns an Array of two Integer values that represent platform-dependent
791-
# internal storage properties.
792-
#
793-
# This method is deprecated and will be removed in the future. Instead, use
794-
# BigDecimal#n_significant_digits for obtaining the number of significant digits
795-
# in scientific notation, and BigDecimal#precision for obtaining the number of
796-
# digits in decimal notation.
797-
#
798-
def precs: () -> [ Integer, Integer ]
799-
800786
# <!--
801787
# rdoc-file=ext/bigdecimal/bigdecimal.c
802788
# - quo(value) -> bigdecimal

test/stdlib/BigDecimal_test.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def test_div
189189
end
190190

191191
def test_divmod
192-
assert_send_type "(::Numeric) -> [ ::BigDecimal, ::BigDecimal ]",
192+
assert_send_type "(::Numeric) -> [ ::Integer, ::BigDecimal ]",
193193
BigDecimal("1.23"), :divmod, 2
194194
end
195195

@@ -318,11 +318,6 @@ def test_power
318318
BigDecimal("1.23"), :**, BigDecimal("1.23")
319319
end
320320

321-
def test_precs
322-
assert_send_type "() -> [ ::Integer, ::Integer ]",
323-
BigDecimal("1.23"), :precs
324-
end
325-
326321
def test_sign
327322
assert_send_type "() -> ::Integer",
328323
BigDecimal("1.23"), :sign

0 commit comments

Comments
 (0)