Returns the cosine of this complex number.
()
| 534 | |
| 535 | */ |
| 536 | public Complex cos() { |
| 537 | double izRe, izIm; |
| 538 | double temp1Re, temp1Im; |
| 539 | double temp2Re, temp2Im; |
| 540 | double scalar; |
| 541 | // cos(z) = ( exp(i*z) + exp(-i*z) ) / 2 |
| 542 | izRe = -im; |
| 543 | izIm = re; |
| 544 | // first exp |
| 545 | scalar = Math.exp(izRe); |
| 546 | temp1Re = scalar*Math.cos(izIm); |
| 547 | temp1Im = scalar*Math.sin(izIm); |
| 548 | // second exp |
| 549 | scalar = Math.exp(-izRe); |
| 550 | temp2Re = scalar*Math.cos(-izIm); |
| 551 | temp2Im = scalar*Math.sin(-izIm); |
| 552 | temp1Re += temp2Re; |
| 553 | temp1Im += temp2Im; |
| 554 | return new Complex(0.5*temp1Re, 0.5*temp1Im); |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * Returns the tangent of this complex number. |