From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA26123 for caml-red; Fri, 2 Feb 2001 16:19:15 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA20348 for ; Thu, 1 Feb 2001 10:58:25 +0100 (MET) Received: from indyio.rz.uni-sb.de (indyio.rz.uni-sb.de [134.96.7.3]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f119wO522641 for ; Thu, 1 Feb 2001 10:58:24 +0100 (MET) Received: from mars.rz.uni-sb.de (IDENT:tithgyVTtjHYMWGWQTxzCJlmCxFlocun@mars.rz.uni-sb.de [134.96.7.4]) by indyio.rz.uni-sb.de (8.9.3/8.9.3) with ESMTP id KAA15659075; Thu, 1 Feb 2001 10:58:21 +0100 (CET) Received: from cs.uni-sb.de (cs.uni-sb.de [134.96.254.254]) by mars.rz.uni-sb.de (8.8.8/8.8.4/8.8.2) with ESMTP id KAA35527225; Thu, 1 Feb 2001 10:58:20 +0100 (CET) Received: from grizzly.ps.uni-sb.de (grizzly.ps.uni-sb.de [134.96.186.68]) by cs.uni-sb.de (8.11.2/2001012900) with ESMTP id f119wJ921819; Thu, 1 Feb 2001 10:58:19 +0100 (CET) Received: from ps.uni-sb.de (grieg.ps.uni-sb.de [134.96.186.139]) by grizzly.ps.uni-sb.de (8.11.0/8.9.1) with ESMTP id f119wJQ25707; Thu, 1 Feb 2001 10:58:19 +0100 Message-ID: <3A79333A.E447EF42@ps.uni-sb.de> Date: Thu, 01 Feb 2001 10:58:18 +0100 From: Andreas Rossberg Organization: =?iso-8859-1?Q?Universit=E4t?= des Saarlandes X-Mailer: Mozilla 4.76 [en] (X11; U; Linux 2.2.16-22 i686) X-Accept-Language: de, en MIME-Version: 1.0 To: Caml Mailing List CC: Christian Lindig , George Russell Subject: Re: NaN Test in OCaml References: <20010131140503.D2418@lakeland.eecs.harvard.edu> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: weis@pauillac.inria.fr Christian Lindig wrote: > > George Russell has suggested on > comp.lang.ml the following test to find out whether a float is NaN: > > x is not a NaN <=> (x = x) > > Doing this leads to interesting results with OCaml 3.0: > > # let nan x = not (x = x);; > val nan : 'a -> bool = > # nan (1.0 /. 0.0);; > - : bool = false (* correct *) > # nan (0.0 /. 0.0);; > - : bool = false (* should be true *) > > The following definition of nan uses a type annotation and has a > different result: > > # let nan (x:float) = not (x = x);; > val nan : float -> bool = > # nan (0.0 /. 0.0);; > - : bool = true (* correct *) > # nan (1.0 /. 0.0);; > - : bool = false (* correct *) Right, because the first example uses polymorphic equality which is purely structural. The second uses proper floating point comparison. Actually, what we have here, is a subtle kind of overloading. Subtle in particular because it is overlapping. IMHO it would be preferable if floating point comparison used different syntax, probably "=.". In that case the compiler should probably emit a warning whenever he discovered the use of structural equality on floats. -- Andreas Rossberg, rossberg@ps.uni-sb.de :: be declarative. be functional. just be. ::