star-mc

Parallel estimation of Monte Carlo integrators
git clone git://git.meso-star.fr/star-mc.git
Log | Files | Refs | README | LICENSE

commit 37b67451efbc4fa5d430c3aab1ad67f7824c51e6
parent 2efd7d71eb5a2d3b500b95482963342205a6c6e0
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 15 Jul 2015 08:38:53 +0200

Fix a precision issue in the smc_<float|double> sqrt function

When the variance is null one could note a tiny negative value due to
numerical imprecisions. The variance is now clamped to 0 when its value
is a small negative number.

Diffstat:
Msrc/smc_type_real.h | 7+++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/smc_type_real.h b/src/smc_type_real.h @@ -33,6 +33,8 @@ #error "Missing the SMC_TYPE_REAL definition" #endif +#include <rsys/math.h> + #define SMC_REAL_FUNC__(Func) \ CONCAT(CONCAT(CONCAT(smc_, SMC_TYPE_REAL), _), Func) @@ -102,8 +104,9 @@ SMC_REAL_FUNC__(divi)(void* result, const void* op0, const size_t op1) static void SMC_REAL_FUNC__(sqrt)(void* result, const void* value) { - ASSERT(result && value && *(const SMC_TYPE_REAL*)value >= (SMC_TYPE_REAL)0); - *(SMC_TYPE_REAL*)result = (SMC_TYPE_REAL)sqrt(*(const SMC_TYPE_REAL*)value); + ASSERT(result && value && *(const SMC_TYPE_REAL*)value >= (SMC_TYPE_REAL)-1.e-6); + *(SMC_TYPE_REAL*)result = (SMC_TYPE_REAL)sqrt + (MMAX(*(const SMC_TYPE_REAL*)value, (SMC_TYPE_REAL)0.0)); } /*******************************************************************************