This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: What is wrong with Bugzilla? [Was: Re: GCC and Floating-Point]
- From: Vincent Lefevre <vincent+gcc at vinc17 dot org>
- To: gcc at gcc dot gnu dot org
- Date: Wed, 1 Jun 2005 02:22:49 +0200
- Subject: Re: What is wrong with Bugzilla? [Was: Re: GCC and Floating-Point]
- References: <20050531124837.GT3541@ay.vinc17.org> <jefyw3tt8j.fsf@sykes.suse.de> <20050531134304.GV3541@ay.vinc17.org> <jeacmbtrnq.fsf@sykes.suse.de> <20050531171400.GY3541@ay.vinc17.org> <jer7fnjjek.fsf@sykes.suse.de> <20050531195816.GE3541@ay.vinc17.org> <jefyw3jguf.fsf@sykes.suse.de> <20050531224258.GJ3541@ay.vinc17.org> <jemzqb2eb2.fsf@sykes.suse.de>
On 2005-06-01 00:58:25 +0200, Andreas Schwab wrote:
> You are mistaken.
No, I don't see any problem.
> #include <assert.h>
> #include <float.h>
>
> long double one = 1.0;
> long double one_plus_eps;
>
> int
> main (void)
> {
> long double one_plus_eps;
>
> one_plus_eps = one + LDBL_EPSILON;
> assert (one != one_plus_eps);
> return 0;
> }
I don't know how the standard should be interpreted (see below), but
if your program fails, this means that either your program is buggy
or the C implemention is buggy.
The standard says for LDBL_EPSILON: "the difference between 1 and the
least value greater than 1 that is representable in the given floating
point type, b^(1-p)".
One may decide that p = 64. The processor will round to double
precision, but that's OK since the C standard doesn't require
correct rounding (the accuracy is implementation-defined, as
said in #4). Your program will fail because it is not portable:
you made some assumptions about the accuracy.
One may decide that p = 53. I think this is better. Your program
will work (unless LDBL_EPSILON has a value assuming that p = 64,
but this would mean that your C implementation is buggy).
--
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / SPACES project at LORIA