This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc 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] | |
------- Additional Comments From khalil dot ghorbal at cea dot fr 2008-06-05 17:52 -------
Hi all,
I have noticed the same problem with libc-2.3.6 (I'm using a precompiled libc6
debian(etch) package).
In the example submitted by Vincent, maybe we should calculate x after choosing
the rounding mode: since x
is evaluated first, the default rounding mode (toward +oo) is used. Altering the
rounding mode later won't
change the internal binary representation for x (the type qualifier volatile
here is without effect).
But even doing this don't change the output of printf !
In fact, to get a correct (with respect to IEEE 754) result, I used an
intermediate variable, say "b", set
to 3.0, we get (see bottom for modified source code):
(using %a)
1/3 rounded downward: 0x1.5555555555555p-2
1/3 rounded upward: 0x1.5555555555556p-2
(using %.17f)
1/3 rounded downward: 0.33333333333333331
1/3 rounded upward: 0.33333333333333337
A height precision (at least .17) is needed to see the difference using %f
instead of %a (and this is not a normal behaviour, as one should see directly
the difference, since we print two different numbers !).
To summarize :
- fesetround don't influence the internal representation of constants such as
1./3. (or 1./10.)
- using %f seems to have some troubles ...
Hope this helps.
Regards,
<<<<<< source modified >>>>>>>>
#include <stdio.h>
#include <fenv.h>
static volatile double x;
void out (const char *s, int r)
{
double b = 3.0;
if (fesetround (r))
fprintf (stderr, "fesetround error\n");
else
x = 1.0/b;
printf ("1/3 rounded %s: %a\n", s, x);
}
int main (void)
{
out ("downward", FE_DOWNWARD);
out (" upward", FE_UPWARD);
return 0;
}
--
http://sourceware.org/bugzilla/show_bug.cgi?id=5044
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |