-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathtrapfpe
41 lines (40 loc) · 2.12 KB
/
trapfpe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/****************************************************************************
* ArtraCFD *
* <By Huangrui Mo> *
* Copyright (C) Huangrui Mo <huangrui.mo@gmail.com> *
* This file is part of ArtraCFD. *
* ArtraCFD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
****************************************************************************/
/****************************************************************************
* Required Header Files
****************************************************************************/
#define _GNU_SOURCE 1 /* GNU C library for floating-point control */
#include <fenv.h> /* floating-point control environment */
/****************************************************************************
* Function definitions
****************************************************************************/
/*
* GNU floating-point exception handling
*
* This is to use a C-callable mechanism to provide general control over
* whether or not floating-point exceptions are trapped or ignored, which
* can be invoked at startup using gcc's constructor attribute. Compiling
* and linking this C code with your program will turn on exception
* trapping for the "common" exceptions on a GNU system.
*
* When an floating-point exception occurs, your program will be sent the
* SIGFPE signal. By default, when SIGFPE is delivered the program will
* terminate, and a core will be dumped. This allows you to debug the
* program at the point where the problem first occurs.
*/
static void __attribute__ ((constructor)) trapfpe (void)
{
/*
* Trap floating point exceptions
*/
feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
}
/* a good practice: end file with a newline */