mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-10 14:52:01 +00:00
compat.h: Add logbase<size_t>().
git-svn-id: https://svn.eduke32.com/eduke32@6119 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
73654c2079
commit
d3c56b8a89
1 changed files with 19 additions and 0 deletions
|
@ -936,6 +936,25 @@ CLAMP_DECL int32_t clamp2(int32_t in, int32_t min, int32_t max) { return in >= m
|
|||
CLAMP_DECL float fclamp2(float in, float min, float max) { return in >= max ? max : (in <= min ? min : in); }
|
||||
|
||||
|
||||
////////// Mathematical operations //////////
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
template <size_t base, typename T>
|
||||
CONSTEXPR size_t logbase(T n)
|
||||
{
|
||||
return n < static_cast<T>(base) ? 1 : 1 + logbase<base>(n / static_cast<T>(base));
|
||||
}
|
||||
// hackish version to work around the impossibility of representing abs(INT*_MIN)
|
||||
template <size_t base, typename T>
|
||||
CONSTEXPR size_t logbasenegative(T n)
|
||||
{
|
||||
return n > static_cast<T>(-(native_t)base) ? 1 : 1 + logbase<base>(n / static_cast<T>(-(native_t)base));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
////////// Utility functions //////////
|
||||
|
||||
#if RAND_MAX == 32767
|
||||
|
|
Loading…
Reference in a new issue