Module: Math
- Defined in:
- lib/rubysl/complex/complex.rb
Class Method Summary collapse
- .acos(z) ⇒ Object
- .acos! ⇒ Object
- .acosh(z) ⇒ Object
- .acosh! ⇒ Object
- .asin(z) ⇒ Object
- .asin! ⇒ Object
- .asinh(z) ⇒ Object
- .asinh! ⇒ Object
- .atan(z) ⇒ Object
- .atan! ⇒ Object
- .atan2(y, x) ⇒ Object
- .atan2! ⇒ Object
- .atanh(z) ⇒ Object
- .atanh! ⇒ Object
-
.cos(z) ⇒ Object
Redefined to handle a Complex argument.
- .cos! ⇒ Object
- .cosh(z) ⇒ Object
- .cosh! ⇒ Object
-
.exp(z) ⇒ Object
Redefined to handle a Complex argument.
- .exp! ⇒ Object
-
.log(z) ⇒ Object
Redefined to handle a Complex argument.
- .log! ⇒ Object
-
.log10(z) ⇒ Object
Redefined to handle a Complex argument.
- .log10! ⇒ Object
-
.sin(z) ⇒ Object
Redefined to handle a Complex argument.
- .sin! ⇒ Object
- .sinh(z) ⇒ Object
- .sinh! ⇒ Object
-
.sqrt(z) ⇒ Object
Redefined to handle a Complex argument.
- .sqrt! ⇒ Object
-
.tan(z) ⇒ Object
Redefined to handle a Complex argument.
- .tan! ⇒ Object
- .tanh(z) ⇒ Object
- .tanh! ⇒ Object
Class Method Details
.acos(z) ⇒ Object
562 563 564 565 566 567 568 |
# File 'lib/rubysl/complex/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 |
.acos! ⇒ Object
454 |
# File 'lib/rubysl/complex/complex.rb', line 454 alias acos! acos |
.acosh(z) ⇒ Object
594 595 596 597 598 599 600 |
# File 'lib/rubysl/complex/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 |
.acosh! ⇒ Object
458 |
# File 'lib/rubysl/complex/complex.rb', line 458 alias acosh! acosh |
.asin(z) ⇒ Object
570 571 572 573 574 575 576 |
# File 'lib/rubysl/complex/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 |
.asin! ⇒ Object
455 |
# File 'lib/rubysl/complex/complex.rb', line 455 alias asin! asin |
.asinh(z) ⇒ Object
602 603 604 605 606 607 608 |
# File 'lib/rubysl/complex/complex.rb', line 602 def asinh(z) if Complex.generic?(z) asinh!(z) else log( z + sqrt(1.0+z*z) ) end end |
.asinh! ⇒ Object
459 |
# File 'lib/rubysl/complex/complex.rb', line 459 alias asinh! asinh |
.atan(z) ⇒ Object
578 579 580 581 582 583 584 |
# File 'lib/rubysl/complex/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 |
.atan! ⇒ Object
456 |
# File 'lib/rubysl/complex/complex.rb', line 456 alias atan! atan |
.atan2(y, x) ⇒ Object
586 587 588 589 590 591 592 |
# File 'lib/rubysl/complex/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 |
.atan2! ⇒ Object
457 |
# File 'lib/rubysl/complex/complex.rb', line 457 alias atan2! atan2 |
.atanh(z) ⇒ Object
610 611 612 613 614 615 616 |
# File 'lib/rubysl/complex/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 |
.atanh! ⇒ Object
460 |
# File 'lib/rubysl/complex/complex.rb', line 460 alias atanh! atanh |
.cos(z) ⇒ Object
Redefined to handle a Complex argument.
491 492 493 494 495 496 497 498 |
# File 'lib/rubysl/complex/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 |
.cos! ⇒ Object
448 |
# File 'lib/rubysl/complex/complex.rb', line 448 alias cos! cos |
.cosh(z) ⇒ Object
527 528 529 530 531 532 533 |
# File 'lib/rubysl/complex/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 |
.cosh! ⇒ Object
451 |
# File 'lib/rubysl/complex/complex.rb', line 451 alias cosh! cosh |
.exp(z) ⇒ Object
Redefined to handle a Complex argument.
482 483 484 485 486 487 488 |
# File 'lib/rubysl/complex/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 |
.exp! ⇒ Object
445 |
# File 'lib/rubysl/complex/complex.rb', line 445 alias exp! exp |
.log(z) ⇒ Object
Redefined to handle a Complex argument.
544 545 546 547 548 549 550 551 |
# File 'lib/rubysl/complex/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 |
.log! ⇒ Object
446 |
# File 'lib/rubysl/complex/complex.rb', line 446 alias log! log |
.log10(z) ⇒ Object
Redefined to handle a Complex argument.
554 555 556 557 558 559 560 |
# File 'lib/rubysl/complex/complex.rb', line 554 def log10(z) if Complex.generic?(z) log10!(z) else log(z)/log!(10) end end |
.log10! ⇒ Object
447 |
# File 'lib/rubysl/complex/complex.rb', line 447 alias log10! log10 |
.sin(z) ⇒ Object
Redefined to handle a Complex argument.
501 502 503 504 505 506 507 508 |
# File 'lib/rubysl/complex/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 |
.sin! ⇒ Object
449 |
# File 'lib/rubysl/complex/complex.rb', line 449 alias sin! sin |
.sinh(z) ⇒ Object
519 520 521 522 523 524 525 |
# File 'lib/rubysl/complex/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 |
.sinh! ⇒ Object
452 |
# File 'lib/rubysl/complex/complex.rb', line 452 alias sinh! sinh |
.sqrt(z) ⇒ Object
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/rubysl/complex/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 |
.sqrt! ⇒ Object
444 |
# File 'lib/rubysl/complex/complex.rb', line 444 alias sqrt! sqrt |
.tan(z) ⇒ Object
Redefined to handle a Complex argument.
511 512 513 514 515 516 517 |
# File 'lib/rubysl/complex/complex.rb', line 511 def tan(z) if Complex.generic?(z) tan!(z) else sin(z)/cos(z) end end |
.tan! ⇒ Object
450 |
# File 'lib/rubysl/complex/complex.rb', line 450 alias tan! tan |
.tanh(z) ⇒ Object
535 536 537 538 539 540 541 |
# File 'lib/rubysl/complex/complex.rb', line 535 def tanh(z) if Complex.generic?(z) tanh!(z) else sinh(z)/cosh(z) end end |
.tanh! ⇒ Object
453 |
# File 'lib/rubysl/complex/complex.rb', line 453 alias tanh! tanh |