This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: What is wrong with Bugzilla? [Was: Re: GCC and Floating-Point]


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]