From 8bca639606f50473bed86bec1aa63909d333f7db Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 2 Mar 2012 17:48:55 +0000 Subject: [PATCH] math: add missing operators (==, !, <= etc.) to the "half" class so that it can at last be put into a vector. --- src/half.h | 13 ++++++++++++- src/lol/math/vector.h | 4 +--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/half.h b/src/half.h index 8d1cb6ae..77e042cf 100644 --- a/src/half.h +++ b/src/half.h @@ -66,7 +66,18 @@ public: static size_t convert(float *dst, half const *src, size_t nelem); /* Operations */ - inline half operator -() { return makebits(bits ^ 0x8000u); } + bool operator ==(half x) const { return (float)*this == (float)x; } + bool operator !=(half x) const { return (float)*this != (float)x; } + bool operator <(half x) const { return (float)*this < (float)x; } + bool operator >(half x) const { return (float)*this > (float)x; } + bool operator <=(half x) const { return (float)*this <= (float)x; } + bool operator >=(half x) const { return (float)*this >= (float)x; } + + bool operator !() const { return !(bool)*this; } + operator bool() const { return bits & 0x7fffu; } + + inline half operator -() const { return makebits(bits ^ 0x8000u); } + inline half operator +() const { return *this; } inline half &operator +=(float f) { return (*this = (half)(*this + f)); } inline half &operator -=(float f) { return (*this = (half)(*this - f)); } inline half &operator *=(float f) { return (*this = (half)(*this * f)); } diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index 0206141d..69e4cc10 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -1052,10 +1052,8 @@ static inline Quat operator /(Quat x, Quat const &y) DECLARE_BOOL_OP(tname, <, <, true, tprefix, T) \ DECLARE_BOOL_OP(tname, >, >, true, tprefix, T) -/* FIXME: a few problems need to be fixed before we can use "half" here. It - * will probably never work until we switch to C++11 because it's not really - * a POD class. */ #define DECLARE_GLOBAL_TYPED_OPS(tname) \ + DECLARE_ALL_GLOBAL_OPS(tname, /* empty */, half) \ DECLARE_ALL_GLOBAL_OPS(tname, /* empty */, float) \ DECLARE_ALL_GLOBAL_OPS(tname, /* empty */, double) \ DECLARE_ALL_GLOBAL_OPS(tname, /* empty */, int8_t) \