why () is () and [] is [] work in other way?

John Nagle nagle at animats.com
Sun Apr 29 17:45:35 EDT 2012


On 4/28/2012 4:47 AM, Kiuhnm wrote:
> On 4/27/2012 17:39, Adam Skutt wrote:
>> On Apr 27, 8:07 am, Kiuhnm<kiuhnm03.4t.yahoo.it> wrote:
>>> Useful... maybe, conceptually sound... no.
>>> Conceptually, NaN is the class of all elements which are not numbers,
>>> therefore NaN = NaN.
>>
>> NaN isn't really the class of all elements which aren't numbers. NaN
>> is the result of a few specific IEEE 754 operations that cannot be
>> computed, like 0/0, and for which there's no other reasonable
>> substitute (e.g., infinity) for practical applications .
>>
>> In the real world, if we were doing the math with pen and paper, we'd
>> stop as soon as we hit such an error. Equality is simply not defined
>> for the operations that can produce NaN, because we don't know to
>> perform those computations. So no, it doesn't conceptually follow
>> that NaN = NaN, what conceptually follows is the operation is
>> undefined because NaN causes a halt.
>
> Mathematics is more than arithmetics with real numbers. We can use FP
> too (we actually do that!). We can say that NaN = NaN but that's just an
> exception we're willing to make. We shouldn't say that the equivalence
> relation rules shouldn't be followed just because *sometimes* we break
> them.
>
>> This is what programming languages ought to do if NaN is compared to
>> anything other than a (floating-point) number: disallow the operation
>> in the first place or toss an exception.

    If you do a signaling floating point comparison on IEEE floating
point numbers, you do get an exception.  On some FPUs, though,
signaling operations are slower.  On superscalar CPUs, exact
floating point exceptions are tough to implement.  They are
done right on x86 machines, mostly for backwards compatibility.
This requires an elaborate "retirement unit" to unwind the
state of the CPU after a floating point exception.  DEC Alphas
didn't have that; SPARC and MIPS machines varied by model.
ARM machines in their better modes do have that.
Most game console FPUs do not have a full IEEE implementation.

    Proper language support for floating point exceptions varies
with the platform.  Microsoft C++ on Windows does support
getting it right.  (I had to deal with this once in a physics
engine, where an overflow or a NaN merely indicated that a
shorter time step was required.)  But even there, it's
an OS exception, like a signal, not a language-level
exception.  Other than Ada, which requires it, few
languages handle such exceptions as language level
exceptions.


				John Nagle



More information about the Python-list mailing list