Opened 13 years ago
Closed 13 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 )
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 13 years ago by
Description: | modified (diff) |
---|
comment:2 follow-ups: 3 4 Changed 13 years ago by
comment:3 Changed 13 years ago by
comment:4 Changed 13 years ago by
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 13 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Closed, since this CR is rejected.
Poll(Should `expt` signal an error when a domain error occurs?; Yes; No)?