From bf4c44491a30d12a55f474cecd63680854af2d47 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 6 Feb 2015 15:40:07 +0500 Subject: [PATCH] Cycles: Some more constants fixes for fast math --- intern/cycles/util/util_math.h | 7 +++++++ intern/cycles/util/util_math_fast.h | 8 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/intern/cycles/util/util_math.h b/intern/cycles/util/util_math.h index f9e160ac822..c92b89f1639 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 540726da410..94e08320a16 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)