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:
authorJacques Lucke <jacques@blender.org>2020-07-16 11:46:18 +0300
committerJacques Lucke <jacques@blender.org>2020-07-16 11:46:18 +0300
commit35bfe1702c3754af17f440c7ee7cb0e9abb8fa9d (patch)
tree317c7f69eabe438062ebe41e6c0ddbeada3e8e5a /source/blender/blenlib
parent4a9d903e2bfd4f6b3f64b482344bc853a6d93236 (diff)
BLI: add safe_powf function
The same function is also used by cycles.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_math_base.h1
-rw-r--r--source/blender/blenlib/intern/math_base_inline.c7
2 files changed, 8 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h
index c456ab0ecef..49aa9f3b465 100644
--- a/source/blender/blenlib/BLI_math_base.h
+++ b/source/blender/blenlib/BLI_math_base.h
@@ -103,6 +103,7 @@ MINLINE float pow2f(float x);
MINLINE float pow3f(float x);
MINLINE float pow4f(float x);
MINLINE float pow7f(float x);
+MINLINE float safe_powf(float base, float exponent);
MINLINE float sqrt3f(float f);
MINLINE double sqrt3d(double d);
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c
index 1b388dcf11f..26dc4d35c80 100644
--- a/source/blender/blenlib/intern/math_base_inline.c
+++ b/source/blender/blenlib/intern/math_base_inline.c
@@ -70,6 +70,13 @@ MINLINE float pow7f(float x)
{
return pow2f(pow3f(x)) * x;
}
+MINLINE float safe_powf(float base, float exponent)
+{
+ if (UNLIKELY(base < 0.0f && exponent != (int)exponent)) {
+ return 0.0f;
+ }
+ return powf(base, exponent);
+}
MINLINE float sqrt3f(float f)
{