Re: [xml] XPath Infinities

On Sun, Apr 29, 2001 at 07:24:10AM -1000, Ray Strode wrote:
 double SetNaN()
   return 0.0 / 0.0;
Actually, that may segfault on RedHat, too.  It's very specific,
it only allows it when the variable is being initialized to it.
It SIGFPE's any other way.  So double NaN = 0.0/0.0 will work, 
but double NaN = SetNaN(), double NaN = 0/0,and double NaN; NaN /= 0.0, 

  yep, what I ultimately want is the following sequence of code:
    save 0/1/-1 to an FP
    divide this FP by the value 0
it is impossible to avoid compiler "optimization", except maybe by calling
a function which would do the divide by 0 (compiler are unlikely to try
to solve this at compilation time. So the solution is probably to do something

/* keeping the function public to absolutely avoid the compiler from trying
   global optimization on this. */

float xmlXPathDivideBy(float f, float fzero) {
    float ret;
#ifdef SIGFPE
#ifdef SIG_IGN
    void (*sighandler)(int);
    sighandler = signal(SIGFPE, SIG_IGN);
   ret = f / fzero;
#ifdef SIGFPE
#ifdef SIG_IGN
   signal(SIGFPE, sighandler);

   float f, fzero;

   f = 0/1/-1;
   fzero = 0.0;
   f = xmlXPathDivideByZero(f, fzero);

NB: restauring the signal is really important for libxml to be seen as a 
    well behaved library :-)

If both of you could check this solution I think it's the best to do
(should work with MS compiler too).


Daniel Veillard      | Red Hat Network
veillard redhat com  | libxml Gnome XML XSLT toolkit | Rpmfind RPM search engine

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]