Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
Main Page
Related Pages
Topics
Namespaces
Data Structures
Files
File List
Globals
EXTERNAL_HEADERS
RSL
etc
config
src
NO_DBL_TRAPS.cpp
Go to the documentation of this file.
1
// checking if floating point math traps
2
3
25
/* IEEE 754 (IEC 559 supeseded by IEC 60559) specifies that
26
* the following operations return NaN unless they trap:
27
*
28
* 1. sqrt (n); n < 0
29
* 2. rem (x, 0.0), rem (inf, x)
30
* 3. 0 * inf
31
* 4. 0.0 / 0.0, inf / inf
32
* 5. inf - inf (when both inf have the same sign)
33
*
34
* Traps are defined as kind of an exception, typically
35
* causing the delivery of SIGFPE (e.g., with Compaq C++
36
* on Tru64 UNIX, except when using the -ieee flag which
37
* disables traps as required by C).
38
*/
39
40
#include "
nodbg.h
"
41
42
double
dbl_get_zero
();
43
double
dbl_get_one
();
44
45
int
main
(
int
argc,
char
*[])
46
{
47
nodbg
();
48
49
double
dbl_inf;
50
double
dbl_nan;
51
52
double
dbl_zero
=
dbl_get_zero
();
53
double
dbl_one =
dbl_get_one
();
54
55
// compute infinity (division by zero may trap)
56
dbl_inf = dbl_one /
dbl_zero
;
57
58
// computation involving infinities that might trap
59
dbl_nan =
dbl_zero
* dbl_inf;
// #3
60
dbl_nan =
dbl_zero
/
dbl_zero
;
// #4a
61
dbl_nan = dbl_inf / dbl_inf;
// #4b
62
dbl_nan = dbl_inf - dbl_inf;
// #5
63
64
if
(argc > 2)
65
return
dbl_nan;
66
67
if
(argc > 1)
68
return
dbl_inf;
69
70
// NEGATIVE test: successful exit status indicates a failure
71
return
0;
72
}
73
74
// foil optimizers
75
double
dbl_get_zero
()
76
{
77
static
double
value
= 0.0;
78
79
return
value
;
80
}
81
82
83
double
dbl_get_one
()
84
{
85
static
double
value
= 1.0;
86
87
return
value
;
88
}
dbl_zero
volatile double dbl_zero
Definition
18.numeric.special.float.cpp:73
value
T value(const T &val)
Definition
26.valarray.cassign.cpp:139
main
#define main
Definition
BAD_ALLOC_COPY_CTOR.cpp:32
dbl_get_one
double dbl_get_one()
Definition
NO_DBL_TRAPS.cpp:83
dbl_get_zero
double dbl_get_zero()
Definition
NO_DBL_TRAPS.cpp:75
nodbg.h
nodbg
void nodbg()
Definition
nodbg.h:52
Generated by
1.9.8