From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 075D57EEBF for ; Thu, 23 Jul 2015 18:35:30 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of boris@yakobowski.org) identity=pra; client-ip=178.33.251.173; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="boris@yakobowski.org"; x-sender="boris@yakobowski.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of boris@yakobowski.org designates 178.33.251.173 as permitted sender) identity=mailfrom; client-ip=178.33.251.173; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="boris@yakobowski.org"; x-sender="boris@yakobowski.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@1.mo69.mail-out.ovh.net) identity=helo; client-ip=178.33.251.173; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="boris@yakobowski.org"; x-sender="postmaster@1.mo69.mail-out.ovh.net"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0D8AgBcF7FVnK37IbJcGYNQaQEFgx2odo8ngiiGAQIMgTsHTAEBAQEBARIBAQEBAQYNCQkhLoQjAQEBAQIBEhEERwsQCwsNDR0CAiISAQUBChIGEwgKEId3AwoIBAEIp1OBLD4xiz+GV4oPA4U4AQEBAQEBAQECAQEBAQEBAQEBGYtMhQIEBzGCOIFDBYVgDI50hHaHRIFERoNXkXASI4EVEQaEDm2CSwEBAQ X-IPAS-Result: A0D8AgBcF7FVnK37IbJcGYNQaQEFgx2odo8ngiiGAQIMgTsHTAEBAQEBARIBAQEBAQYNCQkhLoQjAQEBAQIBEhEERwsQCwsNDR0CAiISAQUBChIGEwgKEId3AwoIBAEIp1OBLD4xiz+GV4oPA4U4AQEBAQEBAQECAQEBAQEBAQEBGYtMhQIEBzGCOIFDBYVgDI50hHaHRIFERoNXkXASI4EVEQaEDm2CSwEBAQ X-IronPort-AV: E=Sophos;i="5.15,531,1432591200"; d="scan'208";a="141008193" Received: from 1.mo69.mail-out.ovh.net ([178.33.251.173]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 23 Jul 2015 18:35:29 +0200 Received: from mail635.ha.ovh.net (gw6.ovh.net [213.251.189.206]) by mo69.mail-out.ovh.net (Postfix) with SMTP id 53740FF86E5 for ; Thu, 23 Jul 2015 18:35:28 +0200 (CEST) Received: from localhost (HELO queueout) (127.0.0.1) by localhost with SMTP; 23 Jul 2015 18:35:27 +0200 Received: from mail-lb0-f172.google.com (boris@yakobowski.org@209.85.217.172) by ns0.ovh.net with SMTP; 23 Jul 2015 18:35:21 +0200 Received: by lblf12 with SMTP id f12so161335662lbl.2; Thu, 23 Jul 2015 09:35:13 -0700 (PDT) X-Received: by 10.112.155.164 with SMTP id vx4mr8925417lbb.38.1437669313658; Thu, 23 Jul 2015 09:35:13 -0700 (PDT) MIME-Version: 1.0 Reply-To: boris@yakobowski.org Received: by 10.112.20.67 with HTTP; Thu, 23 Jul 2015 09:34:54 -0700 (PDT) In-Reply-To: <55B104C9.1000207@inria.fr> References: <20150723083517.GA2029@pl-59055.rocqadm.inria.fr> <55B104C9.1000207@inria.fr> From: Boris Yakobowski Date: Thu, 23 Jul 2015 18:34:54 +0200 Message-ID: To: Jacques-Henri Jourdan Cc: The Caml Mailing List Content-Type: multipart/alternative; boundary=089e01228a92bec770051b8d785b X-Ovh-Tracer-Id: 1713901135074474016 X-Ovh-Remote: 209.85.217.172 (mail-lb0-f172.google.com) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-OVH-SPAMSTATE: OK X-OVH-SPAMSCORE: -51 X-OVH-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeekvddrjeejucetufdoteggucfrrhhofhhilhgvmecuqfggjfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnegoufhushhpvggtthffohhmrghinhculdegledm X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -51 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeekvddrjeejucetufdoteggucfrrhhofhhilhgvmecuqfggjfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnegoufhushhpvggtthffohhmrghinhculdegledm X-Validation-by: boris@yakobowski.org Subject: Re: [Caml-list] Comparing floats --089e01228a92bec770051b8d785b Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Indeed, thanks for the clarification... I got confused when negating OCaml's '=3D' operator (a dangerous side-effect of writing too much C!), hence the erroneous '!=3D' instead of <>. Regardin= g, 'nan <> nan', I had convinced myself that all comparisons with NaN returned false. I wonder why <>/!=3D got a special treatment since e.g. 'nan < 1.' a= nd '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 =C3=A9crit : > > Hi S=C3=A9bastien, > > I feel obligated to point out that the _semantics_ of floating-point > comparison is a bit tricky. IEEE 754 mandates that NaN =3D=3D NaN should = return > false (as well as NaN !=3D NaN), breaking all algebraic laws known to man= kind > :-). > > > Beaware: > > Nan <> Nan -> true > Nan =3D Nan -> false > Nan !=3D Nan and Nan =3D=3D Nan : depends on the memory layout. > > OCaml's operators '=3D' and '!=3D' 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=C3=A9bastien Hinderer < > 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=C3=A9bastien. >> >> -- >> 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 > > > --=20 Boris --089e01228a92bec770051b8d785b Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Indeed, thanks for the clarification...

<= /div>I got confused when negating OCaml's '=3D' operator (a dan= gerous side-effect of writing too much C!), hence the erroneous '!=3D&#= 39; instead of <>. Regarding, 'nan <> nan', I had convi= nced myself that all comparisons with NaN returned false. I wonder why <= >/!=3D 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:
=20=20 =20=20=20=20 =20=20


Le 23/07/2015 13:34, Boris Yakobowski a =C3=A9crit=C2=A0:
Hi S=C3=A9bastien,

I feel obligated to point out that the _semantics_ of floating-point comparison is a bit tricky. IEEE 754 mandates that NaN =3D=3D NaN should return false (as well as NaN !=3D NaN), breaking all algebraic laws known to mankind :-).

Beaware:

Nan <> Nan=C2=A0 -> true
Nan =3D Nan -> false
Nan !=3D Nan and Nan =3D=3D Nan : depends on the memory layout.

OCaml's operators '=3D' and '!=3D' follow= this convention, but=C2=A0 'compare nan nan' returns 0, which is usually t= he desired behavior. However, 'compare 0. (-0.)' also returns 0, whi= le you might want to distinguish those two values.

HTH,

On Thu, Jul 23, 2015 at 10:35 AM, S=C3=A9bastien Hinderer <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=C3=A9bastien.

--
Caml-list mailing list.=C2=A0 Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-lis= t
Beginner's list: http://groups.yaho= o.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



--
Boris




--
Boris
--089e01228a92bec770051b8d785b--