From: Christian Lindig <lindig@eecs.harvard.edu>
To: Caml Mailing List <caml-list@inria.fr>
Cc: George Russell <ger@informatik.uni-bremen.de>,
Archisman Rudra <archi@mosaic.mrl.nyu.edu>
Subject: NaN Test in OCaml
Date: Wed, 31 Jan 2001 14:05:03 -0500 [thread overview]
Message-ID: <20010131140503.D2418@lakeland.eecs.harvard.edu> (raw)
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/
next reply other threads:[~2001-02-01 7:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-01-31 19:05 Christian Lindig [this message]
2001-02-01 9:19 ` David Mentre
2001-02-01 9:58 ` Andreas Rossberg
2001-02-01 14:41 ` Xavier Leroy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20010131140503.D2418@lakeland.eecs.harvard.edu \
--to=lindig@eecs.harvard.edu \
--cc=archi@mosaic.mrl.nyu.edu \
--cc=caml-list@inria.fr \
--cc=ger@informatik.uni-bremen.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox