Hashing. You want isequal(NaN,NaN) so that the NaN hash bucket doesn't end
up being one big endless collision without equality. Also since you have
isequal(x, convert(T, x)) for most other numeric x, it only seems sane to
have the same thing hold for NaNs of different types.

On Fri, Dec 18, 2015 at 9:42 AM, Erik Schnetter <[email protected]> wrote:

> isequal converts ("promotes") both arguments to a common type, if they
> have different types. Thus NaN16 and NaN32 are converted to NaN (i.e.
> NaN64), hence isequal returns true. See `isequal(5, 5.0)`.
>
> The two equality notions in Julia do nest: `isequal` and `is`, where the
> latter is more strict than the former. The operator `==` is basically
> identical to `isequal`, except it also handles IEEE semantics, which
> technically isn't a valid notion of equality, and thus it cannot nest.
>
> -erik
>
>
> On Fri, Dec 18, 2015 at 8:09 AM, Tamas Papp <[email protected]> wrote:
>
>> For example,
>>
>> julia> isequal(NaN,NaN16)
>> true
>>
>> julia> isequal(NaN,NaN32)
>> true
>>
>> This is of course documented in the manual, what I would like to
>> understand is the motivation for this design decision. Some languages
>> have a progression of equality predicates --- eg Common Lisp has EQ,
>> EQL, EQUAL, and EQUALP, each more permissive than the next one. But ==
>> and isequal do not nest, since NaN's are of course not == to anything
>> under IEEE, even themselves.
>>
>> Before reading about this in the manual, I thought of isequal as object
>> identity ("A and B are equal when they cannot be distinguished"), but
>> apparently that's the wrong concept.
>>
>> Just curious -- there must be a good reason and I would like to know it.
>>
>> Best,
>>
>> Tamas
>>
>
>
>
> --
> Erik Schnetter <[email protected]>
> http://www.perimeterinstitute.ca/personal/eschnetter/
>

Reply via email to