summaryrefslogtreecommitdiff
path: root/docs/probe_math_exception.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-02-11 17:37:21 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-02-11 17:37:21 +0000
commit5d53cce4c05d1f4f730cce080233dc959f773059 (patch)
tree1946111a30890c20efd571d5f9228c0f1fc55158 /docs/probe_math_exception.c
parenteb856014a03f49e132d852d6f1627db64d3abd7a (diff)
docs/probe_math_exception.c:
update example libc/sysdeps/linux/i386/bits/mathinline.h: improve __finite() macro, add __finitef macro (why they aren't always macros? why aren't they arch independent?) libm/math_private.h: much better comments on math_opt_barrier() and math_force_eval() libm/s_finite[f].c: improve out-of-line __finite[f]() too (one byte less, yay...)
Diffstat (limited to 'docs/probe_math_exception.c')
-rw-r--r--docs/probe_math_exception.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/docs/probe_math_exception.c b/docs/probe_math_exception.c
index dbeccc5cc..dbc9020d4 100644
--- a/docs/probe_math_exception.c
+++ b/docs/probe_math_exception.c
@@ -5,20 +5,40 @@
#define _ISOC99_SOURCE 1
#define _GNU_SOURCE 1
+#include <stdint.h>
#include <math.h>
#include <fenv.h>
#include <stdio.h>
int main(int argc, char **argv)
{
- float infF = HUGE_VALF * 2;
+ float largest, small, t, inf_float;
+
+ largest = small = 1;
+ while (1) {
+ t = largest + small;
+ /* optimizations may make plain "t == largest" unreliable */
+ if (memcmp(&t, &largest, sizeof(float)) == 0)
+ break;
+ if (isfinite(t)) {
+ largest = t;
+ small *= 2;
+ continue;
+ }
+ small /= 2;
+ }
+ inf_float = largest + largest;
+ //printf("%.40g ", largest);
+ //printf("[%llx]\n", (long long) (*(uint32_t *)&largest));
feclearexcept(FE_ALL_EXCEPT);
-// printf("%.40e\n", 1.0 / 0.0); // FE_DIVBYZERO
-// printf("%.40e\n", nextafterf(HUGE_VALF, infF)); // no exceptions in glibc 2.4
+ //t = 1.0 / 0.0; // simple test: FE_DIVBYZERO
+ //t = nextafterf(largest, 1); // glibc 2.8: no math exceptions raised
+ //t = nextafterf(largest, largest); // glibc 2.8: no math exceptions raised
+ //t = nextafterf(largest, inf_float); // glibc 2.8: FE_INEXACT FE_OVERFLOW
-#define PREX(ex) do { if (fetestexcept(ex)) printf(#ex); } while(0)
+#define PREX(ex) do { if (fetestexcept(ex)) printf(#ex " "); } while(0)
#ifdef FE_INEXACT
PREX(FE_INEXACT);
#endif
@@ -36,6 +56,9 @@ int main(int argc, char **argv)
#endif
if (fetestexcept(FE_ALL_EXCEPT))
printf("\n");
- printf("done\n");
+ else
+ printf("no math exceptions raised\n");
+
+ printf("%.40g\n", t);
return 0;
}