Ver código fonte

math: add missing operators (==, !, <= etc.) to the "half" class so that

it can at last be put into a vector.
legacy
Sam Hocevar sam 12 anos atrás
pai
commit
8bca639606
2 arquivos alterados com 13 adições e 4 exclusões
  1. +12
    -1
      src/half.h
  2. +1
    -3
      src/lol/math/vector.h

+ 12
- 1
src/half.h Ver arquivo

@@ -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)); }


+ 1
- 3
src/lol/math/vector.h Ver arquivo

@@ -1052,10 +1052,8 @@ static inline Quat<T> operator /(Quat<T> x, Quat<T> 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) \


Carregando…
Cancelar
Salvar