Mail Archives: djgpp/1997/11/02/18:04:04
Hi guys,
Sorry to follow up myself. I just found out if I hardcode the numbers in
the assertion there won't be any failure. However, the following piece of
code certainly failed:
#include <assert.h>
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
int main()
{
char buf[32];
double db;
float fl;
long double ld;
assert(sprintf(buf, "%E|%.2f|%Lg", 1.1e20, -3.346, .02L) == 23);
assert(strcmp(buf, "1.100000E+20|-3.35|0.02") == 0);
assert(sscanf(buf, "%e|%lg|%Lf", &fl, &db, &ld) == 3);
assert(fabs(fl - 1.1e20) / 1.1e20 < 4 * FLT_EPSILON);
assert(fabs(db + 3.35) / 3.35 < 4 * DBL_EPSILON);
assert(fabs(ld - 0.02) / 0.02 < 4 * LDBL_EPSILON);
return(0);
}
It seems to be the problem of the string functions rather than that of the
math functions. But the maths functions don't trap EDOM errors is for
sure.
--
Kevin Yeung
Change x to y in email address for private correspondence
- Raw text -