Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-12-16 13:25:07 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-12-16 13:25:07 +0400
commit2253b63c979fbfbbb6f06c93ede85d9b9b6caddf (patch)
tree6fe58202f96a7edd8448d7fbf17a14df6098d0f7 /source/blender/blenlib/intern/math_base_inline.c
parent91f14ddf3da140156c722e347b6f188210903629 (diff)
static functions for getting power of 2 values were being copied about too much, add to the BLI_math api.
- is_power_of_2_i - power_of_2_min_i - power_of_2_max_i
Diffstat (limited to 'source/blender/blenlib/intern/math_base_inline.c')
-rw-r--r--source/blender/blenlib/intern/math_base_inline.c26
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 0b2411af009..7e04e0ae566 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 */