diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-12-17 03:26:29 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-12-17 03:26:29 +0400 |
commit | e5b1f9c28d52254fd11e226ed4ac7bf07d7259d7 (patch) | |
tree | b3a36c302cf470ed5e7c7a195e760623c82bbc7e /source/blender/blenlib/intern | |
parent | d46712cd298f59405646fc44acef52fbb11d2f82 (diff) | |
parent | 3c8ab559a5bd31fd38e9c5cf9da8505ca28f4887 (diff) |
svn merge ^/trunk/blender -r42660:42669
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/math_base_inline.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index 9c7b30bbc67..3977940d135 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -115,6 +115,31 @@ MINLINE float power_of_2(float val) return (float)pow(2.0, ceil(log((double)val) / M_LN2)); } +MINLINE int is_power_of_2_i(int n) +{ + return (n & (n - 1)) == 0; +} + +MINLINE int power_of_2_max_i(int n) +{ + if (is_power_of_2_i(n)) + return n; + + while(!is_power_of_2_i(n)) + n = n & (n - 1); + + return n * 2; +} + +MINLINE int power_of_2_min_i(int n) +{ + while (!is_power_of_2_i(n)) + n = n & (n - 1); + + return n; +} + + MINLINE float minf(float a, float b) { return (a < b)? a: b; @@ -130,5 +155,6 @@ MINLINE float signf(float f) return (f < 0.f)? -1.f: 1.f; } + #endif /* BLI_MATH_BASE_INLINE_H */ |