ape  0.5.0
Audio Programming Environment
mathutil.h
Go to the documentation of this file.
1 #ifndef CPPAPE_MATHUTIL_H
2 #define CPPAPE_MATHUTIL_H
3 
4 #include <cmath>
5 #include <algorithm>
6 
7 namespace ape
8 {
15  inline std::size_t clamp_available(std::size_t position, std::size_t size, std::size_t available)
16  {
17  return std::min(available, size - position);
18  }
19 
23  inline size_t nextpow2(size_t current)
24  {
25  size_t p = 1;
26  while (p < current)
27  p <<= 1;
28  return p;
29  }
30 
34  inline size_t nextpow2above(size_t current)
35  {
36  size_t p = 1;
37  while (p <= current)
38  p <<= 1;
39  return p;
40  }
41 
45  template<typename UIntType>
46  inline typename std::enable_if<std::is_unsigned<UIntType>::value, bool>::type ispow2(UIntType t)
47  {
48  return (t & (t - 1)) == 0;
49  }
50 }
51 
52 #endif
ape
Definition: audiofile.h:7
ape::nextpow2above
size_t nextpow2above(size_t current)
Returns the next power of two, above current
Definition: mathutil.h:34
ape::ispow2
std::enable_if< std::is_unsigned< UIntType >::value, bool >::type ispow2(UIntType t)
Tests whether t is a power of two.
Definition: mathutil.h:46
ape::clamp_available
std::size_t clamp_available(std::size_t position, std::size_t size, std::size_t available)
Step N towards size given available "samples", if at position sample. This is a useful utility to ...
Definition: mathutil.h:15
ape::nextpow2
size_t nextpow2(size_t current)
Returns the next power of two, or equivalent to current
Definition: mathutil.h:23