|
|
1.1 root 1: /* float1.c - test of floating point */
2:
3: #include <stdio.h>
4:
5: #if 0
6: #define FORCE(var,val) {*(int *)(&var) = val;dumpl("FORCE ",var);}
7: #else
8: #define FORCE(var,val)
9: #endif
10:
11: main()
12: {
13: float x = 1.0, y = 2.0, z;
14:
15: xpr(&x);
16: dumpl("x = ", x);
17: FORCE(x, 0x3F800000);
18: xpr(&y);
19: dumpl("y = ", y);
20: FORCE(y, 0x40000000);
21: fflush(stdout);
22:
23: z = x + y;
24: xpr(&z);
25: dumpl("z = ", z);
26: FORCE(z, 0x40400000);
27: fflush(stdout);
28:
29: printf("%f + %f = %f\n", x, y, z);
30: printf("that was formatted %%f output\n");
31: fflush(stdout);
32: }
33:
34: /* Dump a double as 16 hex digits */
35: dumpl(name,flo,fhi)
36: char * name;
37: int flo, fhi;
38: {
39: int exponent;
40: int schi;
41: char sgn;
42:
43: printf("%s%08x,%08x ", name, fhi, flo);
44:
45: sgn = (fhi & 0x80000000) ? '-' : '+';
46: exponent = (fhi >> 20) & 0x7FF;
47: exponent -= 1023;
48: schi = fhi & 0xFFFFF;
49:
50: printf("%c1.%05x,%08xx2**%d\n", sgn, schi, flo, exponent);
51: }
52:
53: /* dump a float as 8 hex digits - called with address of the float */
54: xpr(fa)
55: int * fa;
56: {
57: printf("%08x ", *fa);
58: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.