about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--001help.cc28
1 files changed, 27 insertions, 1 deletions
diff --git a/001help.cc b/001help.cc
index 25dd27d5..a0241e95 100644
--- a/001help.cc
+++ b/001help.cc
@@ -113,7 +113,7 @@ void initialize_signal_handlers() {
   sigaction(SIGABRT, &action, NULL);  // assert() failure or integer overflow on linux (with -ftrapv)
   sigaction(SIGILL,  &action, NULL);  // integer overflow on OS X (with -ftrapv)
 }
-void dump_and_exit(int sig, siginfo_t* siginfo, unused void* dummy) {
+void dump_and_exit(int sig, unused siginfo_t* dummy1, unused void* dummy2) {
   switch (sig) {
     case SIGABRT:
       #ifndef __APPLE__
@@ -134,6 +134,32 @@ void dump_and_exit(int sig, siginfo_t* siginfo, unused void* dummy) {
 :(before "End Includes")
 #include <signal.h>
 
+//: For good measure we'll also enable SIGFPE.
+:(before "atexit(teardown)")
+feenableexcept(FE_OVERFLOW | FE_UNDERFLOW);
+//? assert(sizeof(int) == 4 && sizeof(float) == 4);
+//? //                          | exp   |  mantissa
+//? int smallest_subnormal = 0b00000000000000000000000000000001;
+//? float smallest_subnormal_f = *reinterpret_cast<int*>(&smallest_subnormal);
+//? cerr << "ε/2: " << smallest_subnormal_f/2 << " (underflow)\n";  // test SIGFPE
+:(before "End Includes")
+#include <fenv.h>
+:(code)
+#ifdef __APPLE__
+// Public domain polyfill for feenableexcept on OS X
+// http://www-personal.umich.edu/~williams/archive/computation/fe-handling-example.c
+inline int feenableexcept (unsigned int excepts) {
+  static fenv_t fenv;
+  unsigned int new_excepts = excepts & FE_ALL_EXCEPT;
+  unsigned int old_excepts;
+  if (fegetenv(&fenv)) return -1;
+  old_excepts = fenv.__control & FE_ALL_EXCEPT;
+  fenv.__control &= ~new_excepts;
+  fenv.__mxcsr   &= ~(new_excepts << 7);
+  return fesetenv(&fenv) ? -1 : old_excepts;
+}
+#endif
+
 //: 6. Map's operator[] being non-const is fucking evil.
 :(before "Globals")  // can't generate prototypes for these
 // from http://stackoverflow.com/questions/152643/idiomatic-c-for-reading-from-a-const-map
cc.html?h=hlt&id=90560d7194f3e451ddab9d4033c98d2e6aec977b'>90560d71 ^
4690ce81 ^
a654e4ec ^





672e3e50 ^

a654e4ec ^





672e3e50 ^

a654e4ec ^
672e3e50 ^

e07cbe5e ^
672e3e50 ^







4690ce81 ^
672e3e50 ^

4690ce81 ^
672e3e50 ^


4690ce81 ^


672e3e50 ^

4690ce81 ^
672e3e50 ^
65361948 ^
672e3e50 ^




4690ce81 ^
672e3e50 ^
65361948 ^
672e3e50 ^








4690ce81 ^
672e3e50 ^



4690ce81 ^
672e3e50 ^



4690ce81 ^
672e3e50 ^
4690ce81 ^
0e4a335e ^
672e3e50 ^

672e3e50 ^
d990e8f0 ^
4690ce81 ^
672e3e50 ^


65361948 ^

672e3e50 ^



4690ce81 ^

672e3e50 ^





dcc060c7 ^
672e3e50 ^
4690ce81 ^
672e3e50 ^

4690ce81 ^
dcc060c7 ^


672e3e50 ^

a654e4ec ^
4690ce81 ^
c5ffb6e1 ^
a654e4ec ^
4690ce81 ^
672e3e50 ^



4690ce81 ^
90560d71 ^








672e3e50 ^
298f8065 ^
672e3e50 ^


a654e4ec ^
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149