sscanf & long double seems broken ?
David C Binderman
dcb@pncl.co.uk
Sun Nov 15 09:41:00 GMT 1998
Hello there,
Not sure this is the correct destination, but ISO C library
is *part* of ISO C++ ...
I find that sscanf, when used with ISO C specifiers %Le, %Lf and %Lg,
I cannot seem to get working, for RedHat Linux 5.1 on Alpha EV5.6,
for recent egcs snapshots.
# define NEAR(a, b) ((a >= (b * 0.99)) && (a <= (b * 1.01)))
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int
main(void)
{
const char * const pi = "3.14159265";
// -----------------------------
double x = 0.0;
sscanf( pi, "%lg", &x);
if (NEAR( x, M_PI))
{
printf( "1. ok\n");
} else {
printf( "1. broken, got %f, expected %f\n", x, M_PI);
};
// -----------------------------
long double y = 0.0;
sscanf( pi, "%Le", &y);
if (NEAR( y, M_PI))
{
printf( "2. ok\n");
} else {
printf( "2. broken, got %Lf, expected %Lf\n", y, (long double) M_PI);
};
// -----------------------------
long double z;
sscanf( pi, "%Lf", &z);
if (NEAR( z, M_PI))
{
printf( "3. ok\n");
} else {
printf( "3. broken, got %Lf, expected %Lf\n", z, (long double) M_PI);
};
// -----------------------------
long double w;
sscanf( pi, "%Lg", &w);
if (NEAR( w, M_PI))
{
printf( "4. ok\n");
} else {
printf( "4. broken, got %Lf, expected %Lf\n", w, (long double) M_PI);
};
return 0;
}
produces
1. ok
2. broken, got 0.000000, expected 3.141593
3. broken, got 0.000000, expected 3.141593
4. broken, got 0.000000, expected 3.141593
Is this fixed in any later ISO C library ?
I have glibc version glibc-2.0.7-13
Regards
David C Binderman MSc BSc +44 1293 534847 dcb@pncl.co.uk
More information about the Gcc-bugs
mailing list