|
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 | #
|
@@ -424,6 +427,68 @@ def tanh(x, prec)
|
424 | 427 | (e - einv).div(e + einv, prec)
|
425 | 428 | end
|
426 | 429 |
|
| 430 | + # call-seq: |
| 431 | + # asinh(decimal, numeric) -> BigDecimal |
| 432 | + # |
| 433 | + # Computes the inverse hyperbolic sine of +decimal+ to the specified number of digits of |
| 434 | + # precision, +numeric+. |
| 435 | + # |
| 436 | + # If +decimal+ is NaN, returns NaN. |
| 437 | + # |
| 438 | + # BigMath.asinh(BigDecimal('1'), 16).to_s |
| 439 | + # #=> "0.881373587019543025232609324892919887466177636058e0" |
| 440 | + # |
| 441 | + def asinh(x, prec) |
| 442 | + raise ArgumentError, "Zero or negative precision for tanh" if prec <= 0 |
| 443 | + return x if x.nan? || x.infinite? |
| 444 | + return -asinh(-x, prec) if x < 0 |
| 445 | + |
| 446 | + sqrt_prec = prec + [-x.exponent, 0].max |
| 447 | + BigMath.log(x + sqrt(x**2 + 1, sqrt_prec), prec) |
| 448 | + end |
| 449 | + |
| 450 | + # call-seq: |
| 451 | + # acosh(decimal, numeric) -> BigDecimal |
| 452 | + # |
| 453 | + # Computes the inverse hyperbolic cosine of +decimal+ to the specified number of digits of |
| 454 | + # precision, +numeric+. |
| 455 | + # |
| 456 | + # If +decimal+ is NaN, returns NaN. |
| 457 | + # |
| 458 | + # BigMath.acosh(BigDecimal('2'), 16).to_s |
| 459 | + # #=> "0.1316957896924816708625046347239934461496535769096e1" |
| 460 | + # |
| 461 | + def acosh(x, prec) |
| 462 | + raise ArgumentError, "Zero or negative precision for tanh" if prec <= 0 |
| 463 | + raise Math::DomainError, "Out of domain argument for acosh" if x < 1 |
| 464 | + return BigDecimal::INFINITY if x.infinite? |
| 465 | + return BigDecimal::NAN if x.nan? |
| 466 | + |
| 467 | + BigMath.log(x + sqrt(x**2 - 1, prec), prec) |
| 468 | + end |
| 469 | + |
| 470 | + # call-seq: |
| 471 | + # atanh(decimal, numeric) -> BigDecimal |
| 472 | + # |
| 473 | + # Computes the inverse hyperbolic tangent of +decimal+ to the specified number of digits of |
| 474 | + # precision, +numeric+. |
| 475 | + # |
| 476 | + # If +decimal+ is NaN, returns NaN. |
| 477 | + # |
| 478 | + # BigMath.atanh(BigDecimal('0.5'), 16).to_s |
| 479 | + # #=> "0.54930614433405484569762261846126e0" |
| 480 | + # |
| 481 | + def atanh(x, prec) |
| 482 | + raise ArgumentError, "Zero or negative precision for tanh" if prec <= 0 |
| 483 | + raise Math::DomainError, "Out of domain argument for atanh" if x < -1 || x > 1 |
| 484 | + return BigDecimal::NAN if x.nan? |
| 485 | + return BigDecimal::INFINITY if x == 1 |
| 486 | + return -BigDecimal::INFINITY if x == -1 |
| 487 | + |
| 488 | + prec += BigDecimal.double_fig |
| 489 | + (BigMath.log(x + 1, prec) - BigMath.log(1 - x, prec)).div(2, prec) |
| 490 | + end |
| 491 | + |
427 | 492 | # call-seq:
|
428 | 493 | # PI(numeric) -> BigDecimal
|
429 | 494 | #
|
|
0 commit comments