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!
536 537 538 539 540 541 542 |
# File 'lib/complex.rb', line 536 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!
568 569 570 571 572 573 574 |
# File 'lib/complex.rb', line 568 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!
544 545 546 547 548 549 550 |
# File 'lib/complex.rb', line 544 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!
576 577 578 579 580 581 582 |
# File 'lib/complex.rb', line 576 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!
552 553 554 555 556 557 558 |
# File 'lib/complex.rb', line 552 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!
560 561 562 563 564 565 566 |
# File 'lib/complex.rb', line 560 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!
584 585 586 587 588 589 590 |
# File 'lib/complex.rb', line 584 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.
465 466 467 468 469 470 471 472 |
# File 'lib/complex.rb', line 465 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!
501 502 503 504 505 506 507 |
# File 'lib/complex.rb', line 501 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.
456 457 458 459 460 461 462 |
# File 'lib/complex.rb', line 456 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.
518 519 520 521 522 523 524 525 |
# File 'lib/complex.rb', line 518 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.
528 529 530 531 532 533 534 |
# File 'lib/complex.rb', line 528 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.
475 476 477 478 479 480 481 482 |
# File 'lib/complex.rb', line 475 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!
493 494 495 496 497 498 499 |
# File 'lib/complex.rb', line 493 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.
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
# File 'lib/complex.rb', line 437 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 |