From: Joris Mooij Date: Tue, 13 Nov 2012 18:01:20 +0000 (+0100) Subject: Fixed division-by-zero issue in pow() which caused problems for GLC+ with sparse... X-Git-Tag: v0.3.2~10 X-Git-Url: http://git.tuebingen.mpg.de/?p=libdai.git;a=commitdiff_plain;h=c406c485e89581c7464ff880831a956cb9406706 Fixed division-by-zero issue in pow() which caused problems for GLC+ with sparse factors --- diff --git a/ChangeLog b/ChangeLog index 748649a..10f6e80 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ git HEAD -------- +* Fixed division-by-zero issue in pow() which caused problems for GLC+ with sparse factors * Fixed bugs in unit test prob_test.cpp: replaced all occurences of BOOST_CHECK_CLOSE(...,(Real)0.0,tol) with BOOST_CHECK_SMALL(...,tol) * Merged Generalized Loop Correction code kindly provided by Siamak Ravanbakhsh diff --git a/include/dai/util.h b/include/dai/util.h index 3565ca0..dba4002 100644 --- a/include/dai/util.h +++ b/include/dai/util.h @@ -124,9 +124,15 @@ inline Real exp( Real x ) { return std::exp(x); } -/// Returns \a to the power \a y +/// Returns \a x to the power \a y +/** We use the convention that division by zero yields zero; + * for powers, this means that if \a x == 0.0 and \a y < 0.0, we + * return 0.0 instead of generating an error. + */ inline Real pow( Real x, Real y ) { errno = 0; + if( x == 0.0 && y < 0.0 ) + return 0.0; Real result = std::pow(x, y); DAI_DEBASSERT( errno == 0 ); return result;