caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* NaN Test in OCaml
@ 2001-01-31 19:05 Christian Lindig
  2001-02-01  9:19 ` David Mentre
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Christian Lindig @ 2001-01-31 19:05 UTC (permalink / raw)
  To: Caml Mailing List; +Cc: George Russell, Archisman Rudra


George Russell <ger@informatik.uni-bremen.de> 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 = <fun>
    # 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 = <fun>
    # 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/



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-02-02 15:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-01-31 19:05 NaN Test in OCaml Christian Lindig
2001-02-01  9:19 ` David Mentre
2001-02-01  9:58 ` Andreas Rossberg
2001-02-01 14:41 ` Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).