[Bf-blender-cvs] [78b94902f8] master: Cycles: Add fast-math safe isnan and isfinite

Sergey Sharybin noreply at git.blender.org
Thu Jan 19 14:53:27 CET 2017


Commit: 78b94902f839f0fb84e253d3ff1a34cc6cc51919
Author: Sergey Sharybin
Date:   Thu Jan 19 14:41:04 2017 +0100
Branches: master
https://developer.blender.org/rB78b94902f839f0fb84e253d3ff1a34cc6cc51919

Cycles: Add fast-math safe isnan and isfinite

Currently unused, but might become really handy in the future.

===================================================================

M	intern/cycles/util/util_math.h

===================================================================

diff --git a/intern/cycles/util/util_math.h b/intern/cycles/util/util_math.h
index 6cb68b53d1..d006264641 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)




More information about the Bf-blender-cvs mailing list