Here's where things

On 5/28/13 11:18 AM, Peter Li wrote:
> In src/test/agrad/rev/inv_sqrt_test.cpp:
>
>> @@ -0,0 +1,15 @@
>> +#include <stan/agrad/rev/inv_sqrt.hpp>
>> +#include <test/agrad/util.hpp>
>> +#include <gtest/gtest.h>
>> +
>> +TEST(AgradRev,inv_sqrt) {
>
> When the input is negativ for sqrt, nan is returned for some reason instead of a domain error.

Check out:

http://www.cplusplus.com/reference/cmath/sqrt/

Everything's all version tabbed now, so look under
the behavior for C++98, which says:

   If a domain error occurs, the global variable errno is set to EDOM.

What it doesn't say is that nan will be returned --- at least
on my machine including <cmath> and using std::sqrt().

In C++11 it'll be configurable.  The point is that we want
to have the same behavior as the std library wherever possible
because it's what users of the code will expect.

Pushed through to the Stan modeling language, what'll happen is
that we'll get a NaN return.  If that gets used in a call to
a function like a distribution or matrix algebra function that
raises exceptions, you'll get an exception.  Otherwise what will
happen is that it'll go all the way through and the proposal
that caused the NaN will be rejected.  Now in NUTS, this may just
mean a final branch is eliminated and you won't actually reject
the whole path.

- Bob