Changeset 2536


Ignore:
Timestamp:
Mar 1, 2013, 5:24:20 PM (8 years ago)
Author:
sam
Message:

math: try to refactor rand() to bypass an X360 compiler bug.

File:
1 edited

Legend:

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

    r2526 r2536  
    3434}
    3535
    36 template<>
    37 inline half rand<half>(half a) { return a * std::rand() / RAND_MAX; }
    38 template<>
    39 inline float rand<float>(float a) { return a * std::rand() / RAND_MAX; }
    40 template<>
    41 inline double rand<double>(double a) { return a * std::rand() / RAND_MAX; }
    42 template<>
    43 inline ldouble rand<ldouble>(ldouble a) { return a * std::rand() / RAND_MAX; }
     36template<> inline half rand<half>(half a)
     37{
     38    float f = (float)std::rand() / (float)RAND_MAX;
     39    return (half)(a * f);
     40}
     41
     42template<> inline float rand<float>(float a)
     43{
     44    float f = (float)std::rand() / (float)RAND_MAX;
     45    return a * f;
     46}
     47
     48template<> inline double rand<double>(double a)
     49{
     50    double f = (double)std::rand() / (double)RAND_MAX;
     51    return a * f;
     52}
     53
     54template<> inline ldouble rand<ldouble>(ldouble a)
     55{
     56    ldouble f = (ldouble)std::rand() / (ldouble)RAND_MAX;
     57    return a * f;
     58}
    4459
    4560/* Two-value random number generator -- no need for specialisation */
Note: See TracChangeset for help on using the changeset viewer.