| 357 | */ |
| 358 | template<class ValueType> |
| 359 | uint PrepareSin(ValueType & x, bool & change_sign) |
| 360 | { |
| 361 | ValueType temp; |
| 362 | |
| 363 | change_sign = false; |
| 364 | |
| 365 | if( x.IsSign() ) |
| 366 | { |
| 367 | // we're using the formula 'sin(-x) = -sin(x)' |
| 368 | change_sign = !change_sign; |
| 369 | x.ChangeSign(); |
| 370 | } |
| 371 | |
| 372 | // we're reducing the period 2*PI |
| 373 | // (for big values there'll always be zero) |
| 374 | temp.Set2Pi(); |
| 375 | |
| 376 | if( x.Mod(temp) ) |
| 377 | return 1; |
| 378 | |
| 379 | |
| 380 | // we're setting 'x' as being in the range of <0, 0.5PI> |
| 381 | |
| 382 | temp.SetPi(); |
| 383 | |
| 384 | if( x > temp ) |
| 385 | { |
| 386 | // x is in (pi, 2*pi> |
| 387 | x.Sub( temp ); |
| 388 | change_sign = !change_sign; |
| 389 | } |
| 390 | |
| 391 | temp.Set05Pi(); |
| 392 | |
| 393 | if( x > temp ) |
| 394 | { |
| 395 | // x is in (0.5pi, pi> |
| 396 | x.Sub( temp ); |
| 397 | x = temp - x; |
| 398 | } |
| 399 | |
| 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | |
| 404 | /*! |
no test coverage detected