1
Dependencies: mbed-dev-f303 FastPWM3
FastMath/FastMath.cpp@56:d34e4540ec12, 2020-08-14 (annotated)
- Committer:
- Jasper_gu
- Date:
- Fri Aug 14 07:22:11 2020 +0000
- Revision:
- 56:d34e4540ec12
- Parent:
- 51:b0a3ef66ea3d
uuuu
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
benkatz | 0:4e1c4df6aabd | 1 | #include "FastMath.h" |
benkatz | 0:4e1c4df6aabd | 2 | #include "LUT.h" |
benkatz | 0:4e1c4df6aabd | 3 | |
benkatz | 0:4e1c4df6aabd | 4 | const float Multiplier = 81.4873308631f; |
benkatz | 0:4e1c4df6aabd | 5 | |
benkatz | 0:4e1c4df6aabd | 6 | float FastMath::FastSin(float theta){ |
benkatz | 20:bf9ea5125d52 | 7 | while (theta < 0.0f) theta += 6.28318530718f; |
benkatz | 20:bf9ea5125d52 | 8 | while (theta >= 6.28318530718f) theta -= 6.28318530718f; |
benkatz | 0:4e1c4df6aabd | 9 | return SinTable[(int) (Multiplier*theta)] ; |
benkatz | 0:4e1c4df6aabd | 10 | } |
benkatz | 0:4e1c4df6aabd | 11 | |
benkatz | 0:4e1c4df6aabd | 12 | float FastMath::FastCos(float theta){ |
benkatz | 0:4e1c4df6aabd | 13 | return FastSin(1.57079632679f - theta); |
Rushu | 51:b0a3ef66ea3d | 14 | } |
Rushu | 51:b0a3ef66ea3d | 15 | //========HJB added=====// |
Rushu | 51:b0a3ef66ea3d | 16 | int FastMath::Sgn(float d){ |
Rushu | 51:b0a3ef66ea3d | 17 | if(d<0) return -1; |
Rushu | 51:b0a3ef66ea3d | 18 | else if (d==0) return 0; |
Rushu | 51:b0a3ef66ea3d | 19 | else return 1; |
benkatz | 0:4e1c4df6aabd | 20 | } |