provide trigonometric functions with LUT.
Revision 1:825f5c2e80b4, committed 2015-03-23
- Comitter:
- kb10uy
- Date:
- Mon Mar 23 11:20:09 2015 +0000
- Parent:
- 0:5472db659233
- Commit message:
- double/float????;
Changed in this revision
LUTTrigonometric.cpp | Show annotated file Show diff for this revision Revisions of this file |
LUTTrigonometric.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 5472db659233 -r 825f5c2e80b4 LUTTrigonometric.cpp --- a/LUTTrigonometric.cpp Sat Mar 21 08:36:18 2015 +0000 +++ b/LUTTrigonometric.cpp Mon Mar 23 11:20:09 2015 +0000 @@ -1,1 +1,24 @@ -#include "LUTTrigonometric.h" \ No newline at end of file +#include "LUTTrigonometric.h" + +LUTTrigonometric::LUTTrigonometric(int division): pi(3.1415926535897932384626433832795) { + div = division; + rate = division / pi / 2.0; + table = new double[div]; + for(int i = 0; i < div; i++) table[i] = ::sin(pi * 2.0 / rate * i); +} + +LUTTrigonometric::~LUTTrigonometric() { + delete[] table; +} + + +LUTSingleTrigonometric::LUTSingleTrigonometric(int division): pi(3.1415926535f) { + div = division; + rate = division / pi / 2.0f; + table = new float[div]; + for(int i = 0; i < div; i++) table[i] = (float)::sin(pi * 2.0f / rate * i); +} + +LUTSingleTrigonometric::~LUTSingleTrigonometric() { + delete[] table; +} \ No newline at end of file
diff -r 5472db659233 -r 825f5c2e80b4 LUTTrigonometric.h --- a/LUTTrigonometric.h Sat Mar 21 08:36:18 2015 +0000 +++ b/LUTTrigonometric.h Mon Mar 23 11:20:09 2015 +0000 @@ -1,1 +1,65 @@ -#pragma once \ No newline at end of file +#pragma once + +#include "math.h" + +//double precision version + +class LUTTrigonometric +{ +public: + LUTTrigonometric(int division = 256); + + inline double sin(double x); + inline double cos(double x); + inline double tan(double x); + +private: + double *table; + int div; + const double pi; + double rate; +}; + +double LUTTrigonometric::sin(double x) { + return table[(int)(x * rate) % div]; +} + + +double LUTTrigonometric::cos(double x) { + return table[(int)((x + pi / 2.0) * rate) % div]; +} + +double LUTTrigonometric::tan(double x) { + return sin(x) / cos(x); +} + +//single precision version + +class LUTSingleTrigonometric +{ +public: + LUTSingleTrigonometric(int division = 256); + + inline float sin(float x); + inline float cos(float x); + inline float tan(float x); + +private: + float *table; + int div; + const float pi; + float rate; +}; + +float LUTSingleTrigonometric::sin(float x) { + return table[(int)(x * rate) % div]; +} + + +float LUTSingleTrigonometric::cos(float x) { + return table[(int)((x + pi / 2.0) * rate) % div]; +} + +float LUTSingleTrigonometric::tan(float x) { + return sin(x) / cos(x); +}