[ create a new paste ] login | about

Link: http://codepad.org/03hAQZwq    [ raw code | output | fork ]

C, pasted on Oct 23:
#include <stdio.h>

int main()
{
    printf("Mapping 100 numbers between 0 and 1 ");
    printf("to their hexadecimal exponential form (HEF).\n");
    printf("Most of them do not equal their HEFs. That means ");
    printf("that their representations as floats ");
    printf("differ from their actual values.\n");
    double f = 0.01;
    int i;
    for (i = 0; i < 100; i++) {
        printf("%1.2f -> %a\n",f*i,f*i);
    }
    printf("Printing 128 'float-compatible' numbers ");
    printf("together with their HEFs for comparison.\n");
    f = 0x1p-7; // ==0.0071825
    for (i = 0; i < 0x80; i++) {
        printf("%1.7f -> %a\n",f*i,f*i);
    }
    return 0;
}


Output:
Mapping 100 numbers between 0 and 1 to their hexadecimal exponential form (HEF).
Most of them do not equal their HEFs. That means that their representations as floats differ from their actual values.
0.00 -> 0x0p+0
0.01 -> 0x1.47ae147ae147bp-7
0.02 -> 0x1.47ae147ae147bp-6
0.03 -> 0x1.eb851eb851eb8p-6
0.04 -> 0x1.47ae147ae147bp-5
0.05 -> 0x1.999999999999ap-5
0.06 -> 0x1.eb851eb851eb8p-5
0.07 -> 0x1.1eb851eb851ecp-4
0.08 -> 0x1.47ae147ae147bp-4
0.09 -> 0x1.70a3d70a3d70ap-4
0.10 -> 0x1.999999999999ap-4
0.11 -> 0x1.c28f5c28f5c29p-4
0.12 -> 0x1.eb851eb851eb8p-4
0.13 -> 0x1.0a3d70a3d70a4p-3
0.14 -> 0x1.1eb851eb851ecp-3
0.15 -> 0x1.3333333333333p-3
0.16 -> 0x1.47ae147ae147bp-3
0.17 -> 0x1.5c28f5c28f5c3p-3
0.18 -> 0x1.70a3d70a3d70ap-3
0.19 -> 0x1.851eb851eb852p-3
0.20 -> 0x1.999999999999ap-3
0.21 -> 0x1.ae147ae147ae1p-3
0.22 -> 0x1.c28f5c28f5c29p-3
0.23 -> 0x1.d70a3d70a3d71p-3
0.24 -> 0x1.eb851eb851eb8p-3
0.25 -> 0x1p-2
0.26 -> 0x1.0a3d70a3d70a4p-2
0.27 -> 0x1.147ae147ae148p-2
0.28 -> 0x1.1eb851eb851ecp-2
0.29 -> 0x1.28f5c28f5c28fp-2
0.30 -> 0x1.3333333333333p-2
0.31 -> 0x1.3d70a3d70a3d7p-2
0.32 -> 0x1.47ae147ae147bp-2
0.33 -> 0x1.51eb851eb851fp-2
0.34 -> 0x1.5c28f5c28f5c3p-2
0.35 -> 0x1.6666666666667p-2
0.36 -> 0x1.70a3d70a3d70ap-2
0.37 -> 0x1.7ae147ae147aep-2
0.38 -> 0x1.851eb851eb852p-2
0.39 -> 0x1.8f5c28f5c28f6p-2
0.40 -> 0x1.999999999999ap-2
0.41 -> 0x1.a3d70a3d70a3ep-2
0.42 -> 0x1.ae147ae147ae1p-2
0.43 -> 0x1.b851eb851eb85p-2
0.44 -> 0x1.c28f5c28f5c29p-2
0.45 -> 0x1.ccccccccccccdp-2
0.46 -> 0x1.d70a3d70a3d71p-2
0.47 -> 0x1.e147ae147ae15p-2
0.48 -> 0x1.eb851eb851eb8p-2
0.49 -> 0x1.f5c28f5c28f5cp-2
0.50 -> 0x1p-1
0.51 -> 0x1.051eb851eb852p-1
0.52 -> 0x1.0a3d70a3d70a4p-1
0.53 -> 0x1.0f5c28f5c28f6p-1
0.54 -> 0x1.147ae147ae148p-1
0.55 -> 0x1.199999999999ap-1
0.56 -> 0x1.1eb851eb851ecp-1
0.57 -> 0x1.23d70a3d70a3ep-1
0.58 -> 0x1.28f5c28f5c28fp-1
0.59 -> 0x1.2e147ae147ae1p-1
0.60 -> 0x1.3333333333333p-1
0.61 -> 0x1.3851eb851eb85p-1
0.62 -> 0x1.3d70a3d70a3d7p-1
0.63 -> 0x1.428f5c28f5c29p-1
0.64 -> 0x1.47ae147ae147bp-1
0.65 -> 0x1.4cccccccccccdp-1
0.66 -> 0x1.51eb851eb851fp-1
0.67 -> 0x1.570a3d70a3d71p-1
0.68 -> 0x1.5c28f5c28f5c3p-1
0.69 -> 0x1.6147ae147ae15p-1
0.70 -> 0x1.6666666666667p-1
0.71 -> 0x1.6b851eb851eb8p-1
0.72 -> 0x1.70a3d70a3d70ap-1
0.73 -> 0x1.75c28f5c28f5cp-1
0.74 -> 0x1.7ae147ae147aep-1
0.75 -> 0x1.8p-1
0.76 -> 0x1.851eb851eb852p-1
0.77 -> 0x1.8a3d70a3d70a4p-1
0.78 -> 0x1.8f5c28f5c28f6p-1
0.79 -> 0x1.947ae147ae148p-1
0.80 -> 0x1.999999999999ap-1
0.81 -> 0x1.9eb851eb851ecp-1
0.82 -> 0x1.a3d70a3d70a3ep-1
0.83 -> 0x1.a8f5c28f5c29p-1
0.84 -> 0x1.ae147ae147ae1p-1
0.85 -> 0x1.b333333333333p-1
0.86 -> 0x1.b851eb851eb85p-1
0.87 -> 0x1.bd70a3d70a3d7p-1
0.88 -> 0x1.c28f5c28f5c29p-1
0.89 -> 0x1.c7ae147ae147bp-1
0.90 -> 0x1.ccccccccccccdp-1
0.91 -> 0x1.d1eb851eb851fp-1
0.92 -> 0x1.d70a3d70a3d71p-1
0.93 -> 0x1.dc28f5c28f5c3p-1
0.94 -> 0x1.e147ae147ae15p-1
0.95 -> 0x1.e666666666667p-1
0.96 -> 0x1.eb851eb851eb8p-1
0.97 -> 0x1.f0a3d70a3d70ap-1
0.98 -> 0x1.f5c28f5c28f5cp-1
0.99 -> 0x1.fae147ae147aep-1
Printing 128 'float-compatible' numbers together with their HEFs for comparison.
0.0000000 -> 0x0p+0
0.0078125 -> 0x1p-7
0.0156250 -> 0x1p-6
0.0234375 -> 0x1.8p-6
0.0312500 -> 0x1p-5
0.0390625 -> 0x1.4p-5
0.0468750 -> 0x1.8p-5
0.0546875 -> 0x1.cp-5
0.0625000 -> 0x1p-4
0.0703125 -> 0x1.2p-4
0.0781250 -> 0x1.4p-4
0.0859375 -> 0x1.6p-4
0.0937500 -> 0x1.8p-4
0.1015625 -> 0x1.ap-4
0.1093750 -> 0x1.cp-4
0.1171875 -> 0x1.ep-4
0.1250000 -> 0x1p-3
0.1328125 -> 0x1.1p-3
0.1406250 -> 0x1.2p-3
0.1484375 -> 0x1.3p-3
0.1562500 -> 0x1.4p-3
0.1640625 -> 0x1.5p-3
0.1718750 -> 0x1.6p-3
0.1796875 -> 0x1.7p-3
0.1875000 -> 0x1.8p-3
0.1953125 -> 0x1.9p-3
0.2031250 -> 0x1.ap-3
0.2109375 -> 0x1.bp-3
0.2187500 -> 0x1.cp-3
0.2265625 -> 0x1.dp-3
0.2343750 -> 0x1.ep-3
0.2421875 -> 0x1.fp-3
0.2500000 -> 0x1p-2
0.2578125 -> 0x1.08p-2
0.2656250 -> 0x1.1p-2
0.2734375 -> 0x1.18p-2
0.2812500 -> 0x1.2p-2
0.2890625 -> 0x1.28p-2
0.2968750 -> 0x1.3p-2
0.3046875 -> 0x1.38p-2
0.3125000 -> 0x1.4p-2
0.3203125 -> 0x1.48p-2
0.3281250 -> 0x1.5p-2
0.3359375 -> 0x1.58p-2
0.3437500 -> 0x1.6p-2
0.3515625 -> 0x1.68p-2
0.3593750 -> 0x1.7p-2
0.3671875 -> 0x1.78p-2
0.3750000 -> 0x1.8p-2
0.3828125 -> 0x1.88p-2
0.3906250 -> 0x1.9p-2
0.3984375 -> 0x1.98p-2
0.4062500 -> 0x1.ap-2
0.4140625 -> 0x1.a8p-2
0.4218750 -> 0x1.bp-2
0.4296875 -> 0x1.b8p-2
0.4375000 -> 0x1.cp-2
0.4453125 -> 0x1.c8p-2
0.4531250 -> 0x1.dp-2
0.4609375 -> 0x1.d8p-2
0.4687500 -> 0x1.ep-2
0.4765625 -> 0x1.e8p-2
0.4843750 -> 0x1.fp-2
0.4921875 -> 0x1.f8p-2
0.5000000 -> 0x1p-1
0.5078125 -> 0x1.04p-1
0.5156250 -> 0x1.08p-1
0.5234375 -> 0x1.0cp-1
0.5312500 -> 0x1.1p-1
0.5390625 -> 0x1.14p-1
0.5468750 -> 0x1.18p-1
0.5546875 -> 0x1.1cp-1
0.5625000 -> 0x1.2p-1
0.5703125 -> 0x1.24p-1
0.5781250 -> 0x1.28p-1
0.5859375 -> 0x1.2cp-1
0.5937500 -> 0x1.3p-1
0.6015625 -> 0x1.34p-1
0.6093750 -> 0x1.38p-1
0.6171875 -> 0x1.3cp-1
0.6250000 -> 0x1.4p-1
0.6328125 -> 0x1.44p-1
0.6406250 -> 0x1.48p-1
0.6484375 -> 0x1.4cp-1
0.6562500 -> 0x1.5p-1
0.6640625 -> 0x1.54p-1
0.6718750 -> 0x1.58p-1
0.6796875 -> 0x1.5cp-1
0.6875000 -> 0x1.6p-1
0.6953125 -> 0x1.64p-1
0.7031250 -> 0x1.68p-1
0.7109375 -> 0x1.6cp-1
0.7187500 -> 0x1.7p-1
0.7265625 -> 0x1.74p-1
0.7343750 -> 0x1.78p-1
0.7421875 -> 0x1.7cp-1
0.7500000 -> 0x1.8p-1
0.7578125 -> 0x1.84p-1
0.7656250 -> 0x1.88p-1
0.7734375 -> 0x1.8cp-1
0.7812500 -> 0x1.9p-1
0.7890625 -> 0x1.94p-1
0.7968750 -> 0x1.98p-1
0.8046875 -> 0x1.9cp-1
0.8125000 -> 0x1.ap-1
0.8203125 -> 0x1.a4p-1
0.8281250 -> 0x1.a8p-1
0.8359375 -> 0x1.acp-1
0.8437500 -> 0x1.bp-1
0.8515625 -> 0x1.b4p-1
0.8593750 -> 0x1.b8p-1
0.8671875 -> 0x1.bcp-1
0.8750000 -> 0x1.cp-1
0.8828125 -> 0x1.c4p-1
0.8906250 -> 0x1.c8p-1
0.8984375 -> 0x1.ccp-1
0.9062500 -> 0x1.dp-1
0.9140625 -> 0x1.d4p-1
0.9218750 -> 0x1.d8p-1
0.9296875 -> 0x1.dcp-1
0.9375000 -> 0x1.ep-1
0.9453125 -> 0x1.e4p-1
0.9531250 -> 0x1.e8p-1
0.9609375 -> 0x1.ecp-1
0.9687500 -> 0x1.fp-1
0.9765625 -> 0x1.f4p-1
0.9843750 -> 0x1.f8p-1
0.9921875 -> 0x1.fcp-1


Create a new paste based on this one


Comments: