AOT計算で呼び出し自体を早くする三角関数
AOTTrigon.h@5:2a67061cea78, 2014-12-26 (annotated)
- Committer:
- kb10uy
- Date:
- Fri Dec 26 03:07:12 2014 +0000
- Revision:
- 5:2a67061cea78
- Parent:
- 4:c15b45812c25
- Child:
- 6:fddf871eba15
?????
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 | 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 | 4:c15b45812c25 | 10 | AOTTrigon(); |
kb10uy | 0:2888f1d9a23e | 11 | |
kb10uy | 3:ba78a1dd8b55 | 12 | inline double sin(double); |
kb10uy | 3:ba78a1dd8b55 | 13 | inline double cos(double); |
kb10uy | 3:ba78a1dd8b55 | 14 | inline double tan(double); |
kb10uy | 0:2888f1d9a23e | 15 | |
kb10uy | 0:2888f1d9a23e | 16 | private: |
kb10uy | 0:2888f1d9a23e | 17 | double *t_sin; |
kb10uy | 4:c15b45812c25 | 18 | const int division; |
kb10uy | 0:2888f1d9a23e | 19 | double rate; |
kb10uy | 3:ba78a1dd8b55 | 20 | const double pi; |
kb10uy | 1:f1e55d228f6a | 21 | }; |
kb10uy | 3:ba78a1dd8b55 | 22 | |
kb10uy | 3:ba78a1dd8b55 | 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 | 3:ba78a1dd8b55 | 27 | inline double AOTTrigon::cos(double x) |
kb10uy | 3:ba78a1dd8b55 | 28 | { |
kb10uy | 3:ba78a1dd8b55 | 29 | return sin(x + pi / 2.0); |
kb10uy | 3:ba78a1dd8b55 | 30 | } |
kb10uy | 3:ba78a1dd8b55 | 31 | inline double AOTTrigon::tan(double x) |
kb10uy | 3:ba78a1dd8b55 | 32 | { |
kb10uy | 3:ba78a1dd8b55 | 33 | return sin(x) / cos(x); |
kb10uy | 3:ba78a1dd8b55 | 34 | } |