lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] using log1p(-1)


From: Vadim Zeitlin
Subject: [lmi] using log1p(-1)
Date: Wed, 19 May 2010 17:13:17 +0200

 Hello,

 math_functors_test.cpp currently calls i_upper_12_over_12_from_i(-1) which
results in a call to log1p(-1). When using the Boost version of the
function, passing -1 to it results in an std::overflow_error exception
being thrown resulting in a test failure. This behaviour seems to be
reasonable because POSIX says that "If x is -1, a pole error shall occur"
(see [1]) and while C99 only says "A range error _may_ occur if the
argument equals -1" (emphasis mine, see 7.12.6.9/2 of ISO/IEC 9899:1999(E))
most if not all of the existing C99 implementations also conform to POSIX
and so do treat this as error. So, again, throwing an exception looks like
the right thing to do. And it seems even more right for the next test after
one which calls log1p(-1.01). Here C99 and POSIX agree that this shall
result in a domain error.

 Boost allows to configure what happens in this case (in several different
ways, see [2]) and so in principle we could avoid throwing this exception
but would this be the right thing to do? IMHO if we really need to allow
passing -1 (or inferior) values to i_upper_12_over_12_from_i() it would be
better to handle these cases directly in it instead of changing the
behaviour of the global log1p() function. Especially because doing this
would likely be non-trivial.

 What do you think?
VZ

[1] http://www.opengroup.org/onlinepubs/009695399/functions/log1p.html
[2] 
http://www.boost.org/doc/libs/1_43_0/libs/math/doc/sf_and_dist/html/math_toolkit/policy/pol_tutorial/policy_usage.html

reply via email to

[Prev in Thread] Current Thread [Next in Thread]