Skip to content

Commit c2edc97

Browse files
committed
Add BigMath.gamma and BigMath.lgamma
See also: ruby/bigdecimal#451
1 parent 19af476 commit c2edc97

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

stdlib/bigdecimal-math/0/big_math.rbs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ module BigMath
172172
#
173173
def self?.exp: (BigDecimal, Numeric prec) -> BigDecimal
174174

175+
# Computes the gamma function of +decimal+ to the specified number of
176+
# digits of precision, +numeric+.
177+
#
178+
# BigMath.gamma(BigDecimal('0.5'), 32).to_s
179+
# #=> "0.17724538509055160272981674833411e1"
180+
#
181+
def self?.gamma: (BigDecimal, Numeric) -> BigDecimal
182+
175183
# <!--
176184
# rdoc-file=ext/bigdecimal/bigdecimal.c
177185
# Returns sqrt(x**2 + y**2) to the specified number of digits of precision,
@@ -182,6 +190,14 @@ module BigMath
182190
#
183191
def self?.hypot: (BigDecimal, BigDecimal, Numeric) -> BigDecimal
184192

193+
# Computes the natural logarithm of the absolute value of the gamma function
194+
# of +decimal+ to the specified number of digits of precision, +numeric+ and its sign.
195+
#
196+
# BigMath.lgamma(BigDecimal('0.5'), 32)
197+
# #=> [0.57236494292470008707171367567653e0, 1]
198+
#
199+
def self?.lgamma: (BigDecimal, Numeric) -> [BigDecimal, Integer]
200+
185201
# - BigMath.log(decimal, numeric) -> BigDecimal
186202
# -->
187203
# Computes the natural logarithm of `decimal` to the specified number of digits

test/stdlib/BigMath_test.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_acosh
2626
assert_send_type "(::BigDecimal, ::Numeric) -> ::BigDecimal",
2727
BigMath, :acosh, BigDecimal('2'), 32
2828
end
29-
29+
3030
def test_asin
3131
assert_send_type "(::BigDecimal, ::Numeric) -> ::BigDecimal",
3232
BigMath, :asin, BigDecimal('0.5'), 32
@@ -82,11 +82,21 @@ def test_exp
8282
BigMath, :exp, BigDecimal('1.23'), 10
8383
end
8484

85+
def test_gamma
86+
assert_send_type "(::BigDecimal, ::Numeric) -> ::BigDecimal",
87+
BigMath, :gamma, BigDecimal('0.5'), 32
88+
end
89+
8590
def test_hypot
8691
assert_send_type "(::BigDecimal, ::BigDecimal, ::Numeric) -> ::BigDecimal",
8792
BigMath, :hypot, BigDecimal('1'), BigDecimal('2'), 32
8893
end
8994

95+
def test_lgamma
96+
assert_send_type "(::BigDecimal, ::Numeric) -> [::BigDecimal, ::Integer]",
97+
BigMath, :lgamma, BigDecimal('0.5'), 32
98+
end
99+
90100
def test_log
91101
assert_send_type "(::BigDecimal, ::Numeric prec) -> ::BigDecimal",
92102
BigMath, :log, BigDecimal('1.23'), 10
@@ -202,11 +212,21 @@ def test_exp
202212
TestClass.new, :exp, BigDecimal('1.23'), 10
203213
end
204214

215+
def test_gamma
216+
assert_send_type "(::BigDecimal, ::Numeric) -> ::BigDecimal",
217+
TestClass.new, :gamma, BigDecimal('0.5'), 32
218+
end
219+
205220
def test_hypot
206221
assert_send_type "(::BigDecimal, ::BigDecimal, ::Numeric) -> ::BigDecimal",
207222
TestClass.new, :hypot, BigDecimal('1'), BigDecimal('2'), 32
208223
end
209224

225+
def test_lgamma
226+
assert_send_type "(::BigDecimal, ::Numeric) -> [::BigDecimal, ::Integer]",
227+
TestClass.new, :lgamma, BigDecimal('0.5'), 32
228+
end
229+
210230
def test_log
211231
assert_send_type "(::BigDecimal, ::Numeric prec) -> ::BigDecimal",
212232
TestClass.new, :log, BigDecimal('1.23'), 10

0 commit comments

Comments
 (0)