#if HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <ieeefp.h>
#include <setjmp.h>
#include <signal.h>

#if !SKIP_LOCAL_INCLUDES
#include "exception.h"
#include "message.h"
#endif

static void
catch_sigfpe (int sig, int code, struct sigcontext *scp)
{
  fail ("Floating point exception.");
  raise_exception ();
}

void
enable_fpe_traps ()
{
  struct sigaction act;

  act.sa_handler = (void (*)(int)) catch_sigfpe;
  sigemptyset (&act.sa_mask);
  act.sa_flags = 0;

  if (sigaction (SIGFPE, &act, NULL))
      wipeout ("Bad sigaction call.");

  sigaddset (&act.sa_mask, SIGFPE);
  sigprocmask (SIG_UNBLOCK, &act.sa_mask, NULL);

  fpsetmask (FP_X_INV | FP_X_DZ | FP_X_OFL);
}
