diff options
author | Jacques Lucke <jacques@blender.org> | 2020-07-16 11:46:18 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-07-16 11:46:18 +0300 |
commit | 35bfe1702c3754af17f440c7ee7cb0e9abb8fa9d (patch) | |
tree | 317c7f69eabe438062ebe41e6c0ddbeada3e8e5a /source/blender | |
parent | 4a9d903e2bfd4f6b3f64b482344bc853a6d93236 (diff) |
BLI: add safe_powf function
The same function is also used by cycles.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenlib/BLI_math_base.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_base_inline.c | 7 |
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) { |