Re: [xml] XPath Infinities
- From: Bjorn Reese <breese mail1 stofanet dk>
- To: Ray Strode <halfline hawaii rr com>
- Cc: xml gnome org
- Subject: Re: [xml] XPath Infinities
- Date: Sun, 29 Apr 2001 08:20:04 +0000
Ray Strode wrote:
+ #if defined(__osf__) && defined(__GNUC__)
The problem happened on RedHat 7.0. Is __osf__ defined for RedHat 7.0?
The bug report only mentioned Alpha, and I assumed that we were talking
about Digital Unix (or True64 or whatever they call it these days), so
that's what I tested.
And no, __osf__ is not defined for RedHat. The native Unix on Alpha has
changed name a couple of times, but originally it was called OSF/1, and
the __osf__ define has stuck ever since.
Are you using Linux on Alpha? If so, you could try with the __alpha__
(or something similar) define instead of __osf__. You can get a list of
built-in defines for GCC with
gcc -E -dM -x c /dev/null
Do you really think that just blinding ignoring Floating point exceptions is
a good idea?
I _know_ that it is a good idea. NaN and Inf depends both on hardware, OS,
and compiler support, so you will typically experience different behaviour
on different platforms/compilers.
If you use GCC on Alpha, then 0/0 will normally result in a core dump.
If you supply your own signal handler for SIGFPE, then it returns 0
(or some arbitrary value). If you ignore the signal handler, then it
returns NaN, which is the desired output.
So, you have to ignore SIGFPE on Alpha using GCC.
Also, how is your #ifdef and better than Igor's?
No idea, which is why I left Igor's patch in.
Last question,
your patch still divides by zero in the initialization of the variables, so
I guess I don't really understand the point of the other code? Because it
divides by zero in the initialization it won't cause the SIGFPE, and thus it
will never need to be trapped. Right?
Right. Instead we get a NaN.
With C99 compilers there is a NAN macro which can be used instead.
Or are you saying that the bug still existed on OSF?
With the native C compiler, yes.
#include <stdio.h>
#include <math.h>
#include <float.h>
#include <signal.h>
#include <nan.h>
#ifndef isnan
int isnan(volatile double number)
{
double integral, fraction;
return (/* NaN is the only number which does not compare to itself */
(number != number) ||
/* Fallback solution if NaN compares to NaN */
((number != 0.0) &&
(fraction = modf(number, &integral),
integral == fraction)));
}
#endif
#ifndef isinf
int isinf(double number)
{
#ifdef IsINF
return IsINF(number);
#else
return ((number == HUGE_VAL) ? 1 : ((number == -HUGE_VAL) ? -1 : 0));
#endif
}
#endif
double SetNaN()
{
return 0.0 / 0.0;
}
double SetPInf()
{
return 1.0 / 0.0;
}
double SetNInf()
{
return -1.0 / 0.0;
}
int main(void)
{
double nan_number;
double pinf_number;
double ninf_number;
#if defined(__GNUC__)
signal(SIGFPE, SIG_IGN);
#endif
nan_number = SetNaN();
pinf_number = SetPInf();
ninf_number = SetNInf();
printf(" NaN: %6f %2d\n", nan_number, isnan(nan_number));
printf("+Inf: %6f %2d\n", pinf_number, isinf(pinf_number));
printf("-Inf: %6f %2d\n", ninf_number, isinf(ninf_number));
printf(" NaN: %6f %2d\n", 0.0, isnan(0.0));
printf("+Inf: %6f %2d\n", 0.0, isinf(0.0));
printf("-Inf: %6f %2d\n", 0.0, isinf(0.0));
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]