Changeset 2385


Ignore:
Timestamp:
Feb 9, 2013, 8:31:45 PM (6 years ago)
Author:
sam
Message:

math: avoid unnecessary conversions in the half class and remove a
static method that we can do without.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lol/math/half.h

    r2354 r2385  
    3636    inline half(float f) { *this = makefast(f); }
    3737    inline half(double f) { *this = makefast((float)f); }
    38     inline half(long double f) { *this = makefast((float)f); }
     38    inline half(ldouble f) { *this = makefast((float)f); }
    3939
    4040    inline int is_nan() const
     
    6262    inline half &operator =(float f) { return *this = makefast(f); }
    6363    inline half &operator =(double f) { return *this = makefast((float)f); }
    64     inline half &operator =(long double f) { return *this = makefast((float)f); }
     64    inline half &operator =(ldouble f) { return *this = makefast((float)f); }
    6565    inline operator int8_t() const { return (int8_t)(float)*this; }
    6666    inline operator uint8_t() const { return (uint8_t)(float)*this; }
     
    7272    inline operator uint64_t() const { return (uint64_t)(float)*this; }
    7373
    74     inline operator float() const { return tofloat(*this); }
    75     inline operator double() const { return tofloat(*this); }
    76     inline operator long double() const { return tofloat(*this); }
    77 
    78     static float tofloat(half h);
     74    operator float() const;
     75    inline operator double() const { return (float)(*this); }
     76    inline operator ldouble() const { return (float)(*this); }
    7977
    8078    /* Array conversions */
     
    121119static inline half min(half a, half b) { return a < b ? a : b; }
    122120static inline half max(half a, half b) { return a > b ? a : b; }
    123 static inline half fmod(half a, half b)
     121static inline float fmod(half a, half b)
    124122{
    125123    using std::fmod;
    126     return (half)fmod((float)a, (float)b);
     124    return fmod((float)a, (float)b);
    127125}
    128 static inline half fract(half a) { return (half)fract((float)a); }
     126static inline float fract(half a) { return fract((float)a); }
    129127static inline half abs(half a) { return half::makebits(a.bits & 0x7fffu); }
    130128
     
    173171DECLARE_COERCE_FROM_HALF_OPS(float)
    174172DECLARE_COERCE_FROM_HALF_OPS(double)
    175 DECLARE_COERCE_FROM_HALF_OPS(long double)
     173DECLARE_COERCE_FROM_HALF_OPS(ldouble)
    176174
    177175#undef DECLARE_COERCE_HALF_NUMERIC_OPS
  • trunk/src/math/half.cpp

    r2216 r2385  
    227227/* Cast to float. Uses the branching version because loading the tables
    228228 * for only one value is going to be cache-expensive. */
    229 float half::tofloat(half h)
     229half::operator float() const
    230230{
    231231    union { float f; uint32_t x; } u;
    232     u.x = half_to_float_branch(h.bits);
     232    u.x = half_to_float_branch(bits);
    233233    return u.f;
    234234}
Note: See TracChangeset for help on using the changeset viewer.