AOT計算で呼び出し自体を早くする三角関数

Dependents:   NuMidi401 NuFM401

AOTTrigon.h

Committer:
kb10uy
Date:
2014-12-29
Revision:
10:5bccb4bc4f33
Parent:
9:d6153f6a5f75
Child:
11:19594eeb6f2b

File content as of revision 10:5bccb4bc4f33:

#pragma once
#include "math.h"
#include "mbed.h"

/** AOTTrigon class
 * AOT計算によって三角関数の計算を高速化します。
 */
class AOTTrigon
{
public:
    AOTTrigon();

    inline double sin(double);
    inline double cos(double);
    inline double tan(double);

private:
    double *t_sin;
    double rate;
    const double pi;
};

inline double AOTTrigon::sin(double x)
{
    return t_sin[((int)(x * rate)) & 0xFF];
}

inline double AOTTrigon::cos(double x)
{
    return sin(x + pi / 2.0f);
}

inline double AOTTrigon::tan(double x)
{
    return sin(x) / cos(x);
}