mirror of
https://github.com/yuzu-emu/FasTC
synced 2024-11-22 10:54:01 +00:00
Let the compiler choose what precision we want to do the vector-scalar multiplication/division in.
This commit is contained in:
parent
366a7cdfe4
commit
2d7ee21fb7
2 changed files with 16 additions and 6 deletions
|
@ -206,7 +206,7 @@ namespace FasTC {
|
|||
static inline VectorType ScalarMultiply(const VectorType &v, const ScalarType &s) {
|
||||
VectorType a(v);
|
||||
for(int i = 0; i < VectorType::Size; i++)
|
||||
a(i) *= static_cast<typename VectorType::ScalarType>(s);
|
||||
a(i) = static_cast<typename VectorType::ScalarType>(a(i) * s);
|
||||
return a;
|
||||
}
|
||||
|
||||
|
@ -223,7 +223,7 @@ namespace FasTC {
|
|||
static inline VectorType ScalarDivide(const VectorType &v, const ScalarType &s) {
|
||||
VectorType a(v);
|
||||
for(int i = 0; i < VectorType::Size; i++)
|
||||
a(i) /= static_cast<typename VectorType::ScalarType>(s);
|
||||
a(i) = static_cast<typename VectorType::ScalarType>(a(i) / s);
|
||||
return a;
|
||||
}
|
||||
|
||||
|
|
|
@ -190,16 +190,26 @@ TEST(VectorBase, Scaling) {
|
|||
v2fd = v2f / 3;
|
||||
EXPECT_NEAR(v2fd[0], 1.0f / 3.0f, kEpsilon);
|
||||
EXPECT_NEAR(v2fd[1], 1.0f, kEpsilon);
|
||||
|
||||
unsigned uv[2] = {1, 3};
|
||||
FasTC::VectorBase<unsigned, 2> v2u (uv);
|
||||
FasTC::VectorBase<unsigned, 2> v2ud = v2u * 0.5;
|
||||
EXPECT_EQ(v2ud[0], 0);
|
||||
EXPECT_EQ(v2ud[1], 1);
|
||||
|
||||
v2ud = v2u / 0.5f;
|
||||
EXPECT_EQ(v2ud[0], 2);
|
||||
EXPECT_EQ(v2ud[1], 6);
|
||||
}
|
||||
|
||||
TEST(VectorBase, Addition) {
|
||||
float fv[2] = {1.1f, 3.2f};
|
||||
FasTC::VectorBase<float, 2> v2f (fv);
|
||||
|
||||
unsigned uv[2] = {5, 2};
|
||||
FasTC::VectorBase<unsigned, 2> v2u (uv);
|
||||
int uv[2] = {5, 2};
|
||||
FasTC::VectorBase<int, 2> v2u (uv);
|
||||
|
||||
FasTC::VectorBase<unsigned, 2> au = v2u + v2f;
|
||||
FasTC::VectorBase<int, 2> au = v2u + v2f;
|
||||
EXPECT_EQ(au[0], 6);
|
||||
EXPECT_EQ(au[1], 5);
|
||||
|
||||
|
@ -209,7 +219,7 @@ TEST(VectorBase, Addition) {
|
|||
|
||||
au = v2u - v2f;
|
||||
EXPECT_EQ(au[0], 3);
|
||||
EXPECT_EQ(au[1], 0);
|
||||
EXPECT_EQ(au[1], -1);
|
||||
|
||||
af = v2f - v2u;
|
||||
EXPECT_NEAR(af[0], -3.9f, kEpsilon);
|
||||
|
|
Loading…
Reference in a new issue