[Bf-blender-cvs] [bf4c444] master: Cycles: Some more constants fixes for fast math

Sergey Sharybin noreply at git.blender.org
Fri Feb 6 11:40:25 CET 2015


Commit: bf4c44491a30d12a55f474cecd63680854af2d47
Author: Sergey Sharybin
Date:   Fri Feb 6 15:40:07 2015 +0500
Branches: master
https://developer.blender.org/rBbf4c44491a30d12a55f474cecd63680854af2d47

Cycles: Some more constants fixes for fast math

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

M	intern/cycles/util/util_math.h
M	intern/cycles/util/util_math_fast.h

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

diff --git a/intern/cycles/util/util_math.h b/intern/cycles/util/util_math.h
index f9e160a..c92b89f 100644
--- a/intern/cycles/util/util_math.h
+++ b/intern/cycles/util/util_math.h
@@ -71,6 +71,13 @@ CCL_NAMESPACE_BEGIN
 #define M_SQRT2_F	((float)1.41421356237309504880) 					/* sqrt(2) */
 #endif
 
+#ifndef M_LN2_F
+#define M_LN2_F      ((float)0.6931471805599453)        /* ln(2) */
+#endif
+
+#ifndef M_LN10_F
+#define M_LN10_F     ((float)2.3025850929940457)        /* ln(10) */
+#endif
 
 /* Scalar */
 
diff --git a/intern/cycles/util/util_math_fast.h b/intern/cycles/util/util_math_fast.h
index 540726d..94e0832 100644
--- a/intern/cycles/util/util_math_fast.h
+++ b/intern/cycles/util/util_math_fast.h
@@ -387,7 +387,7 @@ ccl_device_inline float fast_logf(float x)
 	/* Examined 2130706432 values of logf on [1.17549435e-38,3.40282347e+38]:
 	 * 0.313865375 avg ulp diff, 5148137 max ulp, 7.62939e-06 max error.
 	 */
-	return fast_log2f(x) * float(M_LN2);
+	return fast_log2f(x) * M_LN2_F;
 }
 
 ccl_device_inline float fast_log10(float x)
@@ -395,7 +395,7 @@ ccl_device_inline float fast_log10(float x)
 	/* Examined 2130706432 values of log10f on [1.17549435e-38,3.40282347e+38]:
 	 * 0.631237033 avg ulp diff, 4471615 max ulp, 3.8147e-06 max error.
 	 */
-	return fast_log2f(x) * float(M_LN2 / M_LN10);
+	return fast_log2f(x) * M_LN2_F / M_LN10_F;
 }
 
 ccl_device float fast_logb(float x)
@@ -438,7 +438,7 @@ ccl_device_inline float fast_expf(float x)
 	/* Examined 2237485550 values of exp on [-87.3300018,87.3300018]:
 	 * 2.6666452 avg ulp diff, 230 max ulp.
 	 */
-	return fast_exp2f(x * float(1.0 / M_LN2));
+	return fast_exp2f(x / M_LN2_F);
 }
 
 ccl_device_inline float fast_exp10(float x)
@@ -446,7 +446,7 @@ ccl_device_inline float fast_exp10(float x)
 	/* Examined 2217701018 values of exp10 on [-37.9290009,37.9290009]:
 	 * 2.71732409 avg ulp diff, 232 max ulp.
 	 */
-	return fast_exp2f(x * float(M_LN10 / M_LN2));
+	return fast_exp2f(x * M_LN10_F / M_LN2_F);
 }
 
 ccl_device_inline float fast_expm1f(float x)




More information about the Bf-blender-cvs mailing list