From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Multiplication of matrix in C and OCaml
Date: Sat, 10 Feb 2007 14:52:02 +0000 [thread overview]
Message-ID: <200702101452.02955.jon@ffconsultancy.com> (raw)
In-Reply-To: <hbtzxu13d9.fsf@hod.lan.m-e-leypold.de>
On Saturday 10 February 2007 14:41, ls-ocaml-developer-2006@m-e-leypold.de
wrote:
> Just to be sure: Would the compiler be wrong to optimize
>
> c * q > c * k
>
> to just
>
> q > k
>
> (all floats). And why?
Consider c=0, q=3 and k=2:
0 * 3 > 0 * 2 --> false
3 > 2 --> true
It is just mathematically incorrect.
> If not, why, in the case above?
Floats are not reals, they are just an approximation that happens to be very
useful. Floats do not obey the same laws (e.g. associativity). However,
programmers may be relying upon this fact, e.g. when doing exact float
arithmetic.
> I don't want
> letter and verse, but a general hand waving in the right direction
> would be nice, since I have the impression, that is exactly what Gcc
> 4.1. is currently doing (though for the integer case).
Ints are completely different because they are exact (as modulo integers). So
they do obey the same laws and they do not have special constants (like
infinity, neg_infinity, nan, -0. and so on as floats do).
Xavier has written some enlightening posts here in the past, regarding the
adoption of strict IEEE compliance in OCaml:
http://caml.inria.fr/pub/ml-archives/caml-list/2004/10/ffa452944f4bb9827f2cdca552f4f823.en.html
For an example of someone using the float constants that lie outside the set
of reals, look no further than my ray tracer:
http://www.ffconsultancy.com/free/ray_tracer/languages.html
I used an initial intersection parameter of lambda=infinity to represent no
intersection (or intersecting with the sky). I would be mortified if a
compiler decided to optimise away my necessary and working code just because
infinity is not in the set of real numbers.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists
next prev parent reply other threads:[~2007-02-10 14: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 [this message]
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
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=200702101452.02955.jon@ffconsultancy.com \
--to=jon@ffconsultancy.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