Re: [xml] The NaN dilemma



[ This is a reply to a private email by robert. I am posting on
  the mailing-list, because my mailserver refuses to send mail
  directly to robert (I assume it doesn't like the all-digit
  hostname). ]

I have attached a test program that can be used to examine the
problem further. Compile with and without -DLOOP_FOREVER. If you
do find any detailed explanation of what is going on I would like
to hear about it (currently I assume that the default signal
handler is re-installed after the first ignored SIGFPE is met to
prevent the FPU from causing an infinite loop).
#if defined(__GNUC__) && defined(__i386__)
# define USE_FPU_CONTROL
#endif

#include <stdio.h>
#include <float.h>
#ifdef USE_FPU_CONTROL
# include <fpu_control.h>
#endif
#include <signal.h>

double pinf(void) { return DBL_MAX + DBL_MAX; }
double ninf(void) { return -pinf(); }
double nan(void) { return pinf() + ninf(); }

void SignalCatcher(int signo)
{
  fprintf(stderr, "SignalCatcher(%d)\n", signo);
}

int main(void)
{
#ifdef USE_FPU_CONTROL
  fpu_control_t cw;
#endif
  struct sigaction action;

  sigemptyset(&action.sa_mask);
  action.sa_flags = SA_RESTART;
#ifdef LOOP_FOREVER
  action.sa_handler = SignalCatcher;
#else
  action.sa_handler = SIG_IGN;
#endif
  sigaction(SIGFPE, &action, NULL);

#ifdef USE_FPU_CONTROL
  /* Unmask Invalid Operation */
  _FPU_GETCW(cw);
  cw &= ~(_FPU_MASK_IM);
  _FPU_SETCW(cw);
#endif

  printf("%f\n", pinf());
  printf("%f\n", ninf());
  printf("%f\n", nan());

  return 0;
}


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