| 517 | */ |
| 518 | template<class ValueType> |
| 519 | ValueType Sin(ValueType x, ErrorCode * err = 0) |
| 520 | { |
| 521 | using namespace auxiliaryfunctions; |
| 522 | |
| 523 | ValueType one, result; |
| 524 | bool change_sign; |
| 525 | |
| 526 | if( x.IsNan() ) |
| 527 | { |
| 528 | if( err ) |
| 529 | *err = err_improper_argument; |
| 530 | |
| 531 | return x; |
| 532 | } |
| 533 | |
| 534 | if( err ) |
| 535 | *err = err_ok; |
| 536 | |
| 537 | if( PrepareSin( x, change_sign ) ) |
| 538 | { |
| 539 | // x is too big, we cannnot reduce the 2*PI period |
| 540 | // prior to version 0.8.5 the result was zero |
| 541 | |
| 542 | // result has NaN flag set by default |
| 543 | |
| 544 | if( err ) |
| 545 | *err = err_overflow; // maybe another error code? err_improper_argument? |
| 546 | |
| 547 | return result; // NaN is set by default |
| 548 | } |
| 549 | |
| 550 | result = Sin0pi05( x ); |
| 551 | |
| 552 | one.SetOne(); |
| 553 | |
| 554 | // after calculations there can be small distortions in the result |
| 555 | if( result > one ) |
| 556 | result = one; |
| 557 | else |
| 558 | if( result.IsSign() ) |
| 559 | // we've calculated the sin from <0, pi/2> and the result |
| 560 | // should be positive |
| 561 | result.SetZero(); |
| 562 | |
| 563 | if( change_sign ) |
| 564 | result.ChangeSign(); |
| 565 | |
| 566 | return result; |
| 567 | } |
| 568 | |
| 569 | |
| 570 | /*! |
no test coverage detected