1 /* compile with something vaguely like...
3 gcc -o test-float -g -I ../includes prims/test-float.c prims/PrimArith_ap_o.o gmp/libgmp.a
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
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
22 const W_ ArrayOfData_info[4];
36 __decodeDouble( &m, &e, (StgDouble) 42 );
38 str = mpz_get_str( NULL, 10, &m );
40 printf("decoded 42: mant=%s, expon=%d (0x%x)\n", str, e,e);
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);
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);
53 /* test decoding (floats) */
55 for (i = 0; i < NF; i++) {
56 m = floatSignificandZh(float_val[i]);
57 e = floatExponentZh(float_val[i]);
59 f = encodeFloatZh(m, e);
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);