Thread: RE: "ocaml_beginners"::[] Re: Is floating-point equality accurate
RE: "ocaml_beginners"::[] Re:
Is floating-point equality accurate
United States
2007-10-13 19:27:32
Sorry guys, I was really just ranting. I mean this has been a known problem for how long and pretty much no language addresses it. There was one
language I saw a while ago that let you set the epsilon and did the correct thing with an equals comparison, but I can't remember what it was anymore.
Maybe ADA? That language usually doesn't let sloppiness slide.
Anyway that's pretty much exactly the code I came up with, even picked the
same operator.
_____
From: ocaml_beginners%40yahoogroups.com">ocaml_beginnersyahoogroups.com [mailto: ocaml_beginners%40yahoogroups.com">ocaml_beginnersyahoogroups.com] On Behalf Of jshaw10 Sent: Saturday, October 13, 2007 5:20 PM
To: ocaml_beginners%40yahoogroups.com">ocaml_beginnersyahoogroups.com Subject: "ocaml_beginners"::[] Re: Is floating-point equality accurate
If you use an arbitrary precision number library you won't run into
that problem. For example, ocaml's nums library or the GMP. Anyway...
let ( =. ) x y = abs_float (x -. y) < 0.000001
But yes rounding errors seem to be inherent to any language that uses
a CPU's floating point operations. I'm no CPU expert but I believe the
problem is rounding errors.
[Non-text portions of this message have been removed]