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 4451A7EF37 for ; Thu, 23 Jul 2015 11:02:01 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.15,529,1432591200"; d="scan'208";a="171340636" Received: from estephe.inria.fr (HELO [128.93.11.95]) ([128.93.11.95]) by mail2-relais-roc.national.inria.fr with ESMTP; 23 Jul 2015 11:01:40 +0200 Message-ID: <55B0AD74.2030302@inria.fr> Date: Thu, 23 Jul 2015 11:01:40 +0200 From: Xavier Leroy User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: caml-list@inria.fr References: <20150723083517.GA2029@pl-59055.rocqadm.inria.fr> In-Reply-To: <20150723083517.GA2029@pl-59055.rocqadm.inria.fr> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [Caml-list] Comparing floats 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 - Xavier Leroy