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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id B9C2F7EEBF for ; Thu, 23 Jul 2015 17:14:25 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.15,531,1432591200"; d="asc'?scan'208,217";a="171394235" Received: from wifi-auth-191188.inria.fr (HELO nounours.mketjh.fr) ([128.93.191.188]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 23 Jul 2015 17:14:25 +0200 To: caml-list@inria.fr References: <20150723083517.GA2029@pl-59055.rocqadm.inria.fr> From: Jacques-Henri Jourdan Message-ID: <55B104C9.1000207@inria.fr> Date: Thu, 23 Jul 2015 17:14:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="dSFBCjLfEmV7JesPgJAw75kXFSwQXglca" Subject: Re: [Caml-list] Comparing floats This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --dSFBCjLfEmV7JesPgJAw75kXFSwQXglca Content-Type: multipart/alternative; boundary="------------050406050105000707070709" This is a multi-part message in MIME format. --------------050406050105000707070709 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 mankind :-). 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 > > 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 --------------050406050105000707070709 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

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 the desir= ed 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.=C2=A0 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

--------------050406050105000707070709-- --dSFBCjLfEmV7JesPgJAw75kXFSwQXglca Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJVsQTRAAoJEGHoGlEY1GjFTdAH+wW6clvgUMeOwycFvU2wBdvB e56Frkglq4qYVeGUoaxfKxlQTvSB4vbqyQ3OFzzqAcJ6JvXC8vTgW4YGMYV2kQqj rQEkKI2maJfONYUA0uh9pGXgiTo2U6pG8vS0uyMZoOQRJj+KJXnIcVVjzVDW5tzb JxuSPUk6eByoPEYkvYAsFLNGQkWhwG1zLq4ZJ30h91E0AftprLCacLoPM4Ob7mu+ ykC8+Q+K2MPodCS8AddlAu2aK2YsAe+Wn7MOfkZVOq38FQO1MoibmMoJfqxu31RO 3QsW/ve5MNhIvxDgo5nl1k4FtP8c9rQtRlTR0vI8DrB0/1mr6GtsqK42mojKIc4= =2hvs -----END PGP SIGNATURE----- --dSFBCjLfEmV7JesPgJAw75kXFSwQXglca--