ファンクション・ジェネレータ
Dependencies: mbed SerialTxRxIntr MyTicker7 Array_Matrix
Diff: FastSin.hpp
- Revision:
- 0:17c762b41fc7
- Child:
- 1:ea5aa7f3d68c
diff -r 000000000000 -r 17c762b41fc7 FastSin.hpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FastSin.hpp Sat Oct 17 10:05:58 2020 +0000 @@ -0,0 +1,26 @@ +//----------------------------------------------------------- +// FastSin() 関数 +// sin(π/2)x) の値の計算 +// +// 2020/06/01, Copyright (c) 2020 MIKAMI, Naoki +//----------------------------------------------------------- + +#ifndef FASTSIN_POLYNOMIAL_HPP +#define FASTSIN_POLYNOMIAL_HPP + +namespace Mikami +{ + // 引数の範囲: -2 <= x <= 2 + inline float FastSin(float x) + { + static const float A1 = 1.570320019210f; + static const float A3 = -0.642113166941f; + static const float A5 = 0.071860854119f; + + if (x > 1.0f) x = 2.0f - x; + if (x < -1.0f) x = -2.0f - x; + float x2 = x*x; + return ((A5*x2 + A3)*x2 + A1)*x; + } +} +#endif // FASTSIN_POLYNOMIAL_HPP \ No newline at end of file