diff options
author | Eike Rathke <erack@redhat.com> | 2015-10-24 21:30:14 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2015-10-24 21:34:51 +0200 |
commit | 5f2db274dbf4d8b808f9ddbe4959deadbc1ec9fa (patch) | |
tree | b7a5640e06d7849f976a435feb989dcd61ddf887 /sal | |
parent | 0d4f422300d81dcb9d875885c988e88a926fb722 (diff) |
implement proper Inf and NaN handling in rtl_math_erf() and rtl_math_erfc()
Change-Id: Ib96d7123a3c483e9a1c78666bf042396510d733f
Diffstat (limited to 'sal')
-rw-r--r-- | sal/rtl/math.cxx | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx index 95990287bec0..37225f4c7b46 100644 --- a/sal/rtl/math.cxx +++ b/sal/rtl/math.cxx @@ -1143,7 +1143,18 @@ double SAL_CALL rtl_math_erf( double x ) SAL_THROW_EXTERN_C() // Otherwise we may end up in endless recursion through rtl_math_erfc(). if (!::rtl::math::isFinite(x)) + { + // See http://en.cppreference.com/w/cpp/numeric/math/erf + if (::rtl::math::isInf(x)) + { + if (::rtl::math::isSignBitSet(x)) + return -1.0; + else + return 1.0; + } + // It is a NaN. return x; + } bool bNegative = false; if ( x < 0.0 ) @@ -1183,7 +1194,18 @@ double SAL_CALL rtl_math_erfc( double x ) SAL_THROW_EXTERN_C() // Otherwise we may end up in endless recursion through rtl_math_erf(). if (!::rtl::math::isFinite(x)) + { + // See http://en.cppreference.com/w/cpp/numeric/math/erfc + if (::rtl::math::isInf(x)) + { + if (::rtl::math::isSignBitSet(x)) + return 2.0; + else + return 0.0; + } + // It is a NaN. return x; + } bool bNegative = false; if ( x < 0.0 ) |