AOT計算で呼び出し自体を早くする三角関数
AOTTrigon.h@10:5bccb4bc4f33, 2014-12-29 (annotated)
- Committer:
- kb10uy
- Date:
- Mon Dec 29 08:58:51 2014 +0000
- Revision:
- 10:5bccb4bc4f33
- Parent:
- 9:d6153f6a5f75
- Child:
- 11:19594eeb6f2b
?????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kb10uy | 0:2888f1d9a23e | 1 | #pragma once |
kb10uy | 0:2888f1d9a23e | 2 | #include "math.h" |
kb10uy | 10:5bccb4bc4f33 | 3 | #include "mbed.h" |
kb10uy | 0:2888f1d9a23e | 4 | |
kb10uy | 0:2888f1d9a23e | 5 | /** AOTTrigon class |
kb10uy | 0:2888f1d9a23e | 6 | * AOT計算によって三角関数の計算を高速化します。 |
kb10uy | 0:2888f1d9a23e | 7 | */ |
kb10uy | 0:2888f1d9a23e | 8 | class AOTTrigon |
kb10uy | 0:2888f1d9a23e | 9 | { |
kb10uy | 0:2888f1d9a23e | 10 | public: |
kb10uy | 4:c15b45812c25 | 11 | AOTTrigon(); |
kb10uy | 0:2888f1d9a23e | 12 | |
kb10uy | 10:5bccb4bc4f33 | 13 | inline double sin(double); |
kb10uy | 10:5bccb4bc4f33 | 14 | inline double cos(double); |
kb10uy | 10:5bccb4bc4f33 | 15 | inline double tan(double); |
kb10uy | 0:2888f1d9a23e | 16 | |
kb10uy | 0:2888f1d9a23e | 17 | private: |
kb10uy | 10:5bccb4bc4f33 | 18 | double *t_sin; |
kb10uy | 10:5bccb4bc4f33 | 19 | double rate; |
kb10uy | 9:d6153f6a5f75 | 20 | const double pi; |
kb10uy | 1:f1e55d228f6a | 21 | }; |
kb10uy | 3:ba78a1dd8b55 | 22 | |
kb10uy | 10:5bccb4bc4f33 | 23 | inline double AOTTrigon::sin(double x) |
kb10uy | 3:ba78a1dd8b55 | 24 | { |
kb10uy | 4:c15b45812c25 | 25 | return t_sin[((int)(x * rate)) & 0xFF]; |
kb10uy | 3:ba78a1dd8b55 | 26 | } |
kb10uy | 8:b771ac4871bb | 27 | |
kb10uy | 10:5bccb4bc4f33 | 28 | inline double AOTTrigon::cos(double x) |
kb10uy | 3:ba78a1dd8b55 | 29 | { |
kb10uy | 7:eed80268ab34 | 30 | return sin(x + pi / 2.0f); |
kb10uy | 3:ba78a1dd8b55 | 31 | } |
kb10uy | 8:b771ac4871bb | 32 | |
kb10uy | 10:5bccb4bc4f33 | 33 | inline double AOTTrigon::tan(double x) |
kb10uy | 3:ba78a1dd8b55 | 34 | { |
kb10uy | 3:ba78a1dd8b55 | 35 | return sin(x) / cos(x); |
kb10uy | 3:ba78a1dd8b55 | 36 | } |