summaryrefslogtreecommitdiff
path: root/src/common/math_util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/math_util.cpp')
-rw-r--r--src/common/math_util.cpp211
1 files changed, 0 insertions, 211 deletions
diff --git a/src/common/math_util.cpp b/src/common/math_util.cpp
deleted file mode 100644
index bcb70cae5..000000000
--- a/src/common/math_util.cpp
+++ /dev/null
@@ -1,211 +0,0 @@
1// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <cstring>
6#include <numeric> // Necessary on OS X, but not Linux
7
8#include "common/common_types.h"
9#include "common/math_util.h"
10
11namespace MathUtil
12{
13
14u32 ClassifyDouble(double dvalue)
15{
16 // TODO: Optimize the below to be as fast as possible.
17 IntDouble value;
18 value.d = dvalue;
19 u64 sign = value.i & DOUBLE_SIGN;
20 u64 exp = value.i & DOUBLE_EXP;
21 if (exp > DOUBLE_ZERO && exp < DOUBLE_EXP)
22 {
23 // Nice normalized number.
24 return sign ? PPC_FPCLASS_NN : PPC_FPCLASS_PN;
25 }
26 else
27 {
28 u64 mantissa = value.i & DOUBLE_FRAC;
29 if (mantissa)
30 {
31 if (exp)
32 {
33 return PPC_FPCLASS_QNAN;
34 }
35 else
36 {
37 // Denormalized number.
38 return sign ? PPC_FPCLASS_ND : PPC_FPCLASS_PD;
39 }
40 }
41 else if (exp)
42 {
43 //Infinite
44 return sign ? PPC_FPCLASS_NINF : PPC_FPCLASS_PINF;
45 }
46 else
47 {
48 //Zero
49 return sign ? PPC_FPCLASS_NZ : PPC_FPCLASS_PZ;
50 }
51 }
52}
53
54u32 ClassifyFloat(float fvalue)
55{
56 // TODO: Optimize the below to be as fast as possible.
57 IntFloat value;
58 value.f = fvalue;
59 u32 sign = value.i & FLOAT_SIGN;
60 u32 exp = value.i & FLOAT_EXP;
61 if (exp > FLOAT_ZERO && exp < FLOAT_EXP)
62 {
63 // Nice normalized number.
64 return sign ? PPC_FPCLASS_NN : PPC_FPCLASS_PN;
65 }
66 else
67 {
68 u32 mantissa = value.i & FLOAT_FRAC;
69 if (mantissa)
70 {
71 if (exp)
72 {
73 return PPC_FPCLASS_QNAN; // Quiet NAN
74 }
75 else
76 {
77 // Denormalized number.
78 return sign ? PPC_FPCLASS_ND : PPC_FPCLASS_PD;
79 }
80 }
81 else if (exp)
82 {
83 // Infinite
84 return sign ? PPC_FPCLASS_NINF : PPC_FPCLASS_PINF;
85 }
86 else
87 {
88 //Zero
89 return sign ? PPC_FPCLASS_NZ : PPC_FPCLASS_PZ;
90 }
91 }
92}
93
94
95} // namespace
96
97inline void MatrixMul(int n, const float *a, const float *b, float *result)
98{
99 for (int i = 0; i < n; ++i)
100 {
101 for (int j = 0; j < n; ++j)
102 {
103 float temp = 0;
104 for (int k = 0; k < n; ++k)
105 {
106 temp += a[i * n + k] * b[k * n + j];
107 }
108 result[i * n + j] = temp;
109 }
110 }
111}
112
113// Calculate sum of a float list
114float MathFloatVectorSum(const std::vector<float>& Vec)
115{
116 return std::accumulate(Vec.begin(), Vec.end(), 0.0f);
117}
118
119void Matrix33::LoadIdentity(Matrix33 &mtx)
120{
121 memset(mtx.data, 0, sizeof(mtx.data));
122 mtx.data[0] = 1.0f;
123 mtx.data[4] = 1.0f;
124 mtx.data[8] = 1.0f;
125}
126
127void Matrix33::RotateX(Matrix33 &mtx, float rad)
128{
129 float s = sin(rad);
130 float c = cos(rad);
131 memset(mtx.data, 0, sizeof(mtx.data));
132 mtx.data[0] = 1;
133 mtx.data[4] = c;
134 mtx.data[5] = -s;
135 mtx.data[7] = s;
136 mtx.data[8] = c;
137}
138void Matrix33::RotateY(Matrix33 &mtx, float rad)
139{
140 float s = sin(rad);
141 float c = cos(rad);
142 memset(mtx.data, 0, sizeof(mtx.data));
143 mtx.data[0] = c;
144 mtx.data[2] = s;
145 mtx.data[4] = 1;
146 mtx.data[6] = -s;
147 mtx.data[8] = c;
148}
149
150void Matrix33::Multiply(const Matrix33 &a, const Matrix33 &b, Matrix33 &result)
151{
152 MatrixMul(3, a.data, b.data, result.data);
153}
154
155void Matrix33::Multiply(const Matrix33 &a, const float vec[3], float result[3])
156{
157 for (int i = 0; i < 3; ++i) {
158 result[i] = 0;
159 for (int k = 0; k < 3; ++k) {
160 result[i] += a.data[i * 3 + k] * vec[k];
161 }
162 }
163}
164
165void Matrix44::LoadIdentity(Matrix44 &mtx)
166{
167 memset(mtx.data, 0, sizeof(mtx.data));
168 mtx.data[0] = 1.0f;
169 mtx.data[5] = 1.0f;
170 mtx.data[10] = 1.0f;
171 mtx.data[15] = 1.0f;
172}
173
174void Matrix44::LoadMatrix33(Matrix44 &mtx, const Matrix33 &m33)
175{
176 for (int i = 0; i < 3; ++i)
177 {
178 for (int j = 0; j < 3; ++j)
179 {
180 mtx.data[i * 4 + j] = m33.data[i * 3 + j];
181 }
182 }
183
184 for (int i = 0; i < 3; ++i)
185 {
186 mtx.data[i * 4 + 3] = 0;
187 mtx.data[i + 12] = 0;
188 }
189 mtx.data[15] = 1.0f;
190}
191
192void Matrix44::Set(Matrix44 &mtx, const float mtxArray[16])
193{
194 for(int i = 0; i < 16; ++i) {
195 mtx.data[i] = mtxArray[i];
196 }
197}
198
199void Matrix44::Translate(Matrix44 &mtx, const float vec[3])
200{
201 LoadIdentity(mtx);
202 mtx.data[3] = vec[0];
203 mtx.data[7] = vec[1];
204 mtx.data[11] = vec[2];
205}
206
207void Matrix44::Multiply(const Matrix44 &a, const Matrix44 &b, Matrix44 &result)
208{
209 MatrixMul(4, a.data, b.data, result.data);
210}
211