Returns the tangent of this complex number.
()
| 558 | * Returns the tangent of this complex number. |
| 559 | */ |
| 560 | public Complex tan() { |
| 561 | // tan(z) = sin(z)/cos(z) |
| 562 | double izRe, izIm; |
| 563 | double temp1Re, temp1Im; |
| 564 | double temp2Re, temp2Im; |
| 565 | double scalar; |
| 566 | Complex sinResult, cosResult; |
| 567 | // sin(z) = ( exp(i*z) - exp(-i*z) ) / (2*i) |
| 568 | izRe = -im; |
| 569 | izIm = re; |
| 570 | // first exp |
| 571 | scalar = Math.exp(izRe); |
| 572 | temp1Re = scalar*Math.cos(izIm); |
| 573 | temp1Im = scalar*Math.sin(izIm); |
| 574 | // second exp |
| 575 | scalar = Math.exp(-izRe); |
| 576 | temp2Re = scalar*Math.cos(-izIm); |
| 577 | temp2Im = scalar*Math.sin(-izIm); |
| 578 | temp1Re -= temp2Re; |
| 579 | temp1Im -= temp2Im; |
| 580 | sinResult = new Complex(0.5*temp1Re, 0.5*temp1Im); |
| 581 | // cos(z) = ( exp(i*z) + exp(-i*z) ) / 2 |
| 582 | izRe = -im; |
| 583 | izIm = re; |
| 584 | // first exp |
| 585 | scalar = Math.exp(izRe); |
| 586 | temp1Re = scalar*Math.cos(izIm); |
| 587 | temp1Im = scalar*Math.sin(izIm); |
| 588 | // second exp |
| 589 | scalar = Math.exp(-izRe); |
| 590 | temp2Re = scalar*Math.cos(-izIm); |
| 591 | temp2Im = scalar*Math.sin(-izIm); |
| 592 | temp1Re += temp2Re; |
| 593 | temp1Im += temp2Im; |
| 594 | cosResult = new Complex(0.5*temp1Re, 0.5*temp1Im); |
| 595 | return sinResult.div(cosResult); |
| 596 | } |
| 597 | |
| 598 | //------------------------------------------------------------------------ |
| 599 | // Inverse trigonometric functions |
no test coverage detected