mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-30 18:41:14 +00:00
Simpler is_odd()/is_even(). (Let the compiler optimize.)
This commit is contained in:
parent
1364d77914
commit
265a3fbe83
@ -28,13 +28,10 @@
|
||||
#include <sstream>
|
||||
|
||||
template<typename T>
|
||||
inline bool is_odd(T num) {
|
||||
int n = static_cast< int >(num);
|
||||
return static_cast< unsigned int >(n >= 0 ? n : -n) & 1;
|
||||
}
|
||||
inline bool is_even(T num) { return num % 2 == 0; }
|
||||
|
||||
template<typename T>
|
||||
inline bool is_even(T num) { return !is_odd(num); }
|
||||
inline bool is_odd(T num) { return !is_even(num); }
|
||||
|
||||
/** Guarantees portable results for division by 100; round towards 0 */
|
||||
inline int div100rounded(int num) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user