Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Large projects in OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Damien Doligez <damien.doligez@i...>
Subject: Re: [Caml-list] A problem with nan.

On May 20, 2004, at 22:42, Jon Harrop wrote:

> # 2.=nan;;
> - : bool = false
> # [2.]=[nan];;
> - : bool = true
>
> when "=" compares structures recursively so you'd expect it to give 
> the same answer in both cases?

We have contradictory requirements here:
1. We want "=" on floats to be IEEE754 equality.
2. We want "=" on structures to be compatible with "=" on their 
elements.
3. We want "=" on structures to be based on "compare".
4. We want "compare" to be a total ordering.

Since IEEE754 equality is not a reflexive relation, there is no way
to get all four properties.

In the current version of O'Caml, we have 1, 3, and 4.  In the next
version we will have 1, 2, and 4: "compare" and "=" will have slightly
different behaviour, but "=" will be compatible with itself.  This
will make "compare" a valid comparison function for List.sort, for
all types of data (currently it doesn't work for floats).

But "compare nan nan" will return 0, while "nan = nan" will
return false (as mandated by IEEE754).

-- Damien

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners