diff --git a/source/core/include/math/dvc_fix_point.h b/source/core/include/math/dvc_fix_point.h index fa3ca3a..18799c1 100644 --- a/source/core/include/math/dvc_fix_point.h +++ b/source/core/include/math/dvc_fix_point.h @@ -62,6 +62,11 @@ public: return static_cast(s1516 >> kShift); } + static ifloat32 from_raw(int32_t raw) { + ifloat32 ret; + ret.s1516 = raw; + return ret; + } public: inline ifloat32& operator = (const ifloat32& other) { s1516 = other.s1516; @@ -99,56 +104,34 @@ public: //Adds the two FP numbers together. inline friend ifloat32 operator + (const ifloat32& l, const ifloat32& r) { int64_t t = static_cast(l.s1516) + static_cast(r.s1516); - - ifloat32 ret; - ret.s1516 = static_cast(t); - return ret; + return from_raw(t); } //Subtracts the two FP numbers from each other. inline friend ifloat32 operator - (const ifloat32& l, const ifloat32& r) { int64_t t = static_cast(l.s1516) - static_cast(r.s1516); - - ifloat32 ret; - ret.s1516 = t; - return ret; + return from_raw(t); } inline friend ifloat32 operator * (const ifloat32& a, const float32_t& b) { int64_t t = static_cast(a.s1516) * static_cast(b * kFloatScale); - - t = t >> kShift; - - ifloat32 ret; - ret.s1516 = t; - return ret; + return from_raw(t >> kShift); } inline friend ifloat32 operator * (const ifloat32& a, const int32_t& b) { - ifloat32 ret; - ret.s1516 = a.s1516 * b; - return ret; + return from_raw(a.s1516 * b); } //Multiplies two FP values together. inline friend ifloat32 operator * (const ifloat32& a, const ifloat32& b) { int64_t t = static_cast(a.s1516) * static_cast(b.s1516); - - t = t >> kShift; - - ifloat32 ret; - ret.s1516 = static_cast(t); - return ret; + return from_raw(static_cast(t >> kShift)); } inline friend ifloat32 operator / (const ifloat32& a, const ifloat32& b) { // pre-multiply by the base int64_t t = static_cast(a.s1516) << kShift; - t /= b.s1516; - - ifloat32 ret; - ret.s1516 = static_cast(t); - return ret; + return from_raw(static_cast(t/ b.s1516)); } public: @@ -297,7 +280,7 @@ public: ret.s3132 = _safeMulti(a.s3132, b.s3132); return ret; } - + inline friend ifloat64 operator / (const ifloat64& a, const ifloat64& b) { // From http://www.hackersdelight.org/hdcodetxt/divlu.c.txt @@ -369,7 +352,7 @@ public: ret.s3132 = (sign_dif < 0) ? -(int64_t)t : (int64_t)t; return ret; } - + public: static int64_t _safeMulti(const int64_t a, const int64_t b) { int64_t sign_diff = a ^ b; @@ -440,6 +423,12 @@ struct iFloat3 z = z * multiplier; } + inline void mul(const int32_t& multiplier) { + x = x * multiplier; + y = y * multiplier; + z = z * multiplier; + } + inline iFloat operator [] (const size_t i) const { return *(&x + i); }