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

Dependents:   NuMidi401 NuFM401

Committer:
kb10uy
Date:
Thu Dec 25 04:41:19 2014 +0000
Revision:
3:ba78a1dd8b55
Parent:
2:d8c9637a5f09
Child:
4:c15b45812c25
?????????????????; ??????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kb10uy 0:2888f1d9a23e 1 #pragma once
kb10uy 0:2888f1d9a23e 2 #include "math.h"
kb10uy 0:2888f1d9a23e 3
kb10uy 0:2888f1d9a23e 4 /** AOTTrigon class
kb10uy 0:2888f1d9a23e 5 * AOT計算によって三角関数の計算を高速化します。
kb10uy 0:2888f1d9a23e 6 */
kb10uy 0:2888f1d9a23e 7 class AOTTrigon
kb10uy 0:2888f1d9a23e 8 {
kb10uy 0:2888f1d9a23e 9 public:
kb10uy 0:2888f1d9a23e 10 /** AOTTrigon コンストラクター
kb10uy 0:2888f1d9a23e 11 * @param divide 分割数
kb10uy 0:2888f1d9a23e 12 */
kb10uy 0:2888f1d9a23e 13 AOTTrigon(int divide=256);
kb10uy 0:2888f1d9a23e 14
kb10uy 3:ba78a1dd8b55 15 inline double sin(double);
kb10uy 3:ba78a1dd8b55 16 inline double cos(double);
kb10uy 3:ba78a1dd8b55 17 inline double tan(double);
kb10uy 0:2888f1d9a23e 18
kb10uy 0:2888f1d9a23e 19 private:
kb10uy 0:2888f1d9a23e 20 double *t_sin;
kb10uy 0:2888f1d9a23e 21 int division;
kb10uy 0:2888f1d9a23e 22 double rate;
kb10uy 3:ba78a1dd8b55 23 const double pi;
kb10uy 1:f1e55d228f6a 24 };
kb10uy 3:ba78a1dd8b55 25
kb10uy 3:ba78a1dd8b55 26 inline double AOTTrigon::sin(double x)
kb10uy 3:ba78a1dd8b55 27 {
kb10uy 3:ba78a1dd8b55 28 return t_sin[((int)(x * rate)) & (division - 1)];
kb10uy 3:ba78a1dd8b55 29 }
kb10uy 3:ba78a1dd8b55 30 inline double AOTTrigon::cos(double x)
kb10uy 3:ba78a1dd8b55 31 {
kb10uy 3:ba78a1dd8b55 32 return sin(x + pi / 2.0);
kb10uy 3:ba78a1dd8b55 33 }
kb10uy 3:ba78a1dd8b55 34 inline double AOTTrigon::tan(double x)
kb10uy 3:ba78a1dd8b55 35 {
kb10uy 3:ba78a1dd8b55 36 return sin(x) / cos(x);
kb10uy 3:ba78a1dd8b55 37 }