Summary

CR: expt should signal error on domain error

Metadata

Description

`expt` returns +NaN when called with a negative first argument and a non-integer second argument. With a full numeric tower this would be a complex number, but those are of course not supported in the core system.

I suggest signaling an error in this case. This might break existing code that relies on +NaN being returned.

Changes and comments

[2011-06-06 15:37:28 UTC] felix changed description

[2011-06-14 09:32:46 UTC] felix wrote:

`expt` signal an error when a domain error occurs?; Yes; No)]

[2011-06-14 17:03:54 UTC] johnwcowan wrote:

Replying to felix: > `expt` signal an error when a domain error occurs?; Yes; No)]

[2011-06-21 20:09:51 UTC] zbigniew wrote:

It is reasonable to throw an exception on domain error in pow(). To me, this is always going to be a programming mistake by the user, who expects a complex number. Couple notes: errno may, but is not guaranteed to, be set after a domain error; you are supposed to test the exception flags (see fenv(3)) afterward. For example, it doesn't seem to be set on OS X. A better way in this case is probably to detect the domain error by testing the arguments prior to the call. Testing for NaN afterward would probably work as well, since pow() only returns NaN in exactly this case, but feels less right because NaN is not really an error code.

It's also reasonable to have fpexpt just return the raw NaN, in case you want the low-level C behavior. Ideally, we'd have some way for the user to obtain the fp exception flags afterward. But that's probably better saved for when someone is complaining they need it.

[2011-07-04 10:42:46 UTC] felix changed status from new to closed

[2011-07-04 10:42:46 UTC] felix set resolution to wontfix

[2011-07-04 10:42:46 UTC] felix wrote:

Closed, since this CR is rejected.