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 D47C77EEBF for ; Thu, 23 Jul 2015 11:31:09 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.15,529,1432591200"; d="scan'208";a="171346633" Received: from pl-59055.rocq.inria.fr (HELO pl-59055.rocqadm.inria.fr) ([128.93.59.55]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/AES128-SHA; 23 Jul 2015 11:31:09 +0200 Received: from shindere by pl-59055.rocqadm.inria.fr with local (Exim 4.84) (envelope-from ) id 1ZICui-0000e8-Dy for caml-list@inria.fr; Thu, 23 Jul 2015 11:35:40 +0200 Date: Thu, 23 Jul 2015 11:35:40 +0200 From: =?utf-8?Q?S=C3=A9bastien?= Hinderer To: caml-list@inria.fr Message-ID: <20150723093540.GC2346@pl-59055.rocqadm.inria.fr> Mail-Followup-To: caml-list@inria.fr References: <20150723083517.GA2029@pl-59055.rocqadm.inria.fr> <55B0AD74.2030302@inria.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <55B0AD74.2030302@inria.fr> Subject: Re: [Caml-list] Comparing floats Xavier Leroy (2015/07/23 11:01 +0200): > On 23/07/2015 10:35, Sébastien Hinderer wrote: > > 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? > > You'll get good performance by type-specializing Pervasives.compare: > > let compare_float (x: float) (y: float) = compare x y > > If you're absolutely sure your floats are not NaN, you can shave a few > CPU cycles: > > let compare_float (x: float) (y: float) = > if x < y then -1 else if x > y then 1 else 0 Thanks a lot Xavier! Sébastien. > > - Xavier Leroy >