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 IAA06454 for caml-red; Thu, 1 Feb 2001 08:41:04 +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 UAA04788 for ; Wed, 31 Jan 2001 20:05:10 +0100 (MET) Received: from lakeland.eecs.harvard.edu (lakeland.eecs.harvard.edu [140.247.62.173]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f0VJ59T08206 for ; Wed, 31 Jan 2001 20:05:09 +0100 (MET) Received: by lakeland.eecs.harvard.edu (Postfix, from userid 32148) id 6ACDB1FD1E; Wed, 31 Jan 2001 14:05:03 -0500 (EST) Date: Wed, 31 Jan 2001 14:05:03 -0500 From: Christian Lindig To: Caml Mailing List Cc: George Russell , Archisman Rudra Subject: NaN Test in OCaml Message-ID: <20010131140503.D2418@lakeland.eecs.harvard.edu> Mail-Followup-To: Christian Lindig , Caml Mailing List , George Russell , Archisman Rudra Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i Sender: weis@pauillac.inria.fr 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 *) Is this a bug or a feature? Anyway, I guess this again shows the subtleties of equality. -- Christian -- Christian Lindig Harvard University - DEAS lindig@eecs.harvard.edu 33 Oxford St, MD 242, Cambridge MA 02138 phone: +1 (617) 496-7157 http://www.eecs.harvard.edu/~lindig/