Changeset 1176 for trunk/src/lol/math/half.h
 Timestamp:
 Mar 27, 2012, 9:53:54 PM (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/lol/math/half.h
r1161 r1176 32 32 inline half(float f) { *this = makefast(f); } 33 33 inline half(double f) { *this = makefast((float)f); } 34 inline half(long double f) { *this = makefast((float)f); } 34 35 35 36 inline int is_nan() const … … 57 58 inline half &operator =(float f) { return *this = makefast(f); } 58 59 inline half &operator =(double f) { return *this = makefast((float)f); } 59 inline operator int() const { return (int)tofloat(*this); } 60 inline half &operator =(long double f) { return *this = makefast((float)f); } 61 inline operator int8_t() const { return (int8_t)(float)*this; } 62 inline operator uint8_t() const { return (uint8_t)(float)*this; } 63 inline operator int16_t() const { return (int16_t)(float)*this; } 64 inline operator uint16_t() const { return (uint16_t)(float)*this; } 65 inline operator int32_t() const { return (int32_t)(float)*this; } 66 inline operator uint32_t() const { return (uint32_t)(float)*this; } 67 inline operator int64_t() const { return (int64_t)(float)*this; } 68 inline operator uint64_t() const { return (uint64_t)(float)*this; } 69 60 70 inline operator float() const { return tofloat(*this); } 71 inline operator double() const { return tofloat(*this); } 72 inline operator long double() const { return tofloat(*this); } 61 73 62 74 static float tofloat(half h); … … 79 91 inline half operator () const { return makebits(bits ^ 0x8000u); } 80 92 inline half operator +() const { return *this; } 81 inline half &operator +=(float f) { return (*this = (half)(*this + f)); }82 inline half &operator =(float f) { return (*this = (half)(*this  f)); }83 inline half &operator *=(float f) { return (*this = (half)(*this * f)); }84 inline half &operator /=(float f) { return (*this = (half)(*this / f)); }85 93 inline half &operator +=(half h) { return (*this = (half)(*this + h)); } 86 94 inline half &operator =(half h) { return (*this = (half)(*this  h)); } … … 88 96 inline half &operator /=(half h) { return (*this = (half)(*this / h)); } 89 97 90 inline float operator +(float f) const { return (float)*this + f; }91 inline float operator (float f) const { return (float)*this  f; }92 inline float operator *(float f) const { return (float)*this * f; }93 inline float operator /(float f) const { return (float)*this / f; }94 98 inline float operator +(half h) const { return (float)*this + (float)h; } 95 99 inline float operator (half h) const { return (float)*this  (float)h; } … … 111 115 }; 112 116 113 inline float &operator +=(float &f, half h) { return f += (float)h; } 114 inline float &operator =(float &f, half h) { return f = (float)h; } 115 inline float &operator *=(float &f, half h) { return f *= (float)h; } 116 inline float &operator /=(float &f, half h) { return f /= (float)h; } 117 #define DECLARE_COERCE_HALF_NUMERIC_OPS(op, type, ret, x2, h2) \ 118 inline ret operator op(type x, half h) { return x2 op h2; } \ 119 inline ret operator op(half h, type x) { return h2 op x2; } \ 120 inline type &operator op##=(type &x, half h) { return x = x op h2; } \ 121 inline half &operator op##=(half &h, type x) { return h = h op x2; } 117 122 118 inline float operator +(float f, half h) { return f + (float)h; } 119 inline float operator (float f, half h) { return f  (float)h; } 120 inline float operator *(float f, half h) { return f * (float)h; } 121 inline float operator /(float f, half h) { return f / (float)h; } 123 #define DECLARE_COERCE_HALF_BOOL_OPS(op, type, x2, h2) \ 124 inline bool operator op(type x, half h) { return x2 op h2; } \ 125 inline bool operator op(half h, type x) { return h2 op x2; } 126 127 #define DECLARE_COERCE_HALF_OPS(type, ret, x2, h2) \ 128 DECLARE_COERCE_HALF_NUMERIC_OPS(+, type, ret, x2, h2) \ 129 DECLARE_COERCE_HALF_NUMERIC_OPS(, type, ret, x2, h2) \ 130 DECLARE_COERCE_HALF_NUMERIC_OPS(*, type, ret, x2, h2) \ 131 DECLARE_COERCE_HALF_NUMERIC_OPS(/, type, ret, x2, h2) \ 132 \ 133 DECLARE_COERCE_HALF_BOOL_OPS(==, type, x2, h2) \ 134 DECLARE_COERCE_HALF_BOOL_OPS(!=, type, x2, h2) \ 135 DECLARE_COERCE_HALF_BOOL_OPS(>=, type, x2, h2) \ 136 DECLARE_COERCE_HALF_BOOL_OPS(<=, type, x2, h2) \ 137 DECLARE_COERCE_HALF_BOOL_OPS(>, type, x2, h2) \ 138 DECLARE_COERCE_HALF_BOOL_OPS(<, type, x2, h2) 139 140 #define DECLARE_COERCE_TO_HALF_OPS(type) \ 141 DECLARE_COERCE_HALF_OPS(type, half, (half)(int)x, h) 142 143 #define DECLARE_COERCE_FROM_HALF_OPS(type) \ 144 DECLARE_COERCE_HALF_OPS(type, type, x, (type)h) 145 146 DECLARE_COERCE_TO_HALF_OPS(int8_t) 147 DECLARE_COERCE_TO_HALF_OPS(uint8_t) 148 DECLARE_COERCE_TO_HALF_OPS(int16_t) 149 DECLARE_COERCE_TO_HALF_OPS(uint16_t) 150 DECLARE_COERCE_TO_HALF_OPS(int32_t) 151 DECLARE_COERCE_TO_HALF_OPS(uint32_t) 152 DECLARE_COERCE_TO_HALF_OPS(int64_t) 153 DECLARE_COERCE_TO_HALF_OPS(uint64_t) 154 155 DECLARE_COERCE_FROM_HALF_OPS(float) 156 DECLARE_COERCE_FROM_HALF_OPS(double) 157 DECLARE_COERCE_FROM_HALF_OPS(long double) 158 159 #undef DECLARE_COERCE_HALF_NUMERIC_OPS 160 #undef DECLARE_COERCE_HALF_OPS 161 #undef DECLARE_COERCE_TO_HALF_OPS 162 #undef DECLARE_COERCE_FROM_HALF_OPS 122 163 123 164 } /* namespace lol */
Note: See TracChangeset
for help on using the changeset viewer.