diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-01-19 16:41:04 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-01-19 16:51:11 +0300 |
commit | 78b94902f839f0fb84e253d3ff1a34cc6cc51919 (patch) | |
tree | fa3f282eebff1fc8f3cbbffa8aa7aeb8df78d1f1 /intern/cycles/util | |
parent | 6d36e033ba4051362a3a4985989e9d360e3888a8 (diff) |
Cycles: Add fast-math safe isnan and isfinite
Currently unused, but might become really handy in the future.
Diffstat (limited to 'intern/cycles/util')
-rw-r--r-- | intern/cycles/util/util_math.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/intern/cycles/util/util_math.h b/intern/cycles/util/util_math.h index 6cb68b53d16..d0062646414 100644 --- a/intern/cycles/util/util_math.h +++ b/intern/cycles/util/util_math.h @@ -1233,6 +1233,20 @@ ccl_device_inline float __uint_as_float(uint i) return u.f; } +/* Versions of functions which are safe for fast math. */ +ccl_device_inline bool isnan_safe(float f) +{ + unsigned int x = __float_as_uint(f); + return (x << 1) > 0xff000000u; +} + +ccl_device_inline bool isfinite_safe(float f) +{ + /* By IEEE 754 rule, 2*Inf equals Inf */ + unsigned int x = __float_as_uint(f); + return (f == f) && (x == 0 || (f != 2.0f*f)); +} + /* Interpolation */ template<class A, class B> A lerp(const A& a, const A& b, const B& t) |