From f8c9b936cd0655f1ebe54f8c1f2a742cdbdbe0e7 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 22 Jan 2011 14:42:08 +0000 Subject: [PATCH] Fix FPE with integer vector division --- include/Maths.hpp | 8 +++++--- tools/MathsTest.cpp | 12 ++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/Maths.hpp b/include/Maths.hpp index 98951db..276768b 100644 --- a/include/Maths.hpp +++ b/include/Maths.hpp @@ -45,7 +45,7 @@ struct Packed { u.f[0] = a; u.f[1] = b; u.f[2] = c; - u.f[3] = 0.0f; + u.f[3] = 1.0f; return u.p; } }; @@ -63,7 +63,7 @@ struct Packed { u.i[0] = a; u.i[1] = b; u.i[2] = c; - u.i[3] = 0; + u.i[3] = 1; return u.p; } }; @@ -131,7 +131,7 @@ struct Vector { // Magnitude inline T length() const { - const float prod = dot(*this); + const T prod = dot(*this); return sqrt(prod); } @@ -203,6 +203,8 @@ struct Vector { }; typedef Vector VectorF; +typedef Vector VectorD; +typedef Vector VectorI; template std::ostream& operator<<(std::ostream& s, const Vector& v) diff --git a/tools/MathsTest.cpp b/tools/MathsTest.cpp index 494c79f..a2a95cd 100644 --- a/tools/MathsTest.cpp +++ b/tools/MathsTest.cpp @@ -1,8 +1,8 @@ -#include "Maths.hpp" - #include #include +#include "Maths.hpp" + /* Baseline: @@ -388,5 +388,13 @@ int main(int argc, char **argv) vfnorm(a); assert(vflen(a) > 0.999f && vflen(a) < 1.001f); + VectorI x = make_vector(1, 0, 0); + VectorI y = make_vector(0, 1, 0); + + VectorI d = x - y; + d.normalise(); + + cout << d << endl; + return 0; } -- 2.39.2