From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id EBF5A7EEBF for ; Thu, 23 Jul 2015 13:35:06 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of boris@yakobowski.org) identity=pra; client-ip=46.105.58.60; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="boris@yakobowski.org"; x-sender="boris@yakobowski.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of boris@yakobowski.org designates 46.105.58.60 as permitted sender) identity=mailfrom; client-ip=46.105.58.60; receiver=mail2-smtp-roc.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 (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@3.mo68.mail-out.ovh.net) identity=helo; client-ip=46.105.58.60; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="boris@yakobowski.org"; x-sender="postmaster@3.mo68.mail-out.ovh.net"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0DZAQCM0LBVnDw6aS5bg2lpAQWDHahnjyeCKIYBAgiBOAdMAQEBAQEBEgEBAQEBBg0JCSEuhCQBAQMBEhFLEAsLBAcaHQICIhIBBQEKEgYBEhIQh3cDCggEAQinG4EsPjGLP4ZXigsDhTgBAQEBBgEBAQEBHYtMhQILMYI4gUMFhWAMjnSEdodEgURGg1eRcBIjgRURBoQNbYJLAQEB X-IPAS-Result: A0DZAQCM0LBVnDw6aS5bg2lpAQWDHahnjyeCKIYBAgiBOAdMAQEBAQEBEgEBAQEBBg0JCSEuhCQBAQMBEhFLEAsLBAcaHQICIhIBBQEKEgYBEhIQh3cDCggEAQinG4EsPjGLP4ZXigsDhTgBAQEBBgEBAQEBHYtMhQILMYI4gUMFhWAMjnSEdodEgURGg1eRcBIjgRURBoQNbYJLAQEB X-IronPort-AV: E=Sophos;i="5.15,530,1432591200"; d="scan'208";a="171363811" Received: from 3.mo68.mail-out.ovh.net ([46.105.58.60]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 23 Jul 2015 13:35:06 +0200 Received: from mail626.ha.ovh.net (gw6.ovh.net [213.251.189.206]) by mo68.mail-out.ovh.net (Postfix) with SMTP id 058311000624 for ; Thu, 23 Jul 2015 13:35:05 +0200 (CEST) Received: from localhost (HELO queueout) (127.0.0.1) by localhost with SMTP; 23 Jul 2015 13:35:05 +0200 Received: from mail-la0-f49.google.com (boris@yakobowski.org@209.85.215.49) by ns0.ovh.net with SMTP; 23 Jul 2015 13:35:03 +0200 Received: by lagw2 with SMTP id w2so155576122lag.3; Thu, 23 Jul 2015 04:35:02 -0700 (PDT) X-Received: by 10.152.10.72 with SMTP id g8mr7251542lab.97.1437651302824; Thu, 23 Jul 2015 04:35:02 -0700 (PDT) MIME-Version: 1.0 Reply-To: boris@yakobowski.org Received: by 10.112.20.67 with HTTP; Thu, 23 Jul 2015 04:34:43 -0700 (PDT) In-Reply-To: <20150723083517.GA2029@pl-59055.rocqadm.inria.fr> References: <20150723083517.GA2029@pl-59055.rocqadm.inria.fr> From: Boris Yakobowski Date: Thu, 23 Jul 2015 13:34:43 +0200 Message-ID: To: =?UTF-8?Q?S=C3=A9bastien_Hinderer?= , The Caml Mailing List Content-Type: multipart/alternative; boundary=001a1132efa23741fd051b894756 X-Ovh-Tracer-Id: 15089029076873623584 X-Ovh-Remote: 209.85.215.49 (mail-la0-f49.google.com) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-OVH-SPAMSTATE: OK X-OVH-SPAMSCORE: -51 X-OVH-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeekvddrjeeiucetufdoteggucfrrhhofhhilhgvmecuqfggjfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnegoufhushhpvggtthffohhmrghinhculdegledm X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -51 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeekvddrjeeiucetufdoteggucfrrhhofhhilhgvmecuqfggjfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnegoufhushhpvggtthffohhmrghinhculdegledm X-Validation-by: boris@yakobowski.org Subject: Re: [Caml-list] Comparing floats --001a1132efa23741fd051b894756 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 re= turn false (as well as NaN !=3D NaN), breaking all algebraic laws known to manki= nd :-). OCaml's operators '=3D' and '!=3D' follow this convention, but 'compa= re 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 > --=20 Boris --001a1132efa23741fd051b894756 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi S=C3=A9bastien,

I feel obligated= to point out that the _semantics_ of floating-point comparison is a bit tr= icky. IEEE 754 mandates that NaN =3D=3D NaN should return false (as well as= NaN !=3D NaN), breaking all algebraic laws known to mankind :-). OCaml'= ;s operators '=3D' and '!=3D' follow this convention, but= =C2=A0 'compare nan nan' returns 0, which is usually the desired be= havior. 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.=C2=A0 Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocam= l_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



--
Boris
--001a1132efa23741fd051b894756--