Project

General

Profile

Statistics
| Revision:

root / proj / libs / utils / src / fast_math.c @ 352

History | View | Annotate | Download (861 Bytes)

1 178 up20180642
#include <lcom/lcf.h>
2
3 168 up20180642
#include "fast_math.h"
4 250 up20180655
#include "utils.h"
5 168 up20180642
6
#include <math.h>
7
8
double fm_sin(double x){
9
    if(x < 0.0)         return -fm_sin(-x);
10
    if(x > 2.0*M_PI) return fm_sin(x-2.0*M_PI);
11
    if(x > M_PI)      return -fm_sin(x-M_PI);
12
    if(x > 0.5*M_PI) x = M_PI - x;
13
    double x2 = x*x;
14
    double x3 = x*x2;
15
    double x5 = x3*x2;
16
    //double x7 = x5*x2;
17 170 up20180642
    return x-x3*0.1666666666666666666666+x5*0.008333333333333333333333;//-x7*0.0001984126984127;
18 168 up20180642
}
19
20
double fm_cos(double x){
21
    if(x < 0.0)         x = -x;
22
    if(x > 2.0*M_PI) return fm_cos(x-2.0*M_PI);
23
    if(x > M_PI)      x = 2.0*M_PI-x;
24
    if(x > 0.5*M_PI) return -fm_cos(M_PI-x);
25
    double x2 = x*x;
26
    double x4 = x2*x2;
27
    double x6 = x4*x2;
28
    //double x8 = x4*x4;
29 170 up20180642
    return 1.0-x2*0.5+x4*0.041666666666666666666666-x6*0.0013888888888888888888888;//+x8*0.000024801587;
30 168 up20180642
}