summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2012-05-16 10:13:17 +0000
committerCedric BAIL <cedric.bail@free.fr>2012-05-16 10:13:17 +0000
commit65f499648abf356619e43fac0393c5b29c82ab8e (patch)
tree1ae731a2d5bbf2274fc925f1443d6cbcf7ae39ee
parent48d9f440a9050c5c2b36ad9a14d6f39aba5640fa (diff)
eina: backport r71150.
SVN revision: 71151
-rw-r--r--src/lib/eina_fp.c56
1 files changed, 5 insertions, 51 deletions
diff --git a/src/lib/eina_fp.c b/src/lib/eina_fp.c
index d06bb08..ea1775c 100644
--- a/src/lib/eina_fp.c
+++ b/src/lib/eina_fp.c
@@ -465,68 +465,22 @@ eina_f32p32_cos(Eina_F32p32 a)
465 (Eina_F32p32)eina_f32p32_fracc_get( 465 (Eina_F32p32)eina_f32p32_fracc_get(
466 interpol))); 466 interpol)));
467 467
468 if (0 <= remainder_2PI && remainder_2PI < F32P32_PI2) 468 if (F32P32_PI2 < remainder_2PI && remainder_2PI < F32P32_3PI2)
469 return result; 469 result *= -1;
470 else if (F32P32_PI2 <= remainder_2PI && remainder_2PI < EINA_F32P32_PI) 470
471 return -result; 471 return result;
472 else if (EINA_F32P32_PI <= remainder_2PI && remainder_2PI < F32P32_3PI2)
473 return -result;
474 else /* if (F32P32_3PI2 <= remainder_2PI) */
475 return result;
476} 472}
477 473
478EAPI Eina_F32p32 474EAPI Eina_F32p32
479eina_f32p32_sin(Eina_F32p32 a) 475eina_f32p32_sin(Eina_F32p32 a)
480{ 476{
481 Eina_F32p32 F32P32_2PI;
482 Eina_F32p32 F32P32_PI2; 477 Eina_F32p32 F32P32_PI2;
483 Eina_F32p32 F32P32_3PI2;
484 Eina_F32p32 remainder_2PI;
485 Eina_F32p32 remainder_PI;
486 Eina_F32p32 interpol;
487 Eina_F32p32 result;
488 int idx;
489 int index2;
490 478
491 F32P32_2PI = EINA_F32P32_PI << 1;
492 F32P32_PI2 = EINA_F32P32_PI >> 1; 479 F32P32_PI2 = EINA_F32P32_PI >> 1;
493 F32P32_3PI2 = EINA_F32P32_PI + F32P32_PI2;
494 480
495 /* We only have a table for cosinus, but sin(a) = cos(pi / 2 - a) */ 481 /* We only have a table for cosinus, but sin(a) = cos(pi / 2 - a) */
496 a = eina_f32p32_sub(F32P32_PI2, a); 482 a = eina_f32p32_sub(F32P32_PI2, a);
497 483
498 /* Take advantage of cosinus symetrie. */ 484 return eina_f32p32_cos(a);
499 a = eina_fp32p32_llabs(a);
500
501 /* Find table entry in 0 to PI / 2 */
502 remainder_PI = a - (a / EINA_F32P32_PI) * EINA_F32P32_PI;
503
504 /* Find which case from 0 to 2 * PI */
505 remainder_2PI = a - (a / F32P32_2PI) * F32P32_2PI;
506
507 interpol = eina_f32p32_div(eina_f32p32_scale(remainder_PI, (MAX_PREC - 1) * 2),
508 EINA_F32P32_PI);
509 idx = eina_f32p32_int_to(interpol);
510 if (idx >= MAX_PREC)
511 idx = 2 * MAX_PREC - (idx + 1);
512
513 index2 = idx + 1;
514 if (index2 == MAX_PREC)
515 index2 = idx - 1;
516
517 result = eina_f32p32_add(eina_trigo[idx],
518 eina_f32p32_mul(eina_f32p32_sub(eina_trigo[idx],
519 eina_trigo[index2]),
520 (Eina_F32p32)eina_f32p32_fracc_get(
521 interpol)));
522
523 if (0 <= remainder_2PI && remainder_2PI < F32P32_PI2)
524 return result;
525 else if (F32P32_PI2 <= remainder_2PI && remainder_2PI < EINA_F32P32_PI)
526 return -result;
527 else if (EINA_F32P32_PI <= remainder_2PI && remainder_2PI < F32P32_3PI2)
528 return -result;
529 else /* if (F32P32_3PI2 <= remainder_2PI) */
530 return result;
531} 485}
532 486