From: Brian Hurt <bhurt@spnz.org>
To: Andrej.Bauer@andrej.com
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Multiplication of matrix in C and OCaml
Date: Fri, 9 Feb 2007 20:10:26 -0500 (EST) [thread overview]
Message-ID: <Pine.LNX.4.64.0702092000180.19734@localhost> (raw)
In-Reply-To: <45CCEDD8.3080907@fmf.uni-lj.si>
On Fri, 9 Feb 2007, Andrej Bauer wrote:
> I hate to add to this long discussion, but since when is floating point
> multiplication associative?
>
> # 1.3 *. (0.7 *. 2.1) = (1.3 *. 0.7) *. 2.1 ;;
> - : bool = false
Round off error. You can't represent numbers like 7/10 or 13/10 in binary
precisely in a finite number of digits, any more than you can represent
the numbers 1/3 or 4/7 precisely in base-10 in a finite number of digits.
This is a fundamental problem with floating point numbers, and shows up in
every language that has them. But this means reordering the calculations
will result in slightly different answers.
And no, most of the "obvious" solutions don't work. Using rational
arithmetic doesn't help if I ask you to calculate the euclidean length of
the vector (1, 1) for example (hint: sqrt (1.*.1. +. 1.*.1.)). Interval
arithmetic fails miserably on simple algorithms like Newton's method. And
so on.
On the other hand, the precision given by double precision floating point
numbers is generally more than enough- they're precise enough to hold the
distance from here to the moon in microns, for example.
My advice: if you're doing much of anything with floating point numbers,
get a book on numerical analysis and follow the algorithms and
recommendations it gives you (any book except "Numerical Recipies", which
suck). And don't use floating point for money.
Brian
next prev parent reply other threads:[~2007-02-10 0:58 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-07 23:42 Frédéric Gava
2007-02-08 2:14 ` [Caml-list] " Jacques Garrigue
2007-02-08 9:27 ` Frédéric Gava
2007-02-08 9:38 ` Frédéric Gava
2007-02-08 12:08 ` Jacques Garrigue
2007-02-08 9:56 ` Frédéric Gava
2007-02-08 10:45 ` Xavier Leroy
2007-02-08 15:16 ` Frédéric Gava
2007-02-09 2:58 ` Jacques Garrigue
2007-02-09 9:06 ` ls-ocaml-developer-2006
2007-02-09 10:32 ` ls-ocaml-developer-2006
2007-02-09 14:22 ` skaller
2007-02-09 21:47 ` ls-ocaml-developer-2006
2007-02-09 21:55 ` Andrej Bauer
2007-02-09 22:36 ` ls-ocaml-developer-2006
2007-02-09 23:53 ` Jon Harrop
2007-02-10 1:41 ` ls-ocaml-developer-2006
2007-02-10 2:24 ` Jon Harrop
2007-02-10 14:41 ` ls-ocaml-developer-2006
2007-02-10 14:52 ` Jon Harrop
2007-02-10 15:51 ` ls-ocaml-developer-2006
2007-02-10 16:10 ` Xavier Leroy
2007-02-10 16:11 ` Jon Harrop
2007-02-10 14:55 ` Mattias Engdegård
2007-02-11 13:13 ` Christophe Raffalli
2007-02-10 1:10 ` Brian Hurt [this message]
2007-02-10 1:16 ` Robert Roessler
2007-02-09 23:56 ` Jon Harrop
2007-02-09 12:05 ` Jon Harrop
2007-02-09 12:35 ` ls-ocaml-developer-2006
2007-02-09 13:50 ` Brian Hurt
2007-02-09 14:23 ` Gerd Stolpmann
2007-02-09 14:24 Frederic GAVA
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=Pine.LNX.4.64.0702092000180.19734@localhost \
--to=bhurt@spnz.org \
--cc=Andrej.Bauer@andrej.com \
--cc=caml-list@yquem.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