├── Library ├── Include │ └── Fixie │ │ ├── Config.h │ │ ├── Util.h │ │ ├── TransformFactory.h │ │ ├── Trig.h │ │ ├── Quaternion.h │ │ ├── Matrix4.h │ │ ├── Vector3.h │ │ └── Num.h └── Source │ ├── Quaternion.cpp │ ├── TransformFactory.cpp │ ├── Util.cpp │ ├── Matrix4.cpp │ ├── Vector3.cpp │ └── Trig.cpp ├── README.md ├── Test ├── main.cpp ├── QuaternionTest.h ├── UtilTest.h ├── Matrix4Test.h ├── TrigTest.h ├── Orwell.h ├── Vector3Test.h └── NumTest.h ├── Tools ├── Constants.cpp ├── Makefile ├── ArcCosineTable.cpp ├── SineTable.cpp └── CosineTable.cpp └── Makefile /Library/Include/Fixie/Config.h: -------------------------------------------------------------------------------- 1 | #ifndef FIXIE_CONFIG_H 2 | #define FIXIE_CONFIG_H 3 | 4 | namespace Fixie { 5 | namespace Config { 6 | const uint8_t fractionBits = 10; 7 | } 8 | } 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /Library/Include/Fixie/Util.h: -------------------------------------------------------------------------------- 1 | #ifndef FIXIE_UTIL_H 2 | #define FIXIE_UTIL_H 3 | 4 | #include "Fixie/Num.h" 5 | 6 | namespace Fixie { 7 | namespace Util { 8 | Num halve(Num n); 9 | Num floor(Num n); 10 | Num sqrt(Num n); 11 | } 12 | } 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /Library/Include/Fixie/TransformFactory.h: -------------------------------------------------------------------------------- 1 | #ifndef FIXIE_TRANSFORM_FACTORY_H 2 | #define FIXIE_TRANSFORM_FACTORY_H 3 | 4 | #include "Fixie/Vector3.h" 5 | #include "Fixie/Matrix4.h" 6 | 7 | namespace Fixie { 8 | namespace TransformFactory { 9 | Matrix4 translation(Vector3 translation); 10 | } 11 | } 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /Library/Include/Fixie/Trig.h: -------------------------------------------------------------------------------- 1 | #ifndef FIXIE_TRIG_H 2 | #define FIXIE_TRIG_H 3 | 4 | namespace Fixie { 5 | namespace Trig { 6 | extern const Num pi; 7 | extern const Num twoPi; 8 | extern const Num halfPi; 9 | extern const Num inverseTwoPi; 10 | 11 | Num sin(Num n); 12 | Num cos(Num n); 13 | Num acos(Num n); 14 | } 15 | } 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /Library/Source/Quaternion.cpp: -------------------------------------------------------------------------------- 1 | #include "Fixie/Quaternion.h" 2 | 3 | namespace Fixie { 4 | Quaternion::Quaternion() { } 5 | 6 | Quaternion::Quaternion(Num real, Vector3 imaginaries) { 7 | this->real = real; 8 | this->imaginaries = imaginaries; 9 | } 10 | 11 | Quaternion Quaternion::identity() { 12 | return Quaternion(1, Vector3(0, 0, 0)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fixie 2 | 3 | Fixie is a fixed point math library for C++. It's purpose is primarily to enable determistic real number arithmetic in a way that works cross platform. 4 | 5 | Features: 6 | 7 | - Basic arithmetic operators 8 | - `sin`, `cos`, `acos`, `sqrt`, and `floor` 9 | - Basic `Vector4`, `Matrix4` (4x4), and `Quaternion` 10 | 11 | Please see `Test` dir for examples. 12 | -------------------------------------------------------------------------------- /Library/Source/TransformFactory.cpp: -------------------------------------------------------------------------------- 1 | #include "Fixie/TransformFactory.h" 2 | 3 | namespace Fixie { 4 | namespace TransformFactory { 5 | Matrix4 translation(Vector3 translation) { 6 | Matrix4 matrix = Matrix4::identity(); 7 | matrix[12] = translation[0]; 8 | matrix[13] = translation[1]; 9 | matrix[14] = translation[2]; 10 | return matrix; 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Library/Include/Fixie/Quaternion.h: -------------------------------------------------------------------------------- 1 | #ifndef FIXIE_QUATERNION_H 2 | #define FIXIE_QUATERNION_H 3 | 4 | #include "Fixie/Num.h" 5 | #include "Fixie/Vector3.h" 6 | 7 | namespace Fixie { 8 | class Quaternion { 9 | public: 10 | Quaternion(); 11 | Quaternion(Num real, Vector3 imaginaries); 12 | Num real; 13 | Vector3 imaginaries; 14 | static Quaternion identity(); 15 | }; 16 | } 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /Test/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Orwell.h" 2 | #include "NumTest.h" 3 | #include "TrigTest.h" 4 | #include "UtilTest.h" 5 | #include "Vector3Test.h" 6 | #include "Matrix4Test.h" 7 | #include "QuaternionTest.h" 8 | 9 | int main() { 10 | NumTest::setup(); 11 | TrigTest::setup(); 12 | UtilTest::setup(); 13 | Vector3Test::setup(); 14 | Matrix4Test::setup(); 15 | QuaternionTest::setup(); 16 | Orwell::start(); 17 | } 18 | -------------------------------------------------------------------------------- /Tools/Constants.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "Fixie/Num.h" 5 | 6 | int main() { 7 | const Fixie::Num pi = M_PI; 8 | const Fixie::Num twoPi = M_PI*2; 9 | const Fixie::Num halfPi = M_PI*0.5; 10 | const Fixie::Num inverseTwoPi = 1.0 / (M_PI*2.0); 11 | 12 | printf("pi: %d\n", pi.raw); 13 | printf("twoPi: %d\n", twoPi.raw); 14 | printf("halfPi: %d\n", halfPi.raw); 15 | printf("inverseTwoPi: %d\n", inverseTwoPi.raw); 16 | } 17 | -------------------------------------------------------------------------------- /Library/Source/Util.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Fixie/Util.h" 3 | 4 | namespace Fixie { 5 | namespace Util { 6 | Num halve(Num n) { 7 | return Num::createByRaw(n.raw >> 1); 8 | } 9 | 10 | Num floor(Num n) { 11 | n.raw &= 0xfffffc00; 12 | return n; 13 | } 14 | 15 | Num sqrt(Num n) { 16 | assert(n >= Num(0)); 17 | Num s = halve(n); 18 | for(uint8_t i=0; i<6; ++i) { 19 | s = halve(s + n/s); 20 | } 21 | return s; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Tools/Makefile: -------------------------------------------------------------------------------- 1 | sine: 2 | clang++ -std=c++11 -Wall -Wno-c++11-extensions -I../Library/Include SineTable.cpp 3 | ./a.out 4 | rm ./a.out 5 | 6 | cosine: 7 | clang++ -std=c++11 -Wall -Wno-c++11-extensions -I../Library/Include CosineTable.cpp 8 | ./a.out 9 | rm ./a.out 10 | 11 | arccosine: 12 | clang++ -std=c++11 -Wall -Wno-c++11-extensions -I../Library/Include ArcCosineTable.cpp 13 | ./a.out 14 | rm ./a.out 15 | 16 | constants: 17 | clang++ -std=c++11 -Wall -Wno-c++11-extensions -I../Library/Include Constants.cpp 18 | ./a.out 19 | rm ./a.out 20 | -------------------------------------------------------------------------------- /Tools/ArcCosineTable.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "Fixie/Num.h" 5 | 6 | int main() { 7 | static const uint16_t precision = 1024; 8 | for(uint16_t i=0, j=1; i(i)/1024.0)*2-1; 10 | double arcCosine = acos(input); 11 | Fixie::Num num = arcCosine; 12 | printf("%d,", num.raw); 13 | if(i != precision-1) { 14 | if(j != 8) { 15 | printf(" "); 16 | } else { 17 | j = 0; 18 | printf("\n"); 19 | } 20 | } 21 | } 22 | printf("\n0\n"); 23 | } 24 | -------------------------------------------------------------------------------- /Tools/SineTable.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "Fixie/Num.h" 5 | 6 | int main() { 7 | static const uint16_t degress = 1024; 8 | for(uint16_t i=0, j=1; i(i)/degress) * 2 * M_PI; 10 | double sine = sin(angle); 11 | Fixie::Num num = sine; 12 | printf("%d", num.raw); 13 | if(i != degress-1) { 14 | printf(","); 15 | if(j != 8) { 16 | printf(" "); 17 | } else { 18 | j = 0; 19 | printf("\n"); 20 | } 21 | } 22 | } 23 | printf("\n"); 24 | } 25 | -------------------------------------------------------------------------------- /Tools/CosineTable.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "Fixie/Num.h" 5 | 6 | int main() { 7 | static const uint16_t degress = 1024; 8 | for(uint16_t i=0, j=1; i(i)/degress) * 2 * M_PI; 10 | double cosine = cos(angle); 11 | Fixie::Num num = cosine; 12 | printf("%d", num.raw); 13 | if(i != degress-1) { 14 | printf(","); 15 | if(j != 8) { 16 | printf(" "); 17 | } else { 18 | j = 0; 19 | printf("\n"); 20 | } 21 | } 22 | } 23 | printf("\n"); 24 | } 25 | -------------------------------------------------------------------------------- /Library/Include/Fixie/Matrix4.h: -------------------------------------------------------------------------------- 1 | #ifndef FIXIE_MATRIX4_H 2 | #define FIXIE_MATRIX4_H 3 | 4 | #include "Fixie/Num.h" 5 | 6 | namespace Fixie { 7 | class Matrix4 { 8 | public: 9 | Matrix4( 10 | Num c0, 11 | Num c1, 12 | Num c2, 13 | Num c3, 14 | Num c4, 15 | Num c5, 16 | Num c6, 17 | Num c7, 18 | Num c8, 19 | Num c9, 20 | Num c10, 21 | Num c11, 22 | Num c12, 23 | Num c13, 24 | Num c14, 25 | Num c15 26 | ); 27 | Matrix4(); 28 | Num& operator[](const int index); 29 | const Num& operator[](const int index) const; 30 | Matrix4 operator*(Matrix4 other); 31 | Matrix4& operator*=(Matrix4 other); 32 | static Matrix4 identity(); 33 | void reset(); 34 | private: 35 | Num components[16]; 36 | }; 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /Test/QuaternionTest.h: -------------------------------------------------------------------------------- 1 | #include "Orwell.h" 2 | #include "Fixie/Quaternion.h" 3 | 4 | namespace QuaternionTest { 5 | using namespace Orwell::Assertions; 6 | using namespace Fixie; 7 | 8 | void testInit() { 9 | Quaternion q(1, { 2, 3, 4 }); 10 | assertEqual(1, q.real); 11 | assertEqual(2, q.imaginaries[0]); 12 | assertEqual(3, q.imaginaries[1]); 13 | assertEqual(4, q.imaginaries[2]); 14 | } 15 | 16 | void testIdentity() { 17 | Quaternion q = Quaternion::identity(); 18 | assertEqual(1, q.real); 19 | assertEqual(0, q.imaginaries[0]); 20 | assertEqual(0, q.imaginaries[1]); 21 | assertEqual(0, q.imaginaries[2]); 22 | } 23 | 24 | void setup() { 25 | unsigned group = Orwell::createGroup("FixieQuaternionTest"); 26 | Orwell::addTest(group, testInit, "Init"); 27 | Orwell::addTest(group, testIdentity, "Identity"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Test/UtilTest.h: -------------------------------------------------------------------------------- 1 | #include "Orwell.h" 2 | #include "Fixie/Util.h" 3 | 4 | namespace UtilTest { 5 | using namespace Orwell::Assertions; 6 | using namespace Fixie; 7 | 8 | void testFloor() { 9 | Num a; 10 | 11 | a = Util::floor(2.5); 12 | assertEqual(2, a); 13 | 14 | a = Util::floor(9.9); 15 | assertEqual(9, a); 16 | 17 | a = Util::floor(-2.3); 18 | assertEqual(-3, a); 19 | } 20 | 21 | void testSqrt() { 22 | Num a; 23 | 24 | a = Util::sqrt(25); 25 | assertEqual(5, a); 26 | 27 | a = Util::sqrt(2); 28 | assertInDelta(1.4142, 0.001, a); 29 | 30 | a = Util::sqrt(99); 31 | assertInDelta(9.9498, 0.001, a); 32 | } 33 | 34 | void setup() { 35 | unsigned group = Orwell::createGroup("FixieUtilTest"); 36 | Orwell::addTest(group, testFloor, "floor"); 37 | Orwell::addTest(group, testSqrt, "sqrt"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | NAME = Flowstone 2 | 3 | CC = clang++ 4 | CPP_CFLAGS = -Wall -std=gnu++11 -stdlib=libc++ -ferror-limit=1 5 | 6 | BUILD_DIR = ./Build 7 | 8 | TEST_SOURCES =\ 9 | Library/Source/Trig.cpp\ 10 | Library/Source/Util.cpp\ 11 | Library/Source/Vector3.cpp\ 12 | Library/Source/Matrix4.cpp\ 13 | Library/Source/Quaternion.cpp\ 14 | Test/main.cpp 15 | 16 | TEST_HEADER_DIRS =\ 17 | -ILibrary/Include\ 18 | 19 | TEST_OBJECTS = $(patsubst %.cpp,$(BUILD_DIR)/Objects/Test/%.o,$(TEST_SOURCES)) 20 | 21 | TEST_EXECUTABLE_PATH = $(BUILD_DIR)/Test 22 | 23 | test: $(TEST_EXECUTABLE_PATH) 24 | $(TEST_EXECUTABLE_PATH) 25 | 26 | $(TEST_EXECUTABLE_PATH): $(TEST_OBJECTS) 27 | $(CC) $(CFLAGS) $(TEST_HEADER_DIRS) $(TEST_OBJECTS) -o $@ 28 | 29 | $(BUILD_DIR)/Objects/Test/%.o : %.cpp 30 | mkdir -p $(dir $@) 31 | $(CC) $(CPP_CFLAGS) $(TEST_HEADER_DIRS) $< -c -o $@ 32 | 33 | clean: 34 | rm -rf ./Build 35 | -------------------------------------------------------------------------------- /Library/Include/Fixie/Vector3.h: -------------------------------------------------------------------------------- 1 | #ifndef FIXIE_VECTOR3_H 2 | #define FIXIE_VECTOR3_H 3 | 4 | #include "Fixie/Num.h" 5 | 6 | namespace Fixie { 7 | class Vector3 { 8 | public: 9 | Vector3(Num x, Num y, Num z); 10 | Vector3(); 11 | Num& operator[](const int index); 12 | const Num& operator[](const int index) const; 13 | Vector3 operator+(Vector3 other); 14 | Vector3& operator+=(Vector3 other); 15 | Vector3 operator-(Vector3 other); 16 | Vector3& operator-=(Vector3 other); 17 | Vector3 operator*(Num divisor); 18 | Vector3& operator*=(Num divisor); 19 | Vector3 operator/(Num divisor); 20 | Vector3& operator/=(Num divisor); 21 | Num calcLength() const; 22 | Num calcSquaredLength() const; 23 | void reset(); 24 | static Num dot(Vector3 a, Vector3 b); 25 | static Vector3 cross(Vector3 a, Vector3 b); 26 | static Vector3 normalize(Vector3 v); 27 | private: 28 | Num components[3]; 29 | }; 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Test/Matrix4Test.h: -------------------------------------------------------------------------------- 1 | #include "Orwell.h" 2 | #include "Fixie/Matrix4.h" 3 | 4 | namespace Matrix4Test { 5 | using namespace Orwell::Assertions; 6 | using namespace Fixie; 7 | 8 | void testSetGet() { 9 | Matrix4 m; 10 | m[0] = 3; 11 | assertEqual(3, m[0]); 12 | 13 | m[1] = -6; 14 | assertEqual(-6, m[1]); 15 | 16 | m[2] = 5.4; 17 | assertInDelta(5.4, 0.002, m[2]); 18 | 19 | m[3] = 0; 20 | assertEqual(0, m[3]); 21 | 22 | m[4] = Num(99); 23 | assertEqual(99, m[4]); 24 | } 25 | 26 | void testIdentity() { 27 | Matrix4 m = Matrix4::identity(); 28 | assertEqual(1, m[0]); 29 | assertEqual(0, m[1]); 30 | assertEqual(0, m[2]); 31 | assertEqual(0, m[3]); 32 | assertEqual(0, m[4]); 33 | assertEqual(1, m[5]); 34 | assertEqual(0, m[6]); 35 | assertEqual(0, m[7]); 36 | assertEqual(0, m[8]); 37 | assertEqual(0, m[9]); 38 | assertEqual(1, m[10]); 39 | assertEqual(0, m[11]); 40 | assertEqual(0, m[12]); 41 | assertEqual(0, m[13]); 42 | assertEqual(0, m[14]); 43 | assertEqual(1, m[15]); 44 | } 45 | 46 | void testMultiplication() { 47 | Matrix4 a(4, 64, 5, 8, 87, 32, -1, 2, 2, 8, 4, 0, 3, -5, 9, 1); 48 | Matrix4 b(23, 5, 5, 3, 4, 7, 44, 3, 9, 5, -9, 7, 7, 6, 0, 5); 49 | Matrix4 r = a*b; 50 | 51 | assertEqual(546, r[0]); 52 | assertEqual(1657, r[1]); 53 | assertEqual(157, r[2]); 54 | assertEqual(197, r[3]); 55 | assertEqual(722, r[4]); 56 | assertEqual(817, r[5]); 57 | assertEqual(216, r[6]); 58 | assertEqual(49, r[7]); 59 | assertEqual(474, r[8]); 60 | assertEqual(629, r[9]); 61 | assertEqual(67, r[10]); 62 | assertEqual(89, r[11]); 63 | assertEqual(565, r[12]); 64 | assertEqual(615, r[13]); 65 | assertEqual(74, r[14]); 66 | assertEqual(73, r[15]); 67 | } 68 | 69 | void setup() { 70 | unsigned group = Orwell::createGroup("FixieMatrix4Test"); 71 | Orwell::addTest(group, testSetGet, "SetGet"); 72 | Orwell::addTest(group, testIdentity, "Identity"); 73 | Orwell::addTest(group, testMultiplication, "Multiplication"); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Test/TrigTest.h: -------------------------------------------------------------------------------- 1 | #include "Orwell.h" 2 | #include "Fixie/Trig.h" 3 | 4 | namespace TrigTest { 5 | using namespace Orwell::Assertions; 6 | using namespace Fixie; 7 | 8 | void testConstants() { 9 | assertInDelta(3.1415, 0.005, Trig::pi); 10 | assertInDelta(6.2831, 0.005, Trig::twoPi); 11 | } 12 | 13 | void testSine() { 14 | Num n; 15 | 16 | n = Trig::sin(0); 17 | assertEqual(0, n); 18 | 19 | n = Trig::sin(Trig::pi); 20 | assertEqual(0, n); 21 | 22 | n = Trig::sin(Trig::twoPi); 23 | assertEqual(0, n); 24 | 25 | n = Trig::sin(0.3); 26 | assertInDelta(0.2955, 0.01, n); 27 | 28 | n = Trig::sin(-0.3); 29 | assertInDelta(-0.2955, 0.01, n); 30 | 31 | n = Trig::sin(30); 32 | assertInDelta(-0.9880, 0.01, n); 33 | 34 | n = Trig::sin(-100); 35 | assertInDelta(0.5064, 0.01, n); 36 | } 37 | 38 | void testCosine() { 39 | Num n; 40 | 41 | n = Trig::cos(0); 42 | assertEqual(1, n); 43 | 44 | n = Trig::cos(Trig::pi); 45 | assertEqual(-1, n); 46 | 47 | n = Trig::cos(Trig::twoPi); 48 | assertEqual(1, n); 49 | 50 | n = Trig::cos(0.3); 51 | assertInDelta(0.95533, 0.01, n); 52 | 53 | n = Trig::cos(-0.3); 54 | assertInDelta(0.95533, 0.01, n); 55 | 56 | n = Trig::cos(30); 57 | assertInDelta(0.15425, 0.01, n); 58 | 59 | n = Trig::cos(-122); 60 | assertInDelta(-0.86676, 0.01, n); 61 | } 62 | 63 | void testArcCosine() { 64 | Num a; 65 | 66 | a = Trig::acos(-1); 67 | assertInDelta(Trig::pi, 0.01, a); 68 | 69 | a = Trig::acos(0); 70 | assertInDelta(Trig::halfPi, 0.01, a); 71 | 72 | a = Trig::acos(1); 73 | assertEqual(0, a); 74 | 75 | a = Trig::acos(0.5); 76 | assertInDelta(1.04719, 0.01, a); 77 | 78 | a = Trig::acos(0.7); 79 | assertInDelta(0.79539, 0.01, a); 80 | } 81 | 82 | void setup() { 83 | unsigned group = Orwell::createGroup("FixieTrigTest"); 84 | Orwell::addTest(group, testConstants, "Constants"); 85 | Orwell::addTest(group, testSine, "Sine"); 86 | Orwell::addTest(group, testCosine, "Cosine"); 87 | Orwell::addTest(group, testArcCosine, "ArcCosine"); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Library/Source/Matrix4.cpp: -------------------------------------------------------------------------------- 1 | #include "Fixie/Matrix4.h" 2 | 3 | namespace Fixie { 4 | Matrix4::Matrix4( 5 | Num c0, 6 | Num c1, 7 | Num c2, 8 | Num c3, 9 | Num c4, 10 | Num c5, 11 | Num c6, 12 | Num c7, 13 | Num c8, 14 | Num c9, 15 | Num c10, 16 | Num c11, 17 | Num c12, 18 | Num c13, 19 | Num c14, 20 | Num c15 21 | ) { 22 | components[0] = c0; 23 | components[1] = c1; 24 | components[2] = c2; 25 | components[3] = c3; 26 | components[4] = c4; 27 | components[5] = c5; 28 | components[6] = c6; 29 | components[7] = c7; 30 | components[8] = c8; 31 | components[9] = c9; 32 | components[10] = c10; 33 | components[11] = c11; 34 | components[12] = c12; 35 | components[13] = c13; 36 | components[14] = c14; 37 | components[15] = c15; 38 | } 39 | 40 | Matrix4::Matrix4() { } 41 | 42 | Num& Matrix4::operator[](const int index) { 43 | return components[index]; 44 | } 45 | 46 | const Num& Matrix4::operator[](const int index) const { 47 | return components[index]; 48 | } 49 | 50 | void Matrix4::reset() { 51 | for(uint8_t i=0; i<16; ++i) { 52 | components[i] = 0; 53 | } 54 | } 55 | 56 | Matrix4 Matrix4::operator*(Matrix4 vector) { 57 | Matrix4 result = *this; 58 | result *= vector; 59 | return result; 60 | } 61 | 62 | Matrix4& Matrix4::operator*=(Matrix4 other) { 63 | Matrix4 original = *this; 64 | reset(); 65 | 66 | int resultIndex; 67 | for(int row=0; 4>row; row++) { 68 | for(int column=0; 4>column; column++) { 69 | resultIndex = column*4+row; 70 | for(int step=0; 4>step; step++) { 71 | components[resultIndex] += original[row+step*4] * other[column*4+step]; 72 | } 73 | } 74 | } 75 | 76 | return *this; 77 | } 78 | 79 | Matrix4 Matrix4::identity() { 80 | Matrix4 matrix; 81 | 82 | matrix[0] = 1; 83 | matrix[1] = 0; 84 | matrix[2] = 0; 85 | matrix[3] = 0; 86 | matrix[4] = 0; 87 | matrix[5] = 1; 88 | matrix[6] = 0; 89 | matrix[7] = 0; 90 | matrix[8] = 0; 91 | matrix[9] = 0; 92 | matrix[10] = 1; 93 | matrix[11] = 0; 94 | matrix[12] = 0; 95 | matrix[13] = 0; 96 | matrix[14] = 0; 97 | matrix[15] = 1; 98 | 99 | return matrix; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /Test/Orwell.h: -------------------------------------------------------------------------------- 1 | #ifndef ORWELL_H 2 | #define ORWELL_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Orwell { 9 | const static unsigned maxNameLength = 32; 10 | const static unsigned maxGroups = 32; 11 | char groupNames[maxGroups][maxNameLength]; 12 | unsigned groupCount = 0; 13 | 14 | typedef void (*TestFunction)(); 15 | const static unsigned maxTests = 1024; 16 | TestFunction testFunctions[maxTests]; 17 | char testNames[maxTests][maxNameLength]; 18 | unsigned testSuites[maxTests]; 19 | unsigned testFunctionsCount = 0; 20 | 21 | unsigned createGroup(const char *name) { 22 | assert(groupCount != maxGroups); 23 | strncpy(groupNames[groupCount], name, maxNameLength); 24 | return groupCount++; 25 | } 26 | 27 | unsigned currentTest; 28 | 29 | void addTest(unsigned group, TestFunction func, const char *name) { 30 | assert(testFunctionsCount != maxTests); 31 | strncpy(testNames[testFunctionsCount], name, maxNameLength); 32 | testFunctions[testFunctionsCount] = func; 33 | testSuites[testFunctionsCount] = group; 34 | testFunctionsCount++; 35 | } 36 | 37 | void start() { 38 | for(currentTest=0; testFunctionsCount>currentTest; currentTest++) { 39 | testFunctions[currentTest](); 40 | } 41 | printf("Orwell done.\n"); 42 | } 43 | 44 | void reportFailure(const char *failure) { 45 | unsigned group = testSuites[currentTest]; 46 | printf("%s::%s\n", groupNames[group], testNames[currentTest]); 47 | printf("%s\n\n", failure); 48 | } 49 | 50 | namespace Assertions { 51 | void assertEqual(int32_t expected, int32_t actual) { 52 | if(actual != expected) { 53 | char message[64]; 54 | sprintf(message, "%d was not %d.", actual, expected); 55 | reportFailure(message); 56 | } 57 | } 58 | 59 | void assertInDelta(double expected, double delta, double actual) { 60 | if(expected-delta > actual || expected+delta < actual) { 61 | char message[256]; 62 | sprintf(message, "%f was not within %f+-%f.", actual, expected, delta); 63 | reportFailure(message); 64 | } 65 | } 66 | 67 | void assertFalse(bool result) { 68 | if(result != false) { 69 | char message[64]; 70 | sprintf(message, "%d was not false.", result); 71 | reportFailure(message); 72 | } 73 | } 74 | 75 | void assertTrue(bool result) { 76 | if(result != true) { 77 | char message[64]; 78 | sprintf(message, "%d was not true.", result); 79 | reportFailure(message); 80 | } 81 | } 82 | } 83 | } 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /Library/Source/Vector3.cpp: -------------------------------------------------------------------------------- 1 | #include "Fixie/Util.h" 2 | #include "Fixie/Vector3.h" 3 | 4 | namespace Fixie { 5 | Vector3::Vector3() { } 6 | 7 | Vector3::Vector3(Num x, Num y, Num z) { 8 | components[0] = x; 9 | components[1] = y; 10 | components[2] = z; 11 | } 12 | 13 | Num& Vector3::operator[](const int index) { 14 | return components[index]; 15 | } 16 | 17 | const Num& Vector3::operator[](const int index) const { 18 | return components[index]; 19 | } 20 | 21 | Vector3 Vector3::operator+(Vector3 vector) { 22 | Vector3 result = *this; 23 | result += vector; 24 | return result; 25 | } 26 | 27 | Vector3& Vector3::operator+=(Vector3 other) { 28 | components[0] += other[0]; 29 | components[1] += other[1]; 30 | components[2] += other[2]; 31 | return *this; 32 | } 33 | 34 | Vector3 Vector3::operator-(Vector3 vector) { 35 | Vector3 result = *this; 36 | result -= vector; 37 | return result; 38 | } 39 | 40 | Vector3& Vector3::operator-=(Vector3 other) { 41 | components[0] -= other[0]; 42 | components[1] -= other[1]; 43 | components[2] -= other[2]; 44 | return *this; 45 | } 46 | 47 | Vector3 Vector3::operator*(Num divisor) { 48 | Vector3 result = *this; 49 | result *= divisor; 50 | return result; 51 | } 52 | 53 | Vector3& Vector3::operator*=(Num divisor) { 54 | components[0] *= divisor; 55 | components[1] *= divisor; 56 | components[2] *= divisor; 57 | return *this; 58 | } 59 | 60 | Vector3 Vector3::operator/(Num divisor) { 61 | Vector3 result = *this; 62 | result /= divisor; 63 | return result; 64 | } 65 | 66 | Vector3& Vector3::operator/=(Num divisor) { 67 | components[0] /= divisor; 68 | components[1] /= divisor; 69 | components[2] /= divisor; 70 | return *this; 71 | } 72 | 73 | Num Vector3::dot(Vector3 a, Vector3 b) { 74 | return a[0]*b[0] + a[1]*b[1] + a[2]*b[2]; 75 | } 76 | 77 | Vector3 Vector3::cross(Vector3 a, Vector3 b) { 78 | return Vector3( 79 | a[1]*b[2] - a[2]*b[1], 80 | a[2]*b[0] - a[0]*b[2], 81 | a[0]*b[1] - a[1]*b[0] 82 | ); 83 | } 84 | 85 | void Vector3::reset() { 86 | components[0] = 0; 87 | components[1] = 0; 88 | components[2] = 0; 89 | } 90 | 91 | Vector3 Vector3::normalize(Vector3 v) { 92 | return v/v.calcLength(); 93 | } 94 | 95 | Num Vector3::calcLength() const { 96 | return Util::sqrt(calcSquaredLength()); 97 | } 98 | 99 | Num Vector3::calcSquaredLength() const { 100 | return ( 101 | components[0] * components[0] + 102 | components[1] * components[1] + 103 | components[2] * components[2] 104 | ); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /Library/Include/Fixie/Num.h: -------------------------------------------------------------------------------- 1 | #ifndef FIXIE_NUM_H 2 | #define FIXIE_NUM_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "Fixie/Config.h" 8 | 9 | namespace Fixie { 10 | using namespace Config; 11 | 12 | class Num { 13 | public: 14 | int32_t raw = 0; 15 | Num() { } 16 | Num(int32_t x) { 17 | raw = x << fractionBits; 18 | } 19 | Num(double x) { 20 | raw = round(x * (1 << fractionBits)); 21 | } 22 | Num& operator+=(const Num &rhs) { 23 | raw += rhs.raw; 24 | return *this; 25 | } 26 | Num& operator-=(const Num &rhs) { 27 | raw -= rhs.raw; 28 | return *this; 29 | } 30 | Num& operator/=(const Num &rhs) { 31 | assert(rhs.raw != 0); 32 | const int32_t resultNegative = ((raw ^ rhs.raw) & 0x80000000) >> 31; 33 | const int32_t sign = resultNegative*-2+1; 34 | int64_t temp = static_cast(raw) << fractionBits; 35 | temp += rhs.raw/2*sign; 36 | raw = temp / rhs.raw; 37 | return *this; 38 | } 39 | Num& operator*=(const Num &rhs) { 40 | raw = (static_cast(raw) * rhs.raw) >> fractionBits; 41 | return *this; 42 | } 43 | Num operator+(const Num &other) const { 44 | Num result = *this; 45 | result += other; 46 | return result; 47 | } 48 | Num operator-(const Num &other) const { 49 | Num result = *this; 50 | result -= other; 51 | return result; 52 | } 53 | Num operator*(const Num &other) const { 54 | Num result = *this; 55 | result *= other; 56 | return result; 57 | } 58 | Num operator/(const Num &other) const { 59 | Num result = *this; 60 | result /= other; 61 | return result; 62 | } 63 | Num operator%(Num rhs) { 64 | int32_t a = *this; 65 | int32_t b = rhs; 66 | return a % b; 67 | } 68 | bool operator==(const Num &other) { 69 | return raw == other.raw; 70 | } 71 | bool operator!=(const Num &other) { 72 | return !(*this == other); 73 | } 74 | bool operator<(const Num &other) { 75 | return raw < other.raw; 76 | } 77 | bool operator<=(const Num &other) { 78 | return raw <= other.raw; 79 | } 80 | bool operator>(const Num &other) { 81 | return raw > other.raw; 82 | } 83 | bool operator>=(const Num &other) { 84 | return raw >= other.raw; 85 | } 86 | operator float() const { 87 | return static_cast(raw) / (1 << fractionBits); 88 | } 89 | operator double() const { 90 | return static_cast(raw) / (1 << fractionBits); 91 | } 92 | operator int32_t() const { 93 | return raw / (1 << fractionBits); 94 | } 95 | static Num createByRaw(int32_t raw) { 96 | Num n; 97 | n.raw = raw; 98 | return n; 99 | } 100 | }; 101 | } 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /Test/Vector3Test.h: -------------------------------------------------------------------------------- 1 | #include "Orwell.h" 2 | #include "Fixie/Vector3.h" 3 | 4 | namespace Vector3Test { 5 | using namespace Orwell::Assertions; 6 | using namespace Fixie; 7 | 8 | void testInit() { 9 | Vector3 v1(3, 4, 5); 10 | assertEqual(3, v1[0]); 11 | assertEqual(4, v1[1]); 12 | assertEqual(5, v1[2]); 13 | 14 | Vector3 v2(1.5, 2.6, 3.7); 15 | assertInDelta(1.5, 0.005, v2[0]); 16 | assertInDelta(2.6, 0.005, v2[1]); 17 | assertInDelta(3.7, 0.005, v2[2]); 18 | 19 | Vector3 v3(Num(3), Num(4), Num(5)); 20 | assertEqual(3, v3[0]); 21 | assertEqual(4, v3[1]); 22 | assertEqual(5, v3[2]); 23 | } 24 | 25 | void testAddition() { 26 | Vector3 v1; 27 | Vector3 v2; 28 | Vector3 sum; 29 | 30 | v1 = { 3, 4, 5 }; 31 | v2 = { 11, 6.7, 1 }; 32 | sum = v1+v2; 33 | assertEqual(14, sum[0]); 34 | assertInDelta(10.7, 0.001, sum[1]); 35 | assertEqual(6, sum[2]); 36 | 37 | v1 = { 3, 4, 5 }; 38 | v2 = { -3, -4, -5 }; 39 | sum = v1+v2; 40 | assertEqual(0, sum[0]); 41 | assertEqual(0, sum[1]); 42 | assertEqual(0, sum[2]); 43 | } 44 | 45 | void testSubtraction() { 46 | Vector3 v1; 47 | Vector3 v2; 48 | Vector3 sum; 49 | 50 | v1 = { 3, 4, 5 }; 51 | v2 = { 11, 6.7, 1 }; 52 | sum = v1-v2; 53 | assertEqual(-8, sum[0]); 54 | assertInDelta(-2.7, 0.001, sum[1]); 55 | assertEqual(4, sum[2]); 56 | 57 | v1 = { 3, 4, 5 }; 58 | v2 = { -3, -4, -5 }; 59 | sum = v1-v2; 60 | assertEqual(6, sum[0]); 61 | assertEqual(8, sum[1]); 62 | assertEqual(10, sum[2]); 63 | } 64 | 65 | void testMultiplication() { 66 | Vector3 v(2, 6, 10); 67 | Vector3 r = v*4; 68 | 69 | assertEqual(8, r[0]); 70 | assertEqual(24, r[1]); 71 | assertEqual(40, r[2]); 72 | } 73 | 74 | void testDivision() { 75 | Vector3 v; 76 | Vector3 quotient; 77 | 78 | v = { 3, 4, 5 }; 79 | quotient = v/3.3; 80 | assertInDelta(0.90909, 0.002, quotient[0]); 81 | assertInDelta(1.21212, 0.002, quotient[1]); 82 | assertInDelta(1.51515, 0.002, quotient[2]); 83 | 84 | v = { -7, 1.1, 91.9 }; 85 | quotient = v/-6.1; 86 | assertInDelta(1.14754, 0.002, quotient[0]); 87 | assertInDelta(-0.18032, 0.002, quotient[1]); 88 | assertInDelta(-15.0655, 0.002, quotient[2]); 89 | } 90 | 91 | void testDot() { 92 | Vector3 a; 93 | Vector3 b; 94 | Num dotProduct; 95 | 96 | a = { 1, 2, 3 }; 97 | b = { 4, -5, 6 }; 98 | dotProduct = Vector3::dot(a, b); 99 | assertEqual(12, dotProduct); 100 | 101 | a = { 2, -3, 7 }; 102 | b = { -4, 2, -4 }; 103 | dotProduct = Vector3::dot(a, b); 104 | assertEqual(-42, dotProduct); 105 | 106 | } 107 | 108 | void testCross() { 109 | Vector3 a; 110 | Vector3 b; 111 | Vector3 crossProduct; 112 | 113 | a = { 3, -3, 1 }; 114 | b = { 4, 9, 2 }; 115 | crossProduct = Vector3::cross(a, b); 116 | assertEqual(-15, crossProduct[0]); 117 | assertEqual(-2, crossProduct[1]); 118 | assertEqual(39, crossProduct[2]); 119 | 120 | a = { 2, 1, -3 }; 121 | b = { 0, 4, 5 }; 122 | crossProduct = Vector3::cross(a, b); 123 | assertEqual(17, crossProduct[0]); 124 | assertEqual(-10, crossProduct[1]); 125 | assertEqual(8, crossProduct[2]); 126 | } 127 | 128 | void testLength() { 129 | Vector3 v; 130 | Num length; 131 | 132 | v = { 3, 2, 8 }; 133 | length = v.calcLength(); 134 | assertInDelta(8.77496, 0.002, length); 135 | 136 | v = { -7.9, 7, 2 }; 137 | length = v.calcLength(); 138 | assertInDelta(10.74290, 0.002, length); 139 | } 140 | 141 | void testSquaredLength() { 142 | Vector3 v; 143 | Num squaredLength; 144 | 145 | v = { 3, -4, 7.7 }; 146 | squaredLength = v.calcSquaredLength(); 147 | assertInDelta(84.29, 0.005, squaredLength); 148 | 149 | v = { 4, 81, -3.1 }; 150 | squaredLength = v.calcSquaredLength(); 151 | assertInDelta(6586.61, 0.005, squaredLength); 152 | } 153 | 154 | void testNormalize() { 155 | Vector3 v; 156 | 157 | v = { 9, -4, 1.7 }; 158 | v = Vector3::normalize(v); 159 | assertInDelta(0.90049, 0.005, v[0]); 160 | assertInDelta(-0.40022, 0.005, v[1]); 161 | assertInDelta(0.17009, 0.005, v[2]); 162 | 163 | v = { -2, 7, 23 }; 164 | v = Vector3::normalize(v); 165 | assertInDelta(-0.082902, 0.005, v[0]); 166 | assertInDelta(0.29015, 0.005, v[1]); 167 | assertInDelta(0.95338, 0.005, v[2]); 168 | } 169 | 170 | void setup() { 171 | unsigned group = Orwell::createGroup("FixieVector3Test"); 172 | Orwell::addTest(group, testInit, "Init"); 173 | Orwell::addTest(group, testAddition, "Addition"); 174 | Orwell::addTest(group, testSubtraction, "Subtraction"); 175 | Orwell::addTest(group, testMultiplication, "Multiplication"); 176 | Orwell::addTest(group, testDivision, "Division"); 177 | Orwell::addTest(group, testLength, "Length"); 178 | Orwell::addTest(group, testSquaredLength, "SquaredLength"); 179 | Orwell::addTest(group, testNormalize, "Normalize"); 180 | Orwell::addTest(group, testDot, "Dot"); 181 | Orwell::addTest(group, testCross, "Cross"); 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /Test/NumTest.h: -------------------------------------------------------------------------------- 1 | #include "Orwell.h" 2 | #include "Fixie/Num.h" 3 | 4 | namespace NumTest { 5 | using namespace Orwell::Assertions; 6 | using namespace Fixie; 7 | 8 | void testConversion() { 9 | Num n; 10 | 11 | n = 10; 12 | assertEqual(10, n); 13 | 14 | n = 10.0; 15 | assertEqual(n, 10); 16 | 17 | n = 10.0f; 18 | assertEqual(n, 10); 19 | 20 | n = 10.99999; 21 | assertEqual(n, 11); 22 | } 23 | 24 | void testAddition() { 25 | Num a, b; 26 | 27 | a = 37; 28 | b = 3; 29 | assertEqual(40, a+b); 30 | 31 | a = -50; 32 | b = 3; 33 | assertEqual(-47, a+b); 34 | 35 | a = 1.7; 36 | b = 2.7; 37 | assertInDelta(4.4, 0.005, a+b); 38 | } 39 | 40 | void testSubtraction() { 41 | Num a, b; 42 | 43 | a = 37; 44 | b = 3; 45 | assertEqual(34, a-b); 46 | 47 | a = -50; 48 | b = 3; 49 | assertEqual(-53, a-b); 50 | 51 | a = -50; 52 | b = -3; 53 | assertEqual(-47, a-b); 54 | 55 | a = 1.7; 56 | b = 2.7; 57 | assertInDelta(-1, 0.005, a-b); 58 | } 59 | 60 | void testMultiplication() { 61 | Num a, b; 62 | 63 | a = 1.5; 64 | b = 3; 65 | assertInDelta(4.5, 0.005, a*b); 66 | 67 | a = 1.5; 68 | b = -3; 69 | assertInDelta(-4.5, 0.005, a*b); 70 | } 71 | 72 | void testDivision() { 73 | Num a, b; 74 | 75 | a = 1; 76 | b = 3; 77 | assertInDelta(1.0/3.0, 0.0005, a/b); 78 | 79 | a = 1; 80 | b = 2; 81 | assertInDelta(0.5, 0.0005, a/b); 82 | 83 | 84 | a = -1; 85 | b = 3; 86 | assertInDelta(-1.0/3.0, 0.0005, a/b); 87 | 88 | a = -2; 89 | b = 3; 90 | assertInDelta(-2.0/3.0, 0.0005, a/b); 91 | 92 | a = 2; 93 | b = -3; 94 | assertInDelta(2.0/-3.0, 0.0005, a/b); 95 | 96 | a = -2; 97 | b = -3; 98 | assertInDelta(-2.0/-3.0, 0.0005, a/b); 99 | } 100 | 101 | void testModulus() { 102 | Num a, b; 103 | 104 | a = 10; 105 | b = 3; 106 | assertEqual(1, a % b); 107 | 108 | a = 25; 109 | b = 5; 110 | assertEqual(0, a % b); 111 | 112 | a = 7; 113 | b = 16; 114 | assertEqual(7, a % b); 115 | } 116 | 117 | void testEquality() { 118 | Num a, b; 119 | 120 | a = 10; 121 | b = 10; 122 | assertTrue(a == b); 123 | 124 | a = -10; 125 | b = -10; 126 | assertTrue(a == b); 127 | 128 | a = 10; 129 | b = 5; 130 | assertFalse(a == b); 131 | 132 | a = 10; 133 | b = -10; 134 | assertFalse(a == b); 135 | } 136 | 137 | void testInequality() { 138 | Num a, b; 139 | 140 | a = 10; 141 | b = 5; 142 | assertTrue(a != b); 143 | 144 | a = 10; 145 | b = -10; 146 | assertTrue(a != b); 147 | 148 | a = 10; 149 | b = 10; 150 | assertFalse(a != b); 151 | 152 | a = -10; 153 | b = -10; 154 | assertFalse(a != b); 155 | } 156 | 157 | void testGreaterThan() { 158 | Num a, b; 159 | 160 | a = 5; 161 | b = 10; 162 | assertTrue(a < b); 163 | 164 | a = -5; 165 | b = 2; 166 | assertTrue(a < b); 167 | 168 | a = 10; 169 | b = 5; 170 | assertFalse(a < b); 171 | 172 | a = 2; 173 | b = -5; 174 | assertFalse(a < b); 175 | } 176 | 177 | void testGreaterThanOrEqual() { 178 | Num a, b; 179 | 180 | a = 5; 181 | b = 10; 182 | assertTrue(a <= b); 183 | 184 | a = -5; 185 | b = 2; 186 | assertTrue(a <= b); 187 | 188 | a = 2; 189 | b = 2; 190 | assertTrue(a <= b); 191 | 192 | a = 10; 193 | b = 5; 194 | assertFalse(a <= b); 195 | 196 | a = 2; 197 | b = -5; 198 | assertFalse(a <= b); 199 | } 200 | 201 | void testLessThan() { 202 | Num a, b; 203 | 204 | a = 10; 205 | b = 5; 206 | assertTrue(a > b); 207 | 208 | a = 2; 209 | b = -5; 210 | assertTrue(a > b); 211 | 212 | a = 5; 213 | b = 10; 214 | assertFalse(a > b); 215 | 216 | a = -5; 217 | b = 2; 218 | assertFalse(a > b); 219 | } 220 | 221 | void testLessThanOrEqual() { 222 | Num a, b; 223 | 224 | a = 10; 225 | b = 5; 226 | assertTrue(a >= b); 227 | 228 | a = 2; 229 | b = -5; 230 | assertTrue(a >= b); 231 | 232 | a = 2; 233 | b = 2; 234 | assertTrue(a >= b); 235 | 236 | a = 5; 237 | b = 10; 238 | assertFalse(a >= b); 239 | 240 | a = -5; 241 | b = 2; 242 | assertFalse(a >= b); 243 | } 244 | 245 | void setup() { 246 | unsigned group = Orwell::createGroup("FixieNumTest"); 247 | Orwell::addTest(group, testConversion, "Conversion"); 248 | Orwell::addTest(group, testAddition, "Addition"); 249 | Orwell::addTest(group, testSubtraction, "Subtraction"); 250 | Orwell::addTest(group, testMultiplication, "Multiplication"); 251 | Orwell::addTest(group, testDivision, "Division"); 252 | Orwell::addTest(group, testModulus, "Modulus"); 253 | Orwell::addTest(group, testEquality, "Equality"); 254 | Orwell::addTest(group, testInequality, "Inequality"); 255 | Orwell::addTest(group, testGreaterThan, "GreaterThan"); 256 | Orwell::addTest(group, testGreaterThanOrEqual, "GreaterThanOrEqual"); 257 | Orwell::addTest(group, testLessThan, "LessThan"); 258 | Orwell::addTest(group, testLessThanOrEqual, "LessThanOrEqual"); 259 | } 260 | } 261 | -------------------------------------------------------------------------------- /Library/Source/Trig.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Fixie/Num.h" 3 | #include "Fixie/Util.h" 4 | #include "Fixie/Trig.h" 5 | 6 | #include 7 | 8 | namespace Fixie { 9 | namespace Trig { 10 | const Num pi = Num::createByRaw(3217); 11 | const Num twoPi = Num::createByRaw(6434); 12 | const Num halfPi = Num::createByRaw(1608); 13 | const Num inverseTwoPi = Num::createByRaw(163); 14 | 15 | int16_t sineTable[] = { 16 | 0, 6, 13, 19, 25, 31, 38, 44, 17 | 50, 57, 63, 69, 75, 82, 88, 94, 18 | 100, 107, 113, 119, 125, 132, 138, 144, 19 | 150, 156, 163, 169, 175, 181, 187, 194, 20 | 200, 206, 212, 218, 224, 230, 237, 243, 21 | 249, 255, 261, 267, 273, 279, 285, 291, 22 | 297, 303, 309, 315, 321, 327, 333, 339, 23 | 345, 351, 357, 363, 369, 374, 380, 386, 24 | 392, 398, 403, 409, 415, 421, 426, 432, 25 | 438, 443, 449, 455, 460, 466, 472, 477, 26 | 483, 488, 494, 499, 505, 510, 516, 521, 27 | 526, 532, 537, 543, 548, 553, 558, 564, 28 | 569, 574, 579, 584, 590, 595, 600, 605, 29 | 610, 615, 620, 625, 630, 635, 640, 645, 30 | 650, 654, 659, 664, 669, 674, 678, 683, 31 | 688, 692, 697, 702, 706, 711, 715, 720, 32 | 724, 729, 733, 737, 742, 746, 750, 755, 33 | 759, 763, 767, 771, 775, 779, 784, 788, 34 | 792, 796, 799, 803, 807, 811, 815, 819, 35 | 822, 826, 830, 834, 837, 841, 844, 848, 36 | 851, 855, 858, 862, 865, 868, 872, 875, 37 | 878, 882, 885, 888, 891, 894, 897, 900, 38 | 903, 906, 909, 912, 915, 917, 920, 923, 39 | 926, 928, 931, 934, 936, 939, 941, 944, 40 | 946, 948, 951, 953, 955, 958, 960, 962, 41 | 964, 966, 968, 970, 972, 974, 976, 978, 42 | 980, 982, 983, 985, 987, 989, 990, 992, 43 | 993, 995, 996, 998, 999, 1000, 1002, 1003, 44 | 1004, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 45 | 1013, 1014, 1015, 1016, 1016, 1017, 1018, 1018, 46 | 1019, 1020, 1020, 1021, 1021, 1022, 1022, 1022, 47 | 1023, 1023, 1023, 1024, 1024, 1024, 1024, 1024, 48 | 1024, 1024, 1024, 1024, 1024, 1024, 1023, 1023, 49 | 1023, 1022, 1022, 1022, 1021, 1021, 1020, 1020, 50 | 1019, 1018, 1018, 1017, 1016, 1016, 1015, 1014, 51 | 1013, 1012, 1011, 1010, 1009, 1008, 1007, 1006, 52 | 1004, 1003, 1002, 1000, 999, 998, 996, 995, 53 | 993, 992, 990, 989, 987, 985, 983, 982, 54 | 980, 978, 976, 974, 972, 970, 968, 966, 55 | 964, 962, 960, 958, 955, 953, 951, 948, 56 | 946, 944, 941, 939, 936, 934, 931, 928, 57 | 926, 923, 920, 917, 915, 912, 909, 906, 58 | 903, 900, 897, 894, 891, 888, 885, 882, 59 | 878, 875, 872, 868, 865, 862, 858, 855, 60 | 851, 848, 844, 841, 837, 834, 830, 826, 61 | 822, 819, 815, 811, 807, 803, 799, 796, 62 | 792, 788, 784, 779, 775, 771, 767, 763, 63 | 759, 755, 750, 746, 742, 737, 733, 729, 64 | 724, 720, 715, 711, 706, 702, 697, 692, 65 | 688, 683, 678, 674, 669, 664, 659, 654, 66 | 650, 645, 640, 635, 630, 625, 620, 615, 67 | 610, 605, 600, 595, 590, 584, 579, 574, 68 | 569, 564, 558, 553, 548, 543, 537, 532, 69 | 526, 521, 516, 510, 505, 499, 494, 488, 70 | 483, 477, 472, 466, 460, 455, 449, 443, 71 | 438, 432, 426, 421, 415, 409, 403, 398, 72 | 392, 386, 380, 374, 369, 363, 357, 351, 73 | 345, 339, 333, 327, 321, 315, 309, 303, 74 | 297, 291, 285, 279, 273, 267, 261, 255, 75 | 249, 243, 237, 230, 224, 218, 212, 206, 76 | 200, 194, 187, 181, 175, 169, 163, 156, 77 | 150, 144, 138, 132, 125, 119, 113, 107, 78 | 100, 94, 88, 82, 75, 69, 63, 57, 79 | 50, 44, 38, 31, 25, 19, 13, 6, 80 | 0, -6, -13, -19, -25, -31, -38, -44, 81 | -50, -57, -63, -69, -75, -82, -88, -94, 82 | -100, -107, -113, -119, -125, -132, -138, -144, 83 | -150, -156, -163, -169, -175, -181, -187, -194, 84 | -200, -206, -212, -218, -224, -230, -237, -243, 85 | -249, -255, -261, -267, -273, -279, -285, -291, 86 | -297, -303, -309, -315, -321, -327, -333, -339, 87 | -345, -351, -357, -363, -369, -374, -380, -386, 88 | -392, -398, -403, -409, -415, -421, -426, -432, 89 | -438, -443, -449, -455, -460, -466, -472, -477, 90 | -483, -488, -494, -499, -505, -510, -516, -521, 91 | -526, -532, -537, -543, -548, -553, -558, -564, 92 | -569, -574, -579, -584, -590, -595, -600, -605, 93 | -610, -615, -620, -625, -630, -635, -640, -645, 94 | -650, -654, -659, -664, -669, -674, -678, -683, 95 | -688, -692, -697, -702, -706, -711, -715, -720, 96 | -724, -729, -733, -737, -742, -746, -750, -755, 97 | -759, -763, -767, -771, -775, -779, -784, -788, 98 | -792, -796, -799, -803, -807, -811, -815, -819, 99 | -822, -826, -830, -834, -837, -841, -844, -848, 100 | -851, -855, -858, -862, -865, -868, -872, -875, 101 | -878, -882, -885, -888, -891, -894, -897, -900, 102 | -903, -906, -909, -912, -915, -917, -920, -923, 103 | -926, -928, -931, -934, -936, -939, -941, -944, 104 | -946, -948, -951, -953, -955, -958, -960, -962, 105 | -964, -966, -968, -970, -972, -974, -976, -978, 106 | -980, -982, -983, -985, -987, -989, -990, -992, 107 | -993, -995, -996, -998, -999, -1000, -1002, -1003, 108 | -1004, -1006, -1007, -1008, -1009, -1010, -1011, -1012, 109 | -1013, -1014, -1015, -1016, -1016, -1017, -1018, -1018, 110 | -1019, -1020, -1020, -1021, -1021, -1022, -1022, -1022, 111 | -1023, -1023, -1023, -1024, -1024, -1024, -1024, -1024, 112 | -1024, -1024, -1024, -1024, -1024, -1024, -1023, -1023, 113 | -1023, -1022, -1022, -1022, -1021, -1021, -1020, -1020, 114 | -1019, -1018, -1018, -1017, -1016, -1016, -1015, -1014, 115 | -1013, -1012, -1011, -1010, -1009, -1008, -1007, -1006, 116 | -1004, -1003, -1002, -1000, -999, -998, -996, -995, 117 | -993, -992, -990, -989, -987, -985, -983, -982, 118 | -980, -978, -976, -974, -972, -970, -968, -966, 119 | -964, -962, -960, -958, -955, -953, -951, -948, 120 | -946, -944, -941, -939, -936, -934, -931, -928, 121 | -926, -923, -920, -917, -915, -912, -909, -906, 122 | -903, -900, -897, -894, -891, -888, -885, -882, 123 | -878, -875, -872, -868, -865, -862, -858, -855, 124 | -851, -848, -844, -841, -837, -834, -830, -826, 125 | -822, -819, -815, -811, -807, -803, -799, -796, 126 | -792, -788, -784, -779, -775, -771, -767, -763, 127 | -759, -755, -750, -746, -742, -737, -733, -729, 128 | -724, -720, -715, -711, -706, -702, -697, -692, 129 | -688, -683, -678, -674, -669, -664, -659, -654, 130 | -650, -645, -640, -635, -630, -625, -620, -615, 131 | -610, -605, -600, -595, -590, -584, -579, -574, 132 | -569, -564, -558, -553, -548, -543, -537, -532, 133 | -526, -521, -516, -510, -505, -499, -494, -488, 134 | -483, -477, -472, -466, -460, -455, -449, -443, 135 | -438, -432, -426, -421, -415, -409, -403, -398, 136 | -392, -386, -380, -374, -369, -363, -357, -351, 137 | -345, -339, -333, -327, -321, -315, -309, -303, 138 | -297, -291, -285, -279, -273, -267, -261, -255, 139 | -249, -243, -237, -230, -224, -218, -212, -206, 140 | -200, -194, -187, -181, -175, -169, -163, -156, 141 | -150, -144, -138, -132, -125, -119, -113, -107, 142 | -100, -94, -88, -82, -75, -69, -63, -57, 143 | -50, -44, -38, -31, -25, -19, -13, -6 144 | }; 145 | 146 | int16_t cosineTable[] = { 147 | 1024, 1024, 1024, 1024, 1024, 1024, 1023, 1023, 148 | 1023, 1022, 1022, 1022, 1021, 1021, 1020, 1020, 149 | 1019, 1018, 1018, 1017, 1016, 1016, 1015, 1014, 150 | 1013, 1012, 1011, 1010, 1009, 1008, 1007, 1006, 151 | 1004, 1003, 1002, 1000, 999, 998, 996, 995, 152 | 993, 992, 990, 989, 987, 985, 983, 982, 153 | 980, 978, 976, 974, 972, 970, 968, 966, 154 | 964, 962, 960, 958, 955, 953, 951, 948, 155 | 946, 944, 941, 939, 936, 934, 931, 928, 156 | 926, 923, 920, 917, 915, 912, 909, 906, 157 | 903, 900, 897, 894, 891, 888, 885, 882, 158 | 878, 875, 872, 868, 865, 862, 858, 855, 159 | 851, 848, 844, 841, 837, 834, 830, 826, 160 | 822, 819, 815, 811, 807, 803, 799, 796, 161 | 792, 788, 784, 779, 775, 771, 767, 763, 162 | 759, 755, 750, 746, 742, 737, 733, 729, 163 | 724, 720, 715, 711, 706, 702, 697, 692, 164 | 688, 683, 678, 674, 669, 664, 659, 654, 165 | 650, 645, 640, 635, 630, 625, 620, 615, 166 | 610, 605, 600, 595, 590, 584, 579, 574, 167 | 569, 564, 558, 553, 548, 543, 537, 532, 168 | 526, 521, 516, 510, 505, 499, 494, 488, 169 | 483, 477, 472, 466, 460, 455, 449, 443, 170 | 438, 432, 426, 421, 415, 409, 403, 398, 171 | 392, 386, 380, 374, 369, 363, 357, 351, 172 | 345, 339, 333, 327, 321, 315, 309, 303, 173 | 297, 291, 285, 279, 273, 267, 261, 255, 174 | 249, 243, 237, 230, 224, 218, 212, 206, 175 | 200, 194, 187, 181, 175, 169, 163, 156, 176 | 150, 144, 138, 132, 125, 119, 113, 107, 177 | 100, 94, 88, 82, 75, 69, 63, 57, 178 | 50, 44, 38, 31, 25, 19, 13, 6, 179 | 0, -6, -13, -19, -25, -31, -38, -44, 180 | -50, -57, -63, -69, -75, -82, -88, -94, 181 | -100, -107, -113, -119, -125, -132, -138, -144, 182 | -150, -156, -163, -169, -175, -181, -187, -194, 183 | -200, -206, -212, -218, -224, -230, -237, -243, 184 | -249, -255, -261, -267, -273, -279, -285, -291, 185 | -297, -303, -309, -315, -321, -327, -333, -339, 186 | -345, -351, -357, -363, -369, -374, -380, -386, 187 | -392, -398, -403, -409, -415, -421, -426, -432, 188 | -438, -443, -449, -455, -460, -466, -472, -477, 189 | -483, -488, -494, -499, -505, -510, -516, -521, 190 | -526, -532, -537, -543, -548, -553, -558, -564, 191 | -569, -574, -579, -584, -590, -595, -600, -605, 192 | -610, -615, -620, -625, -630, -635, -640, -645, 193 | -650, -654, -659, -664, -669, -674, -678, -683, 194 | -688, -692, -697, -702, -706, -711, -715, -720, 195 | -724, -729, -733, -737, -742, -746, -750, -755, 196 | -759, -763, -767, -771, -775, -779, -784, -788, 197 | -792, -796, -799, -803, -807, -811, -815, -819, 198 | -822, -826, -830, -834, -837, -841, -844, -848, 199 | -851, -855, -858, -862, -865, -868, -872, -875, 200 | -878, -882, -885, -888, -891, -894, -897, -900, 201 | -903, -906, -909, -912, -915, -917, -920, -923, 202 | -926, -928, -931, -934, -936, -939, -941, -944, 203 | -946, -948, -951, -953, -955, -958, -960, -962, 204 | -964, -966, -968, -970, -972, -974, -976, -978, 205 | -980, -982, -983, -985, -987, -989, -990, -992, 206 | -993, -995, -996, -998, -999, -1000, -1002, -1003, 207 | -1004, -1006, -1007, -1008, -1009, -1010, -1011, -1012, 208 | -1013, -1014, -1015, -1016, -1016, -1017, -1018, -1018, 209 | -1019, -1020, -1020, -1021, -1021, -1022, -1022, -1022, 210 | -1023, -1023, -1023, -1024, -1024, -1024, -1024, -1024, 211 | -1024, -1024, -1024, -1024, -1024, -1024, -1023, -1023, 212 | -1023, -1022, -1022, -1022, -1021, -1021, -1020, -1020, 213 | -1019, -1018, -1018, -1017, -1016, -1016, -1015, -1014, 214 | -1013, -1012, -1011, -1010, -1009, -1008, -1007, -1006, 215 | -1004, -1003, -1002, -1000, -999, -998, -996, -995, 216 | -993, -992, -990, -989, -987, -985, -983, -982, 217 | -980, -978, -976, -974, -972, -970, -968, -966, 218 | -964, -962, -960, -958, -955, -953, -951, -948, 219 | -946, -944, -941, -939, -936, -934, -931, -928, 220 | -926, -923, -920, -917, -915, -912, -909, -906, 221 | -903, -900, -897, -894, -891, -888, -885, -882, 222 | -878, -875, -872, -868, -865, -862, -858, -855, 223 | -851, -848, -844, -841, -837, -834, -830, -826, 224 | -822, -819, -815, -811, -807, -803, -799, -796, 225 | -792, -788, -784, -779, -775, -771, -767, -763, 226 | -759, -755, -750, -746, -742, -737, -733, -729, 227 | -724, -720, -715, -711, -706, -702, -697, -692, 228 | -688, -683, -678, -674, -669, -664, -659, -654, 229 | -650, -645, -640, -635, -630, -625, -620, -615, 230 | -610, -605, -600, -595, -590, -584, -579, -574, 231 | -569, -564, -558, -553, -548, -543, -537, -532, 232 | -526, -521, -516, -510, -505, -499, -494, -488, 233 | -483, -477, -472, -466, -460, -455, -449, -443, 234 | -438, -432, -426, -421, -415, -409, -403, -398, 235 | -392, -386, -380, -374, -369, -363, -357, -351, 236 | -345, -339, -333, -327, -321, -315, -309, -303, 237 | -297, -291, -285, -279, -273, -267, -261, -255, 238 | -249, -243, -237, -230, -224, -218, -212, -206, 239 | -200, -194, -187, -181, -175, -169, -163, -156, 240 | -150, -144, -138, -132, -125, -119, -113, -107, 241 | -100, -94, -88, -82, -75, -69, -63, -57, 242 | -50, -44, -38, -31, -25, -19, -13, -6, 243 | 0, 6, 13, 19, 25, 31, 38, 44, 244 | 50, 57, 63, 69, 75, 82, 88, 94, 245 | 100, 107, 113, 119, 125, 132, 138, 144, 246 | 150, 156, 163, 169, 175, 181, 187, 194, 247 | 200, 206, 212, 218, 224, 230, 237, 243, 248 | 249, 255, 261, 267, 273, 279, 285, 291, 249 | 297, 303, 309, 315, 321, 327, 333, 339, 250 | 345, 351, 357, 363, 369, 374, 380, 386, 251 | 392, 398, 403, 409, 415, 421, 426, 432, 252 | 438, 443, 449, 455, 460, 466, 472, 477, 253 | 483, 488, 494, 499, 505, 510, 516, 521, 254 | 526, 532, 537, 543, 548, 553, 558, 564, 255 | 569, 574, 579, 584, 590, 595, 600, 605, 256 | 610, 615, 620, 625, 630, 635, 640, 645, 257 | 650, 654, 659, 664, 669, 674, 678, 683, 258 | 688, 692, 697, 702, 706, 711, 715, 720, 259 | 724, 729, 733, 737, 742, 746, 750, 755, 260 | 759, 763, 767, 771, 775, 779, 784, 788, 261 | 792, 796, 799, 803, 807, 811, 815, 819, 262 | 822, 826, 830, 834, 837, 841, 844, 848, 263 | 851, 855, 858, 862, 865, 868, 872, 875, 264 | 878, 882, 885, 888, 891, 894, 897, 900, 265 | 903, 906, 909, 912, 915, 917, 920, 923, 266 | 926, 928, 931, 934, 936, 939, 941, 944, 267 | 946, 948, 951, 953, 955, 958, 960, 962, 268 | 964, 966, 968, 970, 972, 974, 976, 978, 269 | 980, 982, 983, 985, 987, 989, 990, 992, 270 | 993, 995, 996, 998, 999, 1000, 1002, 1003, 271 | 1004, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 272 | 1013, 1014, 1015, 1016, 1016, 1017, 1018, 1018, 273 | 1019, 1020, 1020, 1021, 1021, 1022, 1022, 1022, 274 | 1023, 1023, 1023, 1024, 1024, 1024, 1024, 1024 275 | }; 276 | 277 | uint16_t arcCosineTable[] = { 278 | 3217, 3153, 3126, 3106, 3089, 3074, 3060, 3047, 279 | 3036, 3025, 3014, 3004, 2995, 2986, 2977, 2969, 280 | 2960, 2952, 2945, 2937, 2930, 2923, 2916, 2909, 281 | 2902, 2896, 2889, 2883, 2877, 2871, 2865, 2859, 282 | 2853, 2847, 2842, 2836, 2831, 2825, 2820, 2815, 283 | 2810, 2804, 2799, 2794, 2789, 2784, 2780, 2775, 284 | 2770, 2765, 2761, 2756, 2751, 2747, 2742, 2738, 285 | 2734, 2729, 2725, 2721, 2716, 2712, 2708, 2704, 286 | 2700, 2695, 2691, 2687, 2683, 2679, 2675, 2671, 287 | 2667, 2663, 2660, 2656, 2652, 2648, 2644, 2641, 288 | 2637, 2633, 2629, 2626, 2622, 2618, 2615, 2611, 289 | 2608, 2604, 2601, 2597, 2594, 2590, 2587, 2583, 290 | 2580, 2576, 2573, 2569, 2566, 2563, 2559, 2556, 291 | 2553, 2549, 2546, 2543, 2540, 2536, 2533, 2530, 292 | 2527, 2523, 2520, 2517, 2514, 2511, 2508, 2505, 293 | 2501, 2498, 2495, 2492, 2489, 2486, 2483, 2480, 294 | 2477, 2474, 2471, 2468, 2465, 2462, 2459, 2456, 295 | 2453, 2450, 2447, 2444, 2441, 2438, 2436, 2433, 296 | 2430, 2427, 2424, 2421, 2418, 2415, 2413, 2410, 297 | 2407, 2404, 2401, 2399, 2396, 2393, 2390, 2387, 298 | 2385, 2382, 2379, 2376, 2374, 2371, 2368, 2366, 299 | 2363, 2360, 2358, 2355, 2352, 2349, 2347, 2344, 300 | 2342, 2339, 2336, 2334, 2331, 2328, 2326, 2323, 301 | 2320, 2318, 2315, 2313, 2310, 2308, 2305, 2302, 302 | 2300, 2297, 2295, 2292, 2290, 2287, 2285, 2282, 303 | 2279, 2277, 2274, 2272, 2269, 2267, 2264, 2262, 304 | 2259, 2257, 2255, 2252, 2250, 2247, 2245, 2242, 305 | 2240, 2237, 2235, 2232, 2230, 2228, 2225, 2223, 306 | 2220, 2218, 2215, 2213, 2211, 2208, 2206, 2203, 307 | 2201, 2199, 2196, 2194, 2191, 2189, 2187, 2184, 308 | 2182, 2180, 2177, 2175, 2173, 2170, 2168, 2166, 309 | 2163, 2161, 2159, 2156, 2154, 2152, 2149, 2147, 310 | 2145, 2142, 2140, 2138, 2135, 2133, 2131, 2129, 311 | 2126, 2124, 2122, 2119, 2117, 2115, 2113, 2110, 312 | 2108, 2106, 2104, 2101, 2099, 2097, 2095, 2092, 313 | 2090, 2088, 2086, 2083, 2081, 2079, 2077, 2074, 314 | 2072, 2070, 2068, 2066, 2063, 2061, 2059, 2057, 315 | 2054, 2052, 2050, 2048, 2046, 2043, 2041, 2039, 316 | 2037, 2035, 2033, 2030, 2028, 2026, 2024, 2022, 317 | 2019, 2017, 2015, 2013, 2011, 2009, 2006, 2004, 318 | 2002, 2000, 1998, 1996, 1994, 1991, 1989, 1987, 319 | 1985, 1983, 1981, 1978, 1976, 1974, 1972, 1970, 320 | 1968, 1966, 1964, 1961, 1959, 1957, 1955, 1953, 321 | 1951, 1949, 1947, 1944, 1942, 1940, 1938, 1936, 322 | 1934, 1932, 1930, 1928, 1926, 1923, 1921, 1919, 323 | 1917, 1915, 1913, 1911, 1909, 1907, 1905, 1903, 324 | 1900, 1898, 1896, 1894, 1892, 1890, 1888, 1886, 325 | 1884, 1882, 1880, 1878, 1876, 1873, 1871, 1869, 326 | 1867, 1865, 1863, 1861, 1859, 1857, 1855, 1853, 327 | 1851, 1849, 1847, 1845, 1843, 1840, 1838, 1836, 328 | 1834, 1832, 1830, 1828, 1826, 1824, 1822, 1820, 329 | 1818, 1816, 1814, 1812, 1810, 1808, 1806, 1804, 330 | 1802, 1800, 1798, 1796, 1794, 1791, 1789, 1787, 331 | 1785, 1783, 1781, 1779, 1777, 1775, 1773, 1771, 332 | 1769, 1767, 1765, 1763, 1761, 1759, 1757, 1755, 333 | 1753, 1751, 1749, 1747, 1745, 1743, 1741, 1739, 334 | 1737, 1735, 1733, 1731, 1729, 1727, 1725, 1723, 335 | 1721, 1719, 1717, 1715, 1713, 1711, 1709, 1707, 336 | 1705, 1703, 1701, 1699, 1697, 1695, 1693, 1691, 337 | 1689, 1687, 1685, 1683, 1681, 1679, 1677, 1675, 338 | 1673, 1671, 1669, 1667, 1665, 1663, 1661, 1659, 339 | 1657, 1655, 1653, 1651, 1649, 1647, 1645, 1643, 340 | 1641, 1638, 1636, 1634, 1632, 1630, 1628, 1626, 341 | 1624, 1622, 1620, 1618, 1616, 1614, 1612, 1610, 342 | 1608, 1606, 1604, 1602, 1600, 1598, 1596, 1594, 343 | 1592, 1590, 1588, 1586, 1584, 1582, 1580, 1578, 344 | 1576, 1574, 1572, 1570, 1568, 1566, 1564, 1562, 345 | 1560, 1558, 1556, 1554, 1552, 1550, 1548, 1546, 346 | 1544, 1542, 1540, 1538, 1536, 1534, 1532, 1530, 347 | 1528, 1526, 1524, 1522, 1520, 1518, 1516, 1514, 348 | 1512, 1510, 1508, 1506, 1504, 1502, 1500, 1498, 349 | 1496, 1494, 1492, 1490, 1488, 1486, 1484, 1482, 350 | 1480, 1478, 1476, 1474, 1472, 1470, 1468, 1466, 351 | 1464, 1462, 1460, 1458, 1456, 1454, 1452, 1450, 352 | 1448, 1446, 1444, 1442, 1440, 1438, 1436, 1434, 353 | 1432, 1430, 1428, 1426, 1423, 1421, 1419, 1417, 354 | 1415, 1413, 1411, 1409, 1407, 1405, 1403, 1401, 355 | 1399, 1397, 1395, 1393, 1391, 1389, 1387, 1385, 356 | 1383, 1381, 1379, 1377, 1374, 1372, 1370, 1368, 357 | 1366, 1364, 1362, 1360, 1358, 1356, 1354, 1352, 358 | 1350, 1348, 1346, 1344, 1341, 1339, 1337, 1335, 359 | 1333, 1331, 1329, 1327, 1325, 1323, 1321, 1319, 360 | 1317, 1314, 1312, 1310, 1308, 1306, 1304, 1302, 361 | 1300, 1298, 1296, 1294, 1291, 1289, 1287, 1285, 362 | 1283, 1281, 1279, 1277, 1275, 1272, 1270, 1268, 363 | 1266, 1264, 1262, 1260, 1258, 1256, 1253, 1251, 364 | 1249, 1247, 1245, 1243, 1241, 1238, 1236, 1234, 365 | 1232, 1230, 1228, 1226, 1223, 1221, 1219, 1217, 366 | 1215, 1213, 1211, 1208, 1206, 1204, 1202, 1200, 367 | 1198, 1195, 1193, 1191, 1189, 1187, 1184, 1182, 368 | 1180, 1178, 1176, 1174, 1171, 1169, 1167, 1165, 369 | 1163, 1160, 1158, 1156, 1154, 1151, 1149, 1147, 370 | 1145, 1143, 1140, 1138, 1136, 1134, 1131, 1129, 371 | 1127, 1125, 1122, 1120, 1118, 1116, 1113, 1111, 372 | 1109, 1107, 1104, 1102, 1100, 1098, 1095, 1093, 373 | 1091, 1088, 1086, 1084, 1082, 1079, 1077, 1075, 374 | 1072, 1070, 1068, 1065, 1063, 1061, 1058, 1056, 375 | 1054, 1051, 1049, 1047, 1044, 1042, 1040, 1037, 376 | 1035, 1033, 1030, 1028, 1026, 1023, 1021, 1018, 377 | 1016, 1014, 1011, 1009, 1006, 1004, 1002, 999, 378 | 997, 994, 992, 989, 987, 985, 982, 980, 379 | 977, 975, 972, 970, 967, 965, 962, 960, 380 | 958, 955, 953, 950, 948, 945, 943, 940, 381 | 937, 935, 932, 930, 927, 925, 922, 920, 382 | 917, 915, 912, 909, 907, 904, 902, 899, 383 | 896, 894, 891, 889, 886, 883, 881, 878, 384 | 875, 873, 870, 867, 865, 862, 859, 857, 385 | 854, 851, 849, 846, 843, 840, 838, 835, 386 | 832, 830, 827, 824, 821, 818, 816, 813, 387 | 810, 807, 804, 802, 799, 796, 793, 790, 388 | 787, 784, 781, 779, 776, 773, 770, 767, 389 | 764, 761, 758, 755, 752, 749, 746, 743, 390 | 740, 737, 734, 731, 728, 725, 722, 719, 391 | 716, 712, 709, 706, 703, 700, 697, 694, 392 | 690, 687, 684, 681, 677, 674, 671, 668, 393 | 664, 661, 658, 654, 651, 648, 644, 641, 394 | 637, 634, 630, 627, 623, 620, 616, 613, 395 | 609, 606, 602, 599, 595, 591, 588, 584, 396 | 580, 576, 573, 569, 565, 561, 557, 554, 397 | 550, 546, 542, 538, 534, 530, 526, 522, 398 | 517, 513, 509, 505, 501, 496, 492, 488, 399 | 483, 479, 475, 470, 466, 461, 456, 452, 400 | 447, 442, 437, 433, 428, 423, 418, 413, 401 | 407, 402, 397, 392, 386, 381, 375, 370, 402 | 364, 358, 352, 346, 340, 334, 328, 321, 403 | 315, 308, 301, 294, 287, 280, 272, 265, 404 | 257, 248, 240, 231, 222, 213, 203, 192, 405 | 181, 170, 157, 143, 128, 111, 91, 64, 406 | 0 407 | }; 408 | 409 | Num normalizeAngle(Num angle) { 410 | return angle - twoPi * Util::floor(angle*inverseTwoPi); 411 | } 412 | 413 | Num sin(Num n) { 414 | const Num radians = normalizeAngle(n); 415 | const Num ratio = radians*inverseTwoPi; 416 | return Num::createByRaw(sineTable[ratio.raw]); 417 | } 418 | 419 | Num cos(Num n) { 420 | const Num radians = normalizeAngle(n); 421 | const Num ratio = radians*inverseTwoPi; 422 | return Num::createByRaw(cosineTable[ratio.raw]); 423 | } 424 | 425 | Num acos(Num n) { 426 | assert(n >= Num(-1) && n <= Num(1)); 427 | uint16_t index = Util::halve(n+Num(1)).raw; 428 | return Num::createByRaw(arcCosineTable[index]); 429 | } 430 | } 431 | } 432 | --------------------------------------------------------------------------------