Changeset 1150


Ignore:
Timestamp:
Mar 2, 2012, 6:48:55 PM (8 years ago)
Author:
sam
Message:

math: add missing operators (==, !, <= etc.) to the "half" class so that
it can at last be put into a vector.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/half.h

    r1146 r1150  
    6767
    6868    /* Operations */
    69     inline half operator -() { return makebits(bits ^ 0x8000u); }
     69    bool operator ==(half x) const { return (float)*this == (float)x; }
     70    bool operator !=(half x) const { return (float)*this != (float)x; }
     71    bool operator <(half x) const { return (float)*this < (float)x; }
     72    bool operator >(half x) const { return (float)*this > (float)x; }
     73    bool operator <=(half x) const { return (float)*this <= (float)x; }
     74    bool operator >=(half x) const { return (float)*this >= (float)x; }
     75
     76    bool operator !() const { return !(bool)*this; }
     77    operator bool() const { return bits & 0x7fffu; }
     78
     79    inline half operator -() const { return makebits(bits ^ 0x8000u); }
     80    inline half operator +() const { return *this; }
    7081    inline half &operator +=(float f) { return (*this = (half)(*this + f)); }
    7182    inline half &operator -=(float f) { return (*this = (half)(*this - f)); }
  • trunk/src/lol/math/vector.h

    r1149 r1150  
    10531053    DECLARE_BOOL_OP(tname, >, >, true, tprefix, T)
    10541054
    1055 /* FIXME: a few problems need to be fixed before we can use "half" here. It
    1056  * will probably never work until we switch to C++11 because it's not really
    1057  * a POD class. */
    10581055#define DECLARE_GLOBAL_TYPED_OPS(tname) \
     1056    DECLARE_ALL_GLOBAL_OPS(tname, /* empty */, half) \
    10591057    DECLARE_ALL_GLOBAL_OPS(tname, /* empty */, float) \
    10601058    DECLARE_ALL_GLOBAL_OPS(tname, /* empty */, double) \
Note: See TracChangeset for help on using the changeset viewer.