Skip to content

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

Closed

Description

@WarrenWeckesser

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?

Activity

  1. 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?[/+] on Apr 15, 2022
  2. mborland commented on Apr 15, 2022

    @mborland
    Member

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

  3. WarrenWeckesser commented on Apr 15, 2022

    @WarrenWeckesser
    ContributorAuthor

    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"?

  4. NAThompson commented on Apr 16, 2022

    @NAThompson
    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.

  5. jzmaddock commented on Apr 16, 2022

    @jzmaddock
    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.

  6. added a commit that references this issue on Nov 25, 2022
  7. added a commit that references this issue on Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions