Changeset 2192


Ignore:
Timestamp:
Jan 2, 2013, 1:53:39 PM (10 years ago)
Author:
sam
Message:

math: implement fract() for vectors and scalar types.

Location:
trunk/src/lol/math
Files:
3 edited

Legend:

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

    r2183 r2192  
    126126    return (half)fmod((float)a, (float)b);
    127127}
     128static inline half fract(half a) { return (half)fract((float)a); }
    128129static inline half abs(half a) { return half::makebits(a.bits & 0x7fffu); }
    129130
  • trunk/src/lol/math/math.h

    r2188 r2192  
    3333static inline double sqrt(double const &x) { return std::sqrt(x); }
    3434static inline float sqrt(float const &x) { return std::sqrt(x); }
     35
     36static inline double exp(double const &x) { return std::exp(x); }
     37static inline float exp(float const &x) { return std::exp(x); }
    3538
    3639static inline double sin(double const &x) { return std::sin(x); }
     
    139142static inline ldouble fmod(ldouble x, ldouble y) { return std::fmod(x, y); }
    140143
     144static inline uint8_t fract(uint8_t x) { return 0; }
     145static inline int8_t fract(int8_t x) { return 0; }
     146static inline uint16_t fract(uint16_t x) { return 0; }
     147static inline int16_t fract(int16_t x) { return 0; }
     148static inline uint32_t fract(uint32_t x) { return 0; }
     149static inline int32_t fract(int32_t x) { return 0; }
     150static inline uint64_t fract(uint64_t x) { return 0; }
     151static inline int64_t fract(int64_t x) { return 0; }
     152static inline float fract(float x) { return x - std::floor(x); }
     153static inline double fract(double x) { return x - std::floor(x); }
     154static inline ldouble fract(ldouble x) { return x - std::floor(x); }
     155
    141156static inline uint8_t min(uint8_t x, uint8_t y) { return std::min(x, y); }
    142157static inline int8_t min(int8_t x, int8_t y) { return std::min(x, y); }
  • trunk/src/lol/math/vector.h

    r2183 r2192  
    11361136
    11371137/*
     1138 * vec mix(vec, vec, vec)
     1139 * vec mix(vec, vec, scalar)
     1140 */
     1141#define LOL_VECTOR_MIX_FUN(tname, tprefix, type) \
     1142    tprefix \
     1143    inline tname<type> mix(tname<type> const &x, \
     1144                           tname<type> const &y, tname<type> const &a) \
     1145    { \
     1146        return x + a * (y - x); \
     1147    } \
     1148    \
     1149    tprefix \
     1150    inline tname<type> mix(tname<type> const &x, \
     1151                           tname<type> const &y, type const &a) \
     1152    { \
     1153        return x + a * (y - x); \
     1154    }
     1155
     1156/*
    11381157 * bool ==(vec, vec)   (also complex & quaternion)
    11391158 * bool !=(vec, vec)   (also complex & quaternion)
     
    12161235    { \
    12171236        return (type)sqrt((double)sqlength(a)); \
     1237    } \
     1238    \
     1239    tprefix \
     1240    inline tname<type> fract(tname<type> const &a) \
     1241    { \
     1242        tname<type> ret; \
     1243        for (size_t n = 0; n < sizeof(a) / sizeof(type); n++) \
     1244            ret[n] = fract(a[n]); \
     1245        return ret; \
    12181246    } \
    12191247    \
     
    12941322    LOL_VECTOR_MINMAX_FUN(tname, max, tprefix, type) \
    12951323    LOL_VECTOR_MINMAX_FUN(tname, fmod, tprefix, type) \
    1296     LOL_VECTOR_CLAMP_FUN(tname, tprefix, type)
     1324    LOL_VECTOR_CLAMP_FUN(tname, tprefix, type) \
     1325    LOL_VECTOR_MIX_FUN(tname, tprefix, type)
    12971326
    12981327#define LOL_VECTOR_COERCE_OPS(tname, tprefix, t1, t2, tf) \
     
    15641593#undef LOL_VECTOR_MINMAX_FUN
    15651594#undef LOL_VECTOR_CLAMP_FUN
     1595#undef LOL_VECTOR_MIX_FUN
    15661596#undef LOL_VECTOR_VECTOR_BOOL_OP
    15671597#undef LOL_VECTOR_SCALAR_COERCE_OP
Note: See TracChangeset for help on using the changeset viewer.