From: "Mr. Herr" <misterherr@freenet.de>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Comparing floats
Date: Thu, 23 Jul 2015 11:05:45 +0200 [thread overview]
Message-ID: <55B0AE69.1080202@freenet.de> (raw)
In-Reply-To: <55B0A9D5.4000008@inria.fr>
On 23.07.2015 10:46, Francois Berenger wrote:
> On 07/23/2015 10:35 AM, Sébastien 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?
>
> It exists in Batteries for sure and in Core I believe.
>
> Also, maybe you can define:
>
> let cmp_f (x: float) (y: float) = x -. y
hmm, this will return float instead of int.
My test says that compare is compiled directly to the adequate internal function,
and if this even in byte code:
str@s131-intel:~/Projekte/Ocaml/ml> cat test_comparefl1.ml && echo -e
"------------\n" && ocamlc -dinstr test_comparefl1.ml
(*
Frage auf mailing list: wie am besten floats vergleichen?
*)
print_endline ("Pervasives.compare 2 floats gives me " ^ (string_of_int (compare 2.0
3.99)))
------------
const 3.99
push
const 2.0
ccall caml_float_compare, 2
push
getglobal Pervasives!
getfield 19
apply 1
push
const "Pervasives.compare 2 floats gives me "
push
getglobal Pervasives!
getfield 15
apply 2
push
getglobal Pervasives!
getfield 30
apply 1
makeblock 0, 0
setglobal Test_comparefl1!
------------------------------
/Str.
next prev parent reply other threads:[~2015-07-23 9:08 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-23 8:35 Sébastien Hinderer
2015-07-23 8:46 ` Francois Berenger
2015-07-23 9:05 ` Mr. Herr [this message]
2015-07-23 9:01 ` Xavier Leroy
2015-07-23 9:35 ` Sébastien Hinderer
2015-07-23 9:54 ` Mr. Herr
2015-08-04 9:06 ` Goswin von Brederlow
2015-07-23 11:34 ` Boris Yakobowski
2015-07-23 15:14 ` Jacques-Henri Jourdan
2015-07-23 16:34 ` Boris Yakobowski
2015-07-23 17:00 ` Xavier Leroy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55B0AE69.1080202@freenet.de \
--to=misterherr@freenet.de \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox