[project @ 1998-11-26 09:17:22 by sof]
[ghc-hetmet.git] / ghc / runtime / prims / test-float.c
1 /* compile with something vaguely like...
2
3 gcc -o test-float -g -I ../includes prims/test-float.c prims/PrimArith_ap_o.o gmp/libgmp.a
4
5 */
6 #include "rtsdefs.h"
7 #include <errno.h>
8
9 StgFloat float_val[] = {
10   0.0, -1.0, 1.0, 1.2, -1.5, 1.5, -1.5e19, -1.5e-19, 1.5e19, 1.5e-19, 1.5e30, 1.5e-30,
11   3.14159265, -3.14159265, 42, -42, 42.2, -42.2
12 };
13 #define NF 18
14
15 StgDouble double_val[] = {
16   0.0, -1.0, 1.0, 1.2, -1.5, 1.5, -1.5e19, -1.5e-19, 1.5e19, 1.5e-19, 1.5e30, 1.5e-30,
17   3.14159265, -3.14159265, 42, -42, 42.2, -42.2
18 };
19 #define ND 18
20
21 P_ Hp_SAVE;
22 const W_ ArrayOfData_info[4];
23
24 void
25 main ()
26 {
27     MP_INT m;
28     I_ e;
29     StgFloat f;
30     StgDouble d;
31     int i;
32     char *str;
33
34     mpz_init ( &m );
35
36     __decodeDouble( &m, &e, (StgDouble) 42 );
37
38     str = mpz_get_str( NULL, 10, &m );
39
40     printf("decoded 42: mant=%s, expon=%d (0x%x)\n", str, e,e);
41
42     /* test decoding (doubles) */
43     for (i = 0; i < ND; i++) {
44         __decodeDouble( &m, &e, double_val[i]);
45         str = mpz_get_str( NULL, 10, &m );
46         d = __encodeDouble( &m, e);
47
48         printf("decodedD: d=%g, mant=%s, expon=%d (0x%x)\n",
49                 double_val[i], str, e,e);
50         printf("encodedD: d=%g\n\n", d);
51     }
52
53     /* test decoding (floats) */
54 #if 0
55     for (i = 0; i < NF; i++) {
56         m = floatSignificandZh(float_val[i]);
57         e = floatExponentZh(float_val[i]);
58
59         f = encodeFloatZh(m, e);
60
61         printf("decodedF: f=%g, mant=%d (0x%x), expon=%d (0x%x)\n",
62                 float_val[i], m,m, e,e);
63         printf("encodedF: f=%g\n\n", f);
64     }
65 #endif
66 }