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