Module: Math
- Defined in:
- lib/complex.rb
Instance Method Summary collapse
- #acos(z) ⇒ Object (also: #acos!)
- #acosh(z) ⇒ Object (also: #acosh!)
- #asin(z) ⇒ Object (also: #asin!)
- #asinh(z) ⇒ Object (also: #asinh!)
- #atan(z) ⇒ Object (also: #atan!)
- #atan2(y, x) ⇒ Object (also: #atan2!)
- #atanh(z) ⇒ Object (also: #atanh!)
-
#cos(z) ⇒ Object
(also: #cos!)
Redefined to handle a Complex argument.
- #cosh(z) ⇒ Object (also: #cosh!)
-
#exp(z) ⇒ Object
(also: #exp!)
Redefined to handle a Complex argument.
-
#log(z) ⇒ Object
(also: #log!)
Redefined to handle a Complex argument.
-
#log10(z) ⇒ Object
(also: #log10!)
Redefined to handle a Complex argument.
-
#sin(z) ⇒ Object
(also: #sin!)
Redefined to handle a Complex argument.
- #sinh(z) ⇒ Object (also: #sinh!)
-
#sqrt(z) ⇒ Object
(also: #sqrt!)
Redefined to handle a Complex argument.
-
#tan(z) ⇒ Object
(also: #tan!)
Redefined to handle a Complex argument.
- #tanh(z) ⇒ Object (also: #tanh!)
Instance Method Details
#acos(z) ⇒ Object Also known as: acos!
562 563 564 565 566 567 568 |
# File 'lib/complex.rb', line 562 def acos(z) if Complex.generic?(z) and z >= -1 and z <= 1 acos!(z) else -1.0.im * log( z + 1.0.im * sqrt(1.0-z*z) ) end end |
#acosh(z) ⇒ Object Also known as: acosh!
594 595 596 597 598 599 600 |
# File 'lib/complex.rb', line 594 def acosh(z) if Complex.generic?(z) and z >= 1 acosh!(z) else log( z + sqrt(z*z-1.0) ) end end |
#asin(z) ⇒ Object Also known as: asin!
570 571 572 573 574 575 576 |
# File 'lib/complex.rb', line 570 def asin(z) if Complex.generic?(z) and z >= -1 and z <= 1 asin!(z) else -1.0.im * log( 1.0.im * z + sqrt(1.0-z*z) ) end end |
#asinh(z) ⇒ Object Also known as: asinh!
602 603 604 605 606 607 608 |
# File 'lib/complex.rb', line 602 def asinh(z) if Complex.generic?(z) asinh!(z) else log( z + sqrt(1.0+z*z) ) end end |
#atan(z) ⇒ Object Also known as: atan!
578 579 580 581 582 583 584 |
# File 'lib/complex.rb', line 578 def atan(z) if Complex.generic?(z) atan!(z) else 1.0.im * log( (1.0.im+z) / (1.0.im-z) ) / 2.0 end end |
#atan2(y, x) ⇒ Object Also known as: atan2!
586 587 588 589 590 591 592 |
# File 'lib/complex.rb', line 586 def atan2(y,x) if Complex.generic?(y) and Complex.generic?(x) atan2!(y,x) else -1.0.im * log( (x+1.0.im*y) / sqrt(x*x+y*y) ) end end |
#atanh(z) ⇒ Object Also known as: atanh!
610 611 612 613 614 615 616 |
# File 'lib/complex.rb', line 610 def atanh(z) if Complex.generic?(z) and z >= -1 and z <= 1 atanh!(z) else log( (1.0+z) / (1.0-z) ) / 2.0 end end |
#cos(z) ⇒ Object Also known as: cos!
Redefined to handle a Complex argument.
491 492 493 494 495 496 497 498 |
# File 'lib/complex.rb', line 491 def cos(z) if Complex.generic?(z) cos!(z) else Complex(cos!(z.real)*cosh!(z.image), -sin!(z.real)*sinh!(z.image)) end end |
#cosh(z) ⇒ Object Also known as: cosh!
527 528 529 530 531 532 533 |
# File 'lib/complex.rb', line 527 def cosh(z) if Complex.generic?(z) cosh!(z) else Complex( cosh!(z.real)*cos!(z.image), sinh!(z.real)*sin!(z.image) ) end end |
#exp(z) ⇒ Object Also known as: exp!
Redefined to handle a Complex argument.
482 483 484 485 486 487 488 |
# File 'lib/complex.rb', line 482 def exp(z) if Complex.generic?(z) exp!(z) else Complex(exp!(z.real) * cos!(z.image), exp!(z.real) * sin!(z.image)) end end |
#log(z) ⇒ Object Also known as: log!
Redefined to handle a Complex argument.
544 545 546 547 548 549 550 551 |
# File 'lib/complex.rb', line 544 def log(z) if Complex.generic?(z) and z >= 0 log!(z) else r, theta = z.polar Complex(log!(r.abs), theta) end end |
#log10(z) ⇒ Object Also known as: log10!
Redefined to handle a Complex argument.
554 555 556 557 558 559 560 |
# File 'lib/complex.rb', line 554 def log10(z) if Complex.generic?(z) log10!(z) else log(z)/log!(10) end end |
#sin(z) ⇒ Object Also known as: sin!
Redefined to handle a Complex argument.
501 502 503 504 505 506 507 508 |
# File 'lib/complex.rb', line 501 def sin(z) if Complex.generic?(z) sin!(z) else Complex(sin!(z.real)*cosh!(z.image), cos!(z.real)*sinh!(z.image)) end end |
#sinh(z) ⇒ Object Also known as: sinh!
519 520 521 522 523 524 525 |
# File 'lib/complex.rb', line 519 def sinh(z) if Complex.generic?(z) sinh!(z) else Complex( sinh!(z.real)*cos!(z.image), cosh!(z.real)*sin!(z.image) ) end end |
#sqrt(z) ⇒ Object Also known as: sqrt!
Redefined to handle a Complex argument.
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
# File 'lib/complex.rb', line 463 def sqrt(z) if Complex.generic?(z) if z >= 0 sqrt!(z) else Complex(0,sqrt!(-z)) end else if z.image < 0 sqrt(z.conjugate).conjugate else r = z.abs x = z.real Complex( sqrt!((r+x)/2), sqrt!((r-x)/2) ) end end end |