From: Boris Yakobowski <boris@yakobowski.org>
To: Jacques-Henri Jourdan <jacques-henri.jourdan@inria.fr>
Cc: The Caml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Comparing floats
Date: Thu, 23 Jul 2015 18:34:54 +0200 [thread overview]
Message-ID: <CABbVA-DenGsjVLhgX3TRugd873FhFy7PsePLO16hUVokb6ov8g@mail.gmail.com> (raw)
In-Reply-To: <55B104C9.1000207@inria.fr>
[-- Attachment #1: Type: text/plain, Size: 1924 bytes --]
Indeed, thanks for the clarification...
I got confused when negating OCaml's '=' operator (a dangerous side-effect
of writing too much C!), hence the erroneous '!=' instead of <>. Regarding,
'nan <> nan', I had convinced myself that all comparisons with NaN returned
false. I wonder why <>/!= got a special treatment since e.g. 'nan < 1.' and
'1. < nan' both return false.
On Thu, Jul 23, 2015 at 5:14 PM, Jacques-Henri Jourdan <
jacques-henri.jourdan@inria.fr> wrote:
>
>
> Le 23/07/2015 13:34, Boris Yakobowski a écrit :
>
> Hi Sébastien,
>
> I feel obligated to point out that the _semantics_ of floating-point
> comparison is a bit tricky. IEEE 754 mandates that NaN == NaN should return
> false (as well as NaN != NaN), breaking all algebraic laws known to mankind
> :-).
>
>
> Beaware:
>
> Nan <> Nan -> true
> Nan = Nan -> false
> Nan != Nan and Nan == Nan : depends on the memory layout.
>
> OCaml's operators '=' and '!=' follow this convention, but 'compare
> nan nan' returns 0, which is usually the desired behavior. However,
> 'compare 0. (-0.)' also returns 0, while you might want to distinguish
> those two values.
>
> HTH,
>
> On Thu, Jul 23, 2015 at 10:35 AM, Sébastien Hinderer <
> <Sebastien.Hinderer@inria.fr>Sebastien.Hinderer@inria.fr> wrote:
>
>> Dear all,
>>
>> What's the most efficient way to compare floats, please?
>> Is it the polymorphic compare function, or is there a more specialized
>> version of it?
>>
>> I saw Float.compare mentionned on the web but that does not seem to exist
>> any longer?
>>
>> Thanks,
>>
>> Sébastien.
>>
>> --
>> Caml-list mailing list. Subscription management and archives:
>> https://sympa.inria.fr/sympa/arc/caml-list
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>>
>
>
>
> --
> Boris
>
>
>
--
Boris
[-- Attachment #2: Type: text/html, Size: 4050 bytes --]
next prev parent reply other threads:[~2015-07-23 16:35 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-23 8:35 Sébastien Hinderer
2015-07-23 8:46 ` Francois Berenger
2015-07-23 9:05 ` Mr. Herr
2015-07-23 9:01 ` Xavier Leroy
2015-07-23 9:35 ` Sébastien Hinderer
2015-07-23 9:54 ` Mr. Herr
2015-08-04 9:06 ` Goswin von Brederlow
2015-07-23 11:34 ` Boris Yakobowski
2015-07-23 15:14 ` Jacques-Henri Jourdan
2015-07-23 16:34 ` Boris Yakobowski [this message]
2015-07-23 17:00 ` 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=CABbVA-DenGsjVLhgX3TRugd873FhFy7PsePLO16hUVokb6ov8g@mail.gmail.com \
--to=boris@yakobowski.org \
--cc=caml-list@inria.fr \
--cc=jacques-henri.jourdan@inria.fr \
/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