Module: Math
- Defined in:
- lib/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
534 535 536 537 538 539 540 |
# File 'lib/complex.rb', line 534 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
426 |
# File 'lib/complex.rb', line 426 alias acos! acos |
.acosh(z) ⇒ Object
566 567 568 569 570 571 572 |
# File 'lib/complex.rb', line 566 def acosh(z) if Complex.generic?(z) and z >= 1 acosh!(z) else log( z + sqrt(z*z-1.0) ) end end |
.acosh! ⇒ Object
430 |
# File 'lib/complex.rb', line 430 alias acosh! acosh |
.asin(z) ⇒ Object
542 543 544 545 546 547 548 |
# File 'lib/complex.rb', line 542 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
427 |
# File 'lib/complex.rb', line 427 alias asin! asin |
.asinh(z) ⇒ Object
574 575 576 577 578 579 580 |
# File 'lib/complex.rb', line 574 def asinh(z) if Complex.generic?(z) asinh!(z) else log( z + sqrt(1.0+z*z) ) end end |
.asinh! ⇒ Object
431 |
# File 'lib/complex.rb', line 431 alias asinh! asinh |
.atan(z) ⇒ Object
550 551 552 553 554 555 556 |
# File 'lib/complex.rb', line 550 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
428 |
# File 'lib/complex.rb', line 428 alias atan! atan |
.atan2(y, x) ⇒ Object
558 559 560 561 562 563 564 |
# File 'lib/complex.rb', line 558 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
429 |
# File 'lib/complex.rb', line 429 alias atan2! atan2 |
.atanh(z) ⇒ Object
582 583 584 585 586 587 588 |
# File 'lib/complex.rb', line 582 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
432 |
# File 'lib/complex.rb', line 432 alias atanh! atanh |
.cos(z) ⇒ Object
Redefined to handle a Complex argument.
463 464 465 466 467 468 469 470 |
# File 'lib/complex.rb', line 463 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
420 |
# File 'lib/complex.rb', line 420 alias cos! cos |
.cosh(z) ⇒ Object
499 500 501 502 503 504 505 |
# File 'lib/complex.rb', line 499 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
423 |
# File 'lib/complex.rb', line 423 alias cosh! cosh |
.exp(z) ⇒ Object
Redefined to handle a Complex argument.
454 455 456 457 458 459 460 |
# File 'lib/complex.rb', line 454 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
417 |
# File 'lib/complex.rb', line 417 alias exp! exp |
.log(z) ⇒ Object
Redefined to handle a Complex argument.
516 517 518 519 520 521 522 523 |
# File 'lib/complex.rb', line 516 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
418 |
# File 'lib/complex.rb', line 418 alias log! log |
.log10(z) ⇒ Object
Redefined to handle a Complex argument.
526 527 528 529 530 531 532 |
# File 'lib/complex.rb', line 526 def log10(z) if Complex.generic?(z) log10!(z) else log(z)/log!(10) end end |
.log10! ⇒ Object
419 |
# File 'lib/complex.rb', line 419 alias log10! log10 |
.sin(z) ⇒ Object
Redefined to handle a Complex argument.
473 474 475 476 477 478 479 480 |
# File 'lib/complex.rb', line 473 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
421 |
# File 'lib/complex.rb', line 421 alias sin! sin |
.sinh(z) ⇒ Object
491 492 493 494 495 496 497 |
# File 'lib/complex.rb', line 491 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
424 |
# File 'lib/complex.rb', line 424 alias sinh! sinh |
.sqrt(z) ⇒ Object
Redefined to handle a Complex argument.
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/complex.rb', line 435 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
416 |
# File 'lib/complex.rb', line 416 alias sqrt! sqrt |
.tan(z) ⇒ Object
Redefined to handle a Complex argument.
483 484 485 486 487 488 489 |
# File 'lib/complex.rb', line 483 def tan(z) if Complex.generic?(z) tan!(z) else sin(z)/cos(z) end end |
.tan! ⇒ Object
422 |
# File 'lib/complex.rb', line 422 alias tan! tan |
.tanh(z) ⇒ Object
507 508 509 510 511 512 513 |
# File 'lib/complex.rb', line 507 def tanh(z) if Complex.generic?(z) tanh!(z) else sinh(z)/cosh(z) end end |
.tanh! ⇒ Object
425 |
# File 'lib/complex.rb', line 425 alias tanh! tanh |