1
2 #include <stdio.h>
3 #include <math.h>
4
5 double d;
6 int i;
7
8 extern void do_fxam ( void );
9
10 asm(
11 "\n"
12 "do_fxam:\n"
13 "\txorl %eax,%eax\n"
14 "\tfld d\n"
15 "\tfxam\n"
16 "\tfnstsw %ax\n"
17 "\tffree %st(0)\n"
18 "\tmovl %eax, i\n"
19 "\tret\n"
20 );
21
22
inf(void)23 double inf ( void ) { return 1.0 / 0.0; }
nAn(void)24 double nAn ( void ) { return 0.0 / 0.0; }
den(void)25 double den ( void ) { return 9.1e-220 / 1e100; }
26
27 /* Try positive and negative variants of: zero, infinity,
28 nAn, and denorm */
29
main(void)30 int main ( void )
31 {
32 d = 0.0; do_fxam(); printf("0x%4x: %f\n", i, d );
33 d = -0.0; do_fxam(); printf("0x%4x: %f\n", i, d );
34
35 d = inf(); do_fxam(); printf("0x%4x: %f\n", i, d );
36 d = -inf(); do_fxam(); printf("0x%4x: %f\n", i, d );
37
38 d = nAn(); do_fxam(); printf("0x%4x: %f\n", i, d );
39 d = -nAn(); do_fxam(); printf("0x%4x: %f\n", i, d );
40
41 d = den(); do_fxam(); printf("0x%4x: %f\n", i, d );
42 d = -den(); do_fxam(); printf("0x%4x: %f\n", i, d );
43 return 0;
44 }
45