Exemplo n.º 1
0
Program::Program() {
#ifndef NDEBUG
    feenableexcept (FE_DIVBYZERO);
    feenableexcept (FE_INVALID);
    feenableexcept (FE_OVERFLOW);
#endif
}
Exemplo n.º 2
0
/* Test that program aborts with no masked interrupts */
static void
feexcp_nomask_test (const char *flag_name, int fe_exc)
{
  int status;
  pid_t pid;

  if (!EXCEPTION_ENABLE_SUPPORTED (fe_exc) && feenableexcept (fe_exc) == -1)
    {
      printf ("Test: not testing feenableexcept, it isn't implemented.\n");
      return;
    }

  printf ("Test: after feenableexcept (%s) processes will abort\n",
	  flag_name);
  printf ("      when feraiseexcept (%s) is called.\n", flag_name);
  pid = fork ();
  if (pid == 0)
    {
#ifdef RLIMIT_CORE
      /* Try to avoid dumping core.  */
      struct rlimit core_limit;
      core_limit.rlim_cur = 0;
      core_limit.rlim_max = 0;
      setrlimit (RLIMIT_CORE, &core_limit);
#endif

      fedisableexcept (FE_ALL_EXCEPT);
      feenableexcept (fe_exc);
      feraiseexcept (fe_exc);
      exit (2);
    }
  else if (pid < 0)
    {
      if (errno != ENOSYS)
	{
	  printf ("  Fail: Could not fork.\n");
	  ++count_errors;
	}
      else
	printf ("  `fork' not implemented, test ignored.\n");
    }
  else {
    if (waitpid (pid, &status, 0) != pid)
      {
	printf ("  Fail: waitpid call failed.\n");
	++count_errors;
      }
    else if (WIFSIGNALED (status) && WTERMSIG (status) == SIGFPE)
      printf ("  Pass: Process received SIGFPE.\n");
    else
      {
	printf ("  Fail: Process didn't receive signal and exited with status %d.\n",
		status);
	++count_errors;
      }
  }
}
Exemplo n.º 3
0
static void
test_feenableexcept (void)
{
#if defined FE_ALL_EXCEPT
  int res;

  fedisableexcept (FE_ALL_EXCEPT);

  res = feenableexcept (FE_ALL_EXCEPT);

  if (!EXCEPTION_ENABLE_SUPPORTED (FE_ALL_EXCEPT) && (res == -1))
    {
      puts ("feenableexcept (FE_ALL_EXCEPT) not supported, cannot test.");
      return;
    }
  else if (res != 0)
    {
      puts ("feenableexcept (FE_ALL_EXCEPT) failed");
      count_errors++;
    }

  if (fegetexcept () != FE_ALL_EXCEPT)
    {
      puts ("feenableexcept did not set all exceptions");
      count_errors++;
    }
#endif
}
Exemplo n.º 4
0
Arquivo: fe.c Projeto: fferri/tvs
int main (int argc, char **argv)
{
    double s;
    struct sigaction act;

    act.sa_sigaction = (void(*))fhdl;
    sigemptyset (&act.sa_mask);
    act.sa_flags = SA_SIGINFO;
    

//  printf ("Old divByZero exception: 0x%08X\n", feenableexcept (FE_DIVBYZERO));
    printf ("Old invalid exception:   0x%08X\n", feenableexcept (FE_INVALID));
    printf ("New fp exception:        0x%08X\n", fegetexcept ());

    // set handler
    if (sigaction(SIGFPE, &act, (struct sigaction *)0) != 0)
    {
        perror("Yikes");
        exit(-1);
    }

//  s = 1.0 / 0.0;  // FE_DIVBYZERO
    s = 0.0 / 0.0;  // FE_INVALID
    return 0;
}
Exemplo n.º 5
0
Arquivo: Xyce.C Projeto: Xycedev/Xyce
//
//-----------------------------------------------------------------------------
// Function      : main
// Purpose       : front end for standalone Xyce executable
// Special Notes :
// Scope         :
// Creator       : Eric Rankin
// Creation Date : 01/28/2004
//-----------------------------------------------------------------------------
int main( int iargs, char *cargs[] )
{
  // Set divide by zero, and invalid operation handling on linux
#ifdef HAVE_LINUX_EXCEPTIONS
  feenableexcept(FE_DIVBYZERO | FE_INVALID);
#endif
  // Set out of memory detection on all systems
  std::set_new_handler (&_new_handler);

  bool bsuccess = false;
#ifdef Xyce_Dakota
  if( checkForDakotaFlag( iargs, cargs ) == true )
  {
    // this will be a Xyce simulation where Dakota creates and
    // then runs N_CIR_Xyce(). So pass control to it

    N_DAK_DakotaController dakotaController( iargs, cargs );
    bsuccess = dakotaController.run();
  }
  else
#endif
  {
    N_CIR_Xyce xyce;
    bsuccess = xyce.run( iargs, cargs );
  }
  (bsuccess) ? exit(0) : exit(-1);
}
/**
@details
-# If incoming on_off flag is true assign fpe_sig_handler() as the signal handler for SIGFPE.
-# Else revert to the default signal handler SIG_DFL.
-# set trap_sigfpe to the current on_off status
   Requirement [@ref r_exec_signal_0].
   Requirement [@ref r_exec_signal_0].
*/
int Trick::Executive::set_trap_sigfpe(bool on_off) {
    static struct sigaction sigact;

    if ( on_off ) {
        /* Assign fpe_sig_handler() as the signal handler for SIGFPE. */
#ifdef __linux
        feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW);
#endif
#if (__APPLE__ | __CYGWIN__ | __INTERIX )
        sigact.sa_handler = (void (*)(int)) fpe_sig_handler;
#else
        sigact.sa_flags = SA_SIGINFO;
        sigact.sa_sigaction = (void (*)(int, siginfo_t *, void *)) fpe_sig_handler;
#endif
    } else {
#ifdef __linux
        fedisableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW);
#endif
        sigact.sa_handler = SIG_DFL;
    }

    if (sigaction(SIGFPE, &sigact, NULL) < 0) {
        perror("sigaction() failed for SIGFPE");
    } else {
        trap_sigfpe = on_off ;
    }

    return(0) ;
}
Exemplo n.º 7
0
	int fpe_enable_trap( unsigned int except )
	{
		if( feclearexcept( (int)except ) < 0 )
			return -1;

		return feenableexcept( (int)except );
	}
Exemplo n.º 8
0
void PetscSetupUtils::CommonSetup()
{
    InitialisePetsc();

    // Check that the working directory is correct, or many tests will fail
    std::string cwd = GetCurrentWorkingDirectory() + "/";
    if (strcmp(cwd.c_str(), ChasteBuildRootDir()) != 0)
    {
#define COVERAGE_IGNORE
        // Change directory
        std::cout << std::endl << "Changing directory from '" << cwd << "' to '" << ChasteBuildRootDir() << "'." << std::endl;
        EXPECT0(chdir, ChasteBuildRootDir());
        std::cout << "CWD now: " << GetCurrentWorkingDirectory() << std::endl;
#undef COVERAGE_IGNORE
    }

#ifdef TEST_FOR_FPE
    // Give all PETSc enabled tests the ability to trap for divide-by-zero
    feenableexcept(FE_DIVBYZERO | FE_INVALID );
    // Catch all SIGFPE signals and convert them to exceptions (before PETSc gets to them)
    struct sigaction sa;
    sa.sa_sigaction = FpeSignalToAbort;
    sa.sa_flags = SA_RESETHAND|SA_SIGINFO;
    sa.sa_restorer = 0;
    sigaction(SIGFPE, &sa, NULL);
#endif
}
Exemplo n.º 9
0
void Set_Floating_Point_Exception_Handling(const bool enable,const bool division_by_zero,const bool invalid_operation,const bool overflow,const bool underflow,const bool inexact_result)
{
    static bool have_original_action=false;
    static struct sigaction original_action;
    if(!have_original_action){ // initialize with original action
        sigaction(SIGFPE,0,&original_action);}
    if(enable){
        int exceptions=0;
        if(division_by_zero) exceptions|=FE_DIVBYZERO;
        if(invalid_operation) exceptions|=FE_INVALID;
        if(overflow) exceptions|=FE_OVERFLOW;
        if(underflow) exceptions|=FE_UNDERFLOW;
        if(inexact_result) exceptions|=FE_INEXACT;
        // avoid catching delayed exceptions caused by external code
        fedisableexcept(FE_ALL_EXCEPT);
        feclearexcept(exceptions);
        // install new handler
        struct sigaction action;
        action.sa_flags=SA_SIGINFO;
        action.sa_sigaction=Floating_Point_Exception_Handler;
        sigemptyset(&action.sa_mask);
        if(sigaction(SIGFPE,&action,0)) PHYSBAM_FATAL_ERROR("Could not register FPE signal handler");
        feenableexcept(exceptions);}
    else{
        if(sigaction(SIGFPE,&original_action,0)) PHYSBAM_FATAL_ERROR("Could not restore FPE signal handler");
        fedisableexcept(FE_ALL_EXCEPT);}
}
Exemplo n.º 10
0
/**
 * gfs_enable_floating_point_exceptions:
 *
 * Enables floating-point exceptions (they are enabled by default
 * when using the Gerris library).
 */
void gfs_enable_floating_point_exceptions (void)
{
#ifdef EXCEPTIONS
  disabled_fpe = FALSE;
  feenableexcept (EXCEPTIONS);
#endif /* !EXCEPTIONS */
}
Exemplo n.º 11
0
void
__ktrap(void)
{
  if (&__ktrapval != 0) {
    int bv = __ktrapval;
    if (bv != 0) {
      /*
       *  -Ktrap      bv
       *    fp      0x001  => inv | divz | ovf
       *    inv     0x008
       *    divz    0x020
       *    ovf     0x040
       *    unf     0x080
       *    inexact 0x100
       */
      int excepts = 0;
      if (bv & 0x001)
        bv = 0x008 | 0x020 | 0x040;
      if (bv & 0x008)
        excepts |= FE_INVALID;
      if (bv & 0x020)
        excepts |= FE_DIVBYZERO;
      if (bv & 0x040)
        excepts |= FE_OVERFLOW;
      if (bv & 0x080)
        excepts |= FE_UNDERFLOW;
      if (bv & 0x100)
        excepts |= FE_INEXACT;
      feenableexcept(excepts);  /* glibc 2.2 extension to fenv.h */
    }
  }
}
Exemplo n.º 12
0
int main (int    argc,
	  char** argv)
// ---------------------------------------------------------------------------
// Driver.
// ---------------------------------------------------------------------------
{
#ifdef _GNU_SOURCE
  feenableexcept (FE_OVERFLOW);    // -- Force SIG8 crash on FP overflow.
#endif

  char*            session;
  vector<Element*> elmt;
  FEML*            file;
  Mesh*            mesh;
  BCmgr*           bman;
  Domain*          domain;
  DNSAnalyser*     analyst;
  
  Femlib::initialize (&argc, &argv);
  getargs (argc, argv, session);

  preprocess (session, file, mesh, elmt, bman, domain);

  analyst = new DNSAnalyser (domain, bman, file);
  
  domain -> restart();

  ROOTONLY domain -> report();
  
  integrateNS (domain, analyst);

  Femlib::finalize();

  return EXIT_SUCCESS;
}
Exemplo n.º 13
0
void Replay::set_signal_handlers(void)
{
    struct sigaction sa;

    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0;

    if (generate_fpe) {
        // SITL_State::_parse_command_line sets up an FPE handler.  We
        // can do better:
        feenableexcept(FE_INVALID | FE_OVERFLOW);
        sa.sa_handler = _replay_sig_fpe;
    } else {
        // disable floating point exception generation:
        int exceptions = FE_OVERFLOW | FE_DIVBYZERO;
#ifndef __i386__
        // i386 with gcc doesn't work with FE_INVALID
        exceptions |= FE_INVALID;
#endif
        if (feclearexcept(exceptions)) {
            ::fprintf(stderr, "Failed to disable floating point exceptions: %s", strerror(errno));
        }
        sa.sa_handler = SIG_IGN;
    }

    if (sigaction(SIGFPE, &sa, nullptr) < 0) {
        ::fprintf(stderr, "Failed to set floating point exceptions' handler: %s", strerror(errno));
    }
}
Exemplo n.º 14
0
Arquivo: fp.c Projeto: Kun-Qu/petsc
EXTERN_C_END

#undef __FUNCT__
#define __FUNCT__ "PetscSetFPTrap"
PetscErrorCode  PetscSetFPTrap(PetscFPTrap on)
{
  PetscFunctionBegin;
  if (on == PETSC_FP_TRAP_ON) {
    /* Clear any flags that are currently set so that activating trapping will not immediately call the signal handler. */
    if (feclearexcept(FE_ALL_EXCEPT)) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Cannot clear floating point exception flags\n");
#if defined FE_NOMASK_ENV
    /* We could use fesetenv(FE_NOMASK_ENV), but that causes spurious exceptions (like gettimeofday() -> PetscLogDouble). */
    if (feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) == -1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Cannot activate floating point exceptions\n");
#elif defined PETSC_HAVE_XMMINTRIN_H
    _MM_SET_EXCEPTION_MASK(_MM_MASK_INEXACT);
#else
    /* C99 does not provide a way to modify the environment so there is no portable way to activate trapping. */
#endif
    if (SIG_ERR == signal(SIGFPE,PetscDefaultFPTrap)) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Can't set floating point handler\n");
  } else {
    if (fesetenv(FE_DFL_ENV)) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Cannot disable floating point exceptions");
    if (SIG_ERR == signal(SIGFPE,SIG_DFL)) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Can't clear floating point handler\n");
  }
  _trapmode = on;
  PetscFunctionReturn(0);
}
Exemplo n.º 15
0
int set_fpe_x87_sse_(void)
{
  int retcode;
  
  retcode = feenableexcept(FE_OVERFLOW|FE_DIVBYZERO|FE_INVALID);

  return(retcode);
}
Exemplo n.º 16
0
        void disable_FPE() {
#if defined(WIN32) || defined(__APPLE__)
	    Logger::warn("Process") << "FPE control not implemented under Windows" << std::endl ;
#else
            feenableexcept(0);
	    Logger::out("Process") << "Disabled FPE" << std::endl ;
#endif
        }
Exemplo n.º 17
0
int fpe_enable_traps (const int excepts) {
#ifdef FPE_WITH_TRAP_CONTROL
   return feenableexcept (excepts);
   fpe_handler_update_mask ();
#else
   return -1;
#endif
}
Exemplo n.º 18
0
TEST(fenv, feenableexcept_fegetexcept) {
#if defined(__aarch64__) || defined(__arm__)
  // ARM doesn't support this. They used to if you go back far enough, but it was removed in
  // the Cortex-A8 between r3p1 and r3p2.
  ASSERT_EQ(-1, feenableexcept(FE_INVALID));
  ASSERT_EQ(0, fegetexcept());
  ASSERT_EQ(-1, feenableexcept(FE_DIVBYZERO));
  ASSERT_EQ(0, fegetexcept());
  ASSERT_EQ(-1, feenableexcept(FE_OVERFLOW));
  ASSERT_EQ(0, fegetexcept());
  ASSERT_EQ(-1, feenableexcept(FE_UNDERFLOW));
  ASSERT_EQ(0, fegetexcept());
  ASSERT_EQ(-1, feenableexcept(FE_INEXACT));
  ASSERT_EQ(0, fegetexcept());
  ASSERT_EQ(-1, feenableexcept(FE_DENORMAL));
  ASSERT_EQ(0, fegetexcept());
#else
  // We can't recover from SIGFPE, so sacrifice a child...
  pid_t pid = fork();
  ASSERT_NE(-1, pid) << strerror(errno);

  if (pid == 0) {
    feclearexcept(FE_ALL_EXCEPT);
    ASSERT_EQ(0, fetestexcept(FE_ALL_EXCEPT));
    ASSERT_EQ(0, feenableexcept(FE_INVALID));
    ASSERT_EQ(FE_INVALID, fegetexcept());
    ASSERT_EQ(0, feraiseexcept(FE_INVALID));
    _exit(123);
  }

  AssertChildExited(pid, -SIGFPE);
#endif
}
Exemplo n.º 19
0
void Replay::setup()
{
    ::printf("Starting\n");

    uint8_t argc;
    char * const *argv;

    hal.util->commandline_arguments(argc, argv);

    _parse_command_line(argc, argv);

    if (!check_generate) {
        logreader.set_save_chek_messages(true);
    }

    // _parse_command_line sets up an FPE handler.  We can do better:
    signal(SIGFPE, _replay_sig_fpe);

    hal.console->printf("Processing log %s\n", filename);

    // remember filename for reporting
    log_filename = filename;

    if (!find_log_info(log_info)) {
        printf("Update to get log information\n");
        exit(1);
    }

    hal.console->printf("Using an update rate of %u Hz\n", log_info.update_rate);

    if (!logreader.open_log(filename)) {
        perror(filename);
        exit(1);
    }

    _vehicle.setup();

    inhibit_gyro_cal();
    set_ins_update_rate(log_info.update_rate);

    feenableexcept(FE_INVALID | FE_OVERFLOW);


    plotf = fopen("plot.dat", "w");
    plotf2 = fopen("plot2.dat", "w");
    ekf1f = fopen("EKF1.dat", "w");
    ekf2f = fopen("EKF2.dat", "w");
    ekf3f = fopen("EKF3.dat", "w");
    ekf4f = fopen("EKF4.dat", "w");

    fprintf(plotf, "time SIM.Roll SIM.Pitch SIM.Yaw BAR.Alt FLIGHT.Roll FLIGHT.Pitch FLIGHT.Yaw FLIGHT.dN FLIGHT.dE FLIGHT.Alt AHR2.Roll AHR2.Pitch AHR2.Yaw DCM.Roll DCM.Pitch DCM.Yaw EKF.Roll EKF.Pitch EKF.Yaw INAV.dN INAV.dE INAV.Alt EKF.dN EKF.dE EKF.Alt\n");
    fprintf(plotf2, "time E1 E2 E3 VN VE VD PN PE PD GX GY GZ WN WE MN ME MD MX MY MZ E1ref E2ref E3ref\n");
    fprintf(ekf1f, "timestamp TimeMS Roll Pitch Yaw VN VE VD PN PE PD GX GY GZ\n");
    fprintf(ekf2f, "timestamp TimeMS AX AY AZ VWN VWE MN ME MD MX MY MZ\n");
    fprintf(ekf3f, "timestamp TimeMS IVN IVE IVD IPN IPE IPD IMX IMY IMZ IVT\n");
    fprintf(ekf4f, "timestamp TimeMS SV SP SH SMX SMY SMZ SVT OFN EFE FS DS\n");
}
Exemplo n.º 20
0
void EnableFPE()
{
#if defined(_GNU_SOURCE) && !defined(__APPLE__)
	// clear any outstanding exceptions before enabling, otherwise they'll
	// trip immediately
	feclearexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
	feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
#endif
}
Exemplo n.º 21
0
static int
do_test (void)
{
  if (FE_ALL_EXCEPT == 0)
    {
      printf("Skipping test; no support for FP exceptions.\n");
      return 0;
    }

  int except_mask = 0;
#ifdef FE_DIVBYZERO
  except_mask |= FE_DIVBYZERO;
#endif
#ifdef FE_INVALID
  except_mask |= FE_INVALID;
#endif
#ifdef FE_OVERFLOW
  except_mask |= FE_OVERFLOW;
#endif
#ifdef FE_UNDERFLOW
  except_mask |= FE_UNDERFLOW;
#endif
  int status = feenableexcept (except_mask);

  except_mask = fegetexcept ();
  if (except_mask == -1)
    {
      printf("\nBefore getcontext(): fegetexcept returned: %d\n",
	     except_mask);
      return 1;
    }

  ucontext_t ctx;
  status = getcontext(&ctx);
  if (status)
    {
      printf("\ngetcontext failed, errno: %d.\n", errno);
      return 1;
    }

  printf ("\nDone with getcontext()!\n");
  fflush (NULL);

  int mask = fegetexcept ();
  if (mask != except_mask)
    {
      printf("\nAfter getcontext(): fegetexcept returned: %d, expected: %d.\n",
	     mask, except_mask);
      return 1;
    }

  printf("\nAt end fegetexcept() returned %d, expected: %d.\n",
	 mask, except_mask);

  return 0;
}
Exemplo n.º 22
0
 static void
  ieee0(Void)
        
{
    /* Clear all exception flags */
    if (fedisableexcept(FE_ALL_EXCEPT)==-1)
         unsupported_error();
    if (feenableexcept(FE_DIVBYZERO|FE_INVALID|FE_OVERFLOW)==-1)
         unsupported_error();
}
Exemplo n.º 23
0
int main(int, char* argv[]) {
	feenableexcept (FE_DIVBYZERO);
	feenableexcept (FE_INVALID);
	feenableexcept (FE_OVERFLOW);
	const int col1 = 14 * (atoi(argv[2]) - 1);
	const int col2 = 14 * (atoi(argv[2]));
	const char* filename = argv[1];
	double phase = 0.0, last_t = 0.0;
	std::vector<double> d;
	char buffer[BUFSZ];
	FILE* fp = fopen(filename, "rt");
	while (!feof(fp)) {
		fgets(buffer, BUFSZ - 1, fp);
		if( feof(fp)) {
			break;
		}
		double this_t = atof(buffer);
		const double omega = atof(buffer + OMEGA_COL);
		const double x = atof(buffer + col1);
		const double y = atof(buffer + col2);
		const double dat = (x * cos(phase) - y*sin(phase))/ sqrt(x*x+y*y);
		d.push_back(dat);
		const double dt = this_t - last_t;
		phase += omega * dt;
		last_t = this_t;
	}

	int sz = d.size();
	double a, b;
	for( int n = 0; n != sz; ++n ) {
		a = b = 0.0;
		const double theta_0 = 2.0 * M_PI * double(n) / double(sz);
		for (int i = 0; i < sz; i++) {
			const double d0 = d[i];
			a += cos(-theta_0 * i) * d0;
			b += sin(-theta_0 * i) * d0;
		}
		a /= sz;
		b /= sz;
		printf("%e %e %e\n", theta_0, a, b);
	}
	return 0;
}
Exemplo n.º 24
0
int main(void)
{
  double x = __builtin_nan ("");
  long double y = 1.1L;

  feenableexcept (FE_INEXACT);
  feclearexcept (FE_ALL_EXCEPT);
  x = x + y;
  return fetestexcept(FE_INEXACT);
}
Exemplo n.º 25
0
static void setup_sigfpe_handler(void)
{
  struct sigaction a;
  feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW);
  memset(&a, 0, sizeof(a));
  a.sa_sigaction = sigfpe_handler;
  a.sa_flags = SA_SIGINFO;
  if (sigaction(SIGFPE, &a, NULL) == -1) {
       fprintf(stderr, "cannot install sigfpe handler\n");
       exit(1);
  }
}
Exemplo n.º 26
0
void enableFloatingPointTraps(bool enable)
{
	static const int FLAGS = FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW;
	if(enable)
	{
			feenableexcept(FLAGS);
	}
	else
	{
			fedisableexcept(FLAGS);
	}
}
Exemplo n.º 27
0
/**
 * gfs_restore_floating_point_exceptions:
 *
 * Restores the default floating-point exceptions set in the Gerris
 * library.
 *
 * Returns: 0 if no exceptions where raised between this call and the
 * call to gfs_catch_floating_point_exceptions(), non-zero otherwise.
 */
int gfs_restore_floating_point_exceptions (void)
{
#ifdef EXCEPTIONS
  int ret = fetestexcept (EXCEPTIONS);
  feclearexcept (EXCEPTIONS);
  if (!disabled_fpe)
    feenableexcept (EXCEPTIONS);
  return ret;
#else /* !EXCEPTIONS */
  return 0;
#endif /* !EXCEPTIONS */
}
Exemplo n.º 28
0
/**
 * @brief Call the real polynomial (or secular equation, or whatever) solver
 * and do the computation.
 *
 * The algorithm used must be selected before this call with <code>mps_select_algorithm</code>
 * and the data (the coefficients, or whatever the algorithm may require) should be provided
 * after that.
 *
 * Roots can then be obtained with the functions <code>mps_context_get_roots_*</code>
 *
 */
void
mps_mpsolve (mps_context * s)
{
#ifdef MPS_CATCH_FPE
  feenableexcept (FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW); 
#endif

  if (mps_context_has_errors (s))
    return;

  (*s->mpsolve_ptr) (s);
}
Exemplo n.º 29
0
static void fpe_trap_setup(void)
{
    struct sigaction trap;

    sigemptyset(&trap.sa_mask);
    trap.sa_flags = SA_SIGINFO;
    trap.sa_sigaction = sigfpe_handler;

    sigaction(SIGFPE, &trap, NULL);
    //feenableexcept(FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW);
    //feenableexcept(FE_ALL_EXCEPT);
    feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
}
Exemplo n.º 30
0
void primitive_reset_float_environment(void)
{
  feclearexcept(FE_ALL_EXCEPT);
#if defined OPEN_DYLAN_PLATFORM_FREEBSD || defined OPEN_DYLAN_PLATFORM_LINUX
  feenableexcept(FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INVALID);
#elif defined OPEN_DYLAN_PLATFORM_DARWIN \
  && (defined OPEN_DYLAN_ARCH_X86 || defined OPEN_DYLAN_ARCH_X86_64)
  fenv_t fenv;
  fegetenv(&fenv);
  fenv.__control &= ~(FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INVALID);
  fenv.__mxcsr &= ~((FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INVALID) << 7);
  fesetenv(&fenv);
#endif
}