Opened 10 years ago

Closed 10 years ago

#587 closed task (wontfix)

CR: expt should signal error on domain error

Reported by: felix winkelmann Owned by:
Priority: minor Milestone:
Component: core libraries Version: 4.7.x
Keywords: expt Cc:
Estimated difficulty:

Description (last modified by felix winkelmann)

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.

Change History (5)

comment:1 Changed 10 years ago by felix winkelmann

Description: modified (diff)

comment:4 in reply to:  2 Changed 10 years ago by Jim Ursetto

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.

comment:5 Changed 10 years ago by felix winkelmann

Resolution: wontfix
Status: newclosed

Closed, since this CR is rejected.

Note: See TracTickets for help on using tickets.