Changeset 1053 for cpp


Ignore:
Timestamp:
12/27/20 19:35:00 (3 years ago)
Author:
Maciej Komosinski
Message:

Implemented missing ffs(int) for Windows compilers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/nonstd_math.h

    r979 r1053  
    7878void fpExceptDisable();
    7979
    80 // std::lerp can be used since c++20 (and has some guaranteed properties probably better than this basic formula) but apparently it is not a template
     80// std::lerp can be used since C++20 (and has some guaranteed properties probably better than this basic formula) but apparently it is not a template
    8181template <typename Value, typename Linear> Value universal_lerp(Value a,Value b,Linear t) {return a*(1-t)+b*t;}
    8282
     
    8686}
    8787
     88//in C++20, related: https://en.cppreference.com/w/cpp/numeric/countl_zero
     89#ifdef _WIN32 //visual studio is missing ffs()
     90static inline unsigned ffs(int x)
     91{
     92        if (x == 0) return 0u;
     93        unsigned r = 1;
     94        while ((x & 1) == 0)
     95                x >>= 1, ++r;
     96        return r;
     97}
    8898#endif
     99
     100
     101#endif
Note: See TracChangeset for help on using the changeset viewer.