|
17 | 17 | # sinh (x, prec)
|
18 | 18 | # cosh (x, prec)
|
19 | 19 | # tanh (x, prec)
|
| 20 | +# asinh(x, prec) |
| 21 | +# acosh(x, prec) |
| 22 | +# atanh(x, prec) |
20 | 23 | # PI (prec)
|
21 | 24 | # E (prec) == exp(1.0,prec)
|
22 | 25 | #
|
@@ -435,6 +438,68 @@ def tanh(x, prec)
|
435 | 438 | (e - einv).div(e + einv, prec)
|
436 | 439 | end
|
437 | 440 |
|
| 441 | + # call-seq: |
| 442 | + # asinh(decimal, numeric) -> BigDecimal |
| 443 | + # |
| 444 | + # Computes the inverse hyperbolic sine of +decimal+ to the specified number of digits of |
| 445 | + # precision, +numeric+. |
| 446 | + # |
| 447 | + # If +decimal+ is NaN, returns NaN. |
| 448 | + # |
| 449 | + # BigMath.asinh(BigDecimal('1'), 16).to_s |
| 450 | + # #=> "0.881373587019543025232609324892919887466177636058e0" |
| 451 | + # |
| 452 | + def asinh(x, prec) |
| 453 | + raise ArgumentError, "Zero or negative precision for tanh" if prec <= 0 |
| 454 | + return x if x.nan? || x.infinite? |
| 455 | + return -asinh(-x, prec) if x < 0 |
| 456 | + |
| 457 | + sqrt_prec = prec + [-x.exponent, 0].max |
| 458 | + BigMath.log(x + sqrt(x**2 + 1, sqrt_prec), prec) |
| 459 | + end |
| 460 | + |
| 461 | + # call-seq: |
| 462 | + # acosh(decimal, numeric) -> BigDecimal |
| 463 | + # |
| 464 | + # Computes the inverse hyperbolic cosine of +decimal+ to the specified number of digits of |
| 465 | + # precision, +numeric+. |
| 466 | + # |
| 467 | + # If +decimal+ is NaN, returns NaN. |
| 468 | + # |
| 469 | + # BigMath.acosh(BigDecimal('2'), 16).to_s |
| 470 | + # #=> "0.1316957896924816708625046347239934461496535769096e1" |
| 471 | + # |
| 472 | + def acosh(x, prec) |
| 473 | + raise ArgumentError, "Zero or negative precision for tanh" if prec <= 0 |
| 474 | + raise Math::DomainError, "Out of domain argument for acosh" if x < 1 |
| 475 | + return BigDecimal::INFINITY if x.infinite? |
| 476 | + return BigDecimal::NAN if x.nan? |
| 477 | + |
| 478 | + BigMath.log(x + sqrt(x**2 - 1, prec), prec) |
| 479 | + end |
| 480 | + |
| 481 | + # call-seq: |
| 482 | + # atanh(decimal, numeric) -> BigDecimal |
| 483 | + # |
| 484 | + # Computes the inverse hyperbolic tangent of +decimal+ to the specified number of digits of |
| 485 | + # precision, +numeric+. |
| 486 | + # |
| 487 | + # If +decimal+ is NaN, returns NaN. |
| 488 | + # |
| 489 | + # BigMath.atanh(BigDecimal('0.5'), 16).to_s |
| 490 | + # #=> "0.54930614433405484569762261846126e0" |
| 491 | + # |
| 492 | + def atanh(x, prec) |
| 493 | + raise ArgumentError, "Zero or negative precision for tanh" if prec <= 0 |
| 494 | + raise Math::DomainError, "Out of domain argument for atanh" if x < -1 || x > 1 |
| 495 | + return BigDecimal::NAN if x.nan? |
| 496 | + return BigDecimal::INFINITY if x == 1 |
| 497 | + return -BigDecimal::INFINITY if x == -1 |
| 498 | + |
| 499 | + prec += BigDecimal.double_fig |
| 500 | + (BigMath.log(x + 1, prec) - BigMath.log(1 - x, prec)).div(2, prec) |
| 501 | + end |
| 502 | + |
438 | 503 | # call-seq:
|
439 | 504 | # PI(numeric) -> BigDecimal
|
440 | 505 | #
|
|
0 commit comments