bsnes/nall - revise some constexpr to be more legal+portable
This commit is contained in:
parent
a922f7bda4
commit
e60cde3314
|
@ -10,20 +10,27 @@ namespace nall {
|
||||||
|
|
||||||
template<unsigned bits>
|
template<unsigned bits>
|
||||||
constexpr inline uintmax_t uclip(const uintmax_t x) {
|
constexpr inline uintmax_t uclip(const uintmax_t x) {
|
||||||
enum : uintmax_t { b = 1ull << (bits - 1), m = b * 2 - 1 };
|
//zero 17-jun-2015 - revised to use more standard constexpr behaviour
|
||||||
return (x & m);
|
//enum : uintmax_t { b = 1ull << (bits - 1), m = b * 2 - 1 };
|
||||||
|
//return (x & m); //test
|
||||||
|
return (x & ((uintmax_t)(((uintmax_t)(1ull << (bits - 1))) * 2 - 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned bits>
|
template<unsigned bits>
|
||||||
constexpr inline intmax_t sclamp(const intmax_t x) {
|
constexpr inline intmax_t sclamp(const intmax_t x) {
|
||||||
enum : intmax_t { b = 1ull << (bits - 1), m = b - 1 };
|
//zero 17-jun-2015 - revised to use more standard constexpr behaviour
|
||||||
return (x > m) ? m : (x < -b) ? -b : x;
|
//enum : intmax_t { b = 1ull << (bits - 1), m = b - 1 };
|
||||||
|
//(intmax_t)(1ull << (bits - 1)) //b
|
||||||
|
//(((intmax_t)(1ull << (bits - 1))) - 1) //m
|
||||||
|
//return (x > m) ? m : (x < -b) ? -b : x;
|
||||||
|
return (x > (((intmax_t)(1ull << (bits - 1))) - 1)) ? (((intmax_t)(1ull << (bits - 1))) - 1) : (x < -((intmax_t)(1ull << (bits - 1)))) ? -((intmax_t)(1ull << (bits - 1))) : x; //test
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned bits>
|
template<unsigned bits>
|
||||||
constexpr inline intmax_t sclip(const intmax_t x) {
|
constexpr inline intmax_t sclip(const intmax_t x) {
|
||||||
enum : uintmax_t { b = 1ull << (bits - 1), m = b * 2 - 1 };
|
//zero 17-jun-2015 - revised to use more standard constexpr behaviour
|
||||||
return ((x & m) ^ b) - b;
|
//enum : uintmax_t { b = 1ull << (bits - 1), m = b * 2 - 1 }; //test
|
||||||
|
return ((x & ((uintmax_t)(((uintmax_t)(1ull << (bits - 1))) * 2 - 1))) ^ ((uintmax_t)(1ull << (bits - 1)))) - ((uintmax_t)(1ull << (bits - 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace bit {
|
namespace bit {
|
||||||
|
|
Loading…
Reference in New Issue