Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

powm1(0.0, -2.0) doesn't throw an exception. Should it? #781

Closed
WarrenWeckesser opened this issue Apr 15, 2022 · 4 comments
Closed

powm1(0.0, -2.0) doesn't throw an exception. Should it? #781

WarrenWeckesser opened this issue Apr 15, 2022 · 4 comments

Comments

@WarrenWeckesser
Copy link
Contributor

Here's a test program that I compiled with the develop branch:

#include <iostream>
#include <boost/math/special_functions/powm1.hpp>

using namespace std;
using boost::math::powm1;


int main()
{
    try {
        double p = powm1(0.0, -2.0);
        cout << "p = " << p << endl;
    } catch (const exception& e) {
        cerr << "*** Caught: " << e.what() << endl;
        cerr << "*** Type: " << typeid(e).name() << endl;
    }
}

I expected powm1(0.0, -2.0) to throw an exception, but it does not; the program outputs p = inf. Should it throw an exception?

@WarrenWeckesser WarrenWeckesser changed the title powm1(0.0, -2.0) doesn't raise an exception. Should it? powm1(0.0, -2.0) doesn't throw an exception. Should it? Apr 15, 2022
@mborland
Copy link
Member

I think the behavior is correct. If you compare to the error handling of std::pow returning infinity is expected.

@WarrenWeckesser
Copy link
Contributor Author

OK, I'm still figuring out the conventions followed by the functions in Boost/Math/Special Functions. Based on the policy docs, I thought the default behavior would be to throw a std::domain_error.

I see that log1p(-1.0) and atanh(±1.0) also do not throw, so I guess this is not unusual.

On the other hand, erf_inv(±1.0) and cyl_neumann(0, 0.0) each throw an overflow error. (Shouldn't those exceptions be domain errors, as the closest thing to a pole error?) So in general, is the rule "It depends, you just have to try it"?

@NAThompson
Copy link
Collaborator

@WarrenWeckesser : Lol, I like that rule. Personally I find it preferable to use all the semantic space that IEEE floats gives us and like the inf, but I think that you could definitely argue for a domain_error.

@jzmaddock
Copy link
Collaborator

It's a bug, but I'm not sure in which direction: wolframalpha reports 0^-2 as complex-infinity which would be a domain error, but if we treat it as 1/0^2 then it should be a straight overflow error.

AZero13 pushed a commit to AZero13/math that referenced this issue Jan 19, 2023
Makes 0^-n an overflow error (which matches std::pow which returns +INF rather than a NaN).
Fixes boostorg#781.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants