Re: [Python-ideas] [Python-Dev] Why is nan != nan?

[Moving back to python-ideas] On Sat, Mar 27, 2010 at 12:05 AM, Steven D'Aprano <steve@pearwood.info> wrote:
I'd prefer the opposite: that arithmetic operations and math functions raise rather than produce nans; this seems friendlier for users who don't want to know or care about infinities and nans. But I agree that there are uses for nonstop mode. <python-ideas-territory> How about default behaviour like the above, with a "from __options__ import non-stop-arithmetic" for people who want 1./0. to give infinity and sqrt(-1) to give nan? In order words, default behaviour roughly corresponds to the IEEE 754 spec with the 'invalid operation', 'overflow' and 'divide-by-zero' operations trapped (exactly as the default context in the decimal module does currently), and the non-stop behaviour corresponds to IEEE 754 with none of those operations trapped and returning default values. A more elaborate proposal would allow individual control over the three signals above. (Full control over the 'underflow' and 'inexact' signals isn't really feasible given C's poor support for these things.) </python-ideas-territory>. Mark

On Sat, Mar 27, 2010 at 12:39 PM, Mark Dickinson <dickinsm@gmail.com> wrote:
Hmm. That would be a horrible way to control the option. But the idea's the same: give some way to enable non-stop arithmetic. Some sort of context manager might make sense: with non_stop_arithmetic: result = calculation() if isnan(result): ... Mark

On Sat, Mar 27, 2010 at 12:39 PM, Mark Dickinson <dickinsm@gmail.com> wrote:
Hmm. That would be a horrible way to control the option. But the idea's the same: give some way to enable non-stop arithmetic. Some sort of context manager might make sense: with non_stop_arithmetic: result = calculation() if isnan(result): ... Mark
participants (1)
-
Mark Dickinson