add FE_cos, FE_sin ad optimize

This commit is contained in:
util1 2019-07-21 16:32:43 +02:00
parent 556195cb4b
commit 29e1df611d
3 changed files with 56 additions and 0 deletions

View File

@ -1,4 +1,5 @@
#include "FxEngine.h"
#include <libprof.h>
#include <display.h>

View File

@ -0,0 +1,43 @@
#include "functions.h"
static const double pi2=pi*2;
static const double pi_sur2=pi/2;
// cos (0<x<pi/2)
static double reducted_cos(const double& a)
{
double u=1.0;
double a2=a*a;
// p doit toujours être un nombre impair >1
for(int p=13;p>=1;p-=2)
u=1-a2/(p*p+p)*u;
return u;
}
static void modulo_2pi(double& a)
{
while (a<=-pi2) a+=pi2;
while (a>pi2) a-=pi2;
return a;
}
double FE_cos(double angle)
{
modulo_2pi(angle);
int angle_arrondi=(int)(angle/pi_sur2);
switch (angle_arrondi)
{
case -2:
case 1:
return -reducted_cos(angle);
case -1:
case 0:
return reducted_cos(angle);
}
}
double FE_sin(double angle)
{
return FE_cos(angle-pi_sur2);
}

View File

@ -0,0 +1,12 @@
#ifndef FE_FUNCTIONS_H
#define FE_FUNCTIONS_H
const extern double pi=3.141592653589793238462643383279
double FE_cos(double angle);
double FE_sin(double angle);
#endif