/* Test code for floating point parsing You will want to test more numbers - this is by no means exhaustive */ #include #include /* Prototype for sprint_double */ void sprint_double(char* outbuf, uint64_t f); int main() { char buf[256]; uint64_t num; double a; //hex num = 0xffff0000; sprint_double(buf,num << 32); printf("%s should be: -NaN\n",buf); num = 0x7ff00000; sprint_double(buf,num << 32); printf("%s should be: infinity\n",buf); num = 0x00010000; sprint_double(buf,num << 32); printf("%s should be: denorm\n",buf); num = 0x80000000; sprint_double(buf,num << 32); printf("%s should be: -0\n",buf); num = 0x34554342; sprint_double(buf,num << 32); printf("%s should be: 1.0101010000110100001E-10111010\n",buf); //These weird casts are needed to pass in doubles a = 35.0; sprint_double(buf,*(uint64_t*)(&a)); printf("%s should be: 100011\n",buf); a = 64.0; sprint_double(buf,*(uint64_t*)(&a)); printf("%s should be: 1.0E110\n",buf); a = -96.0; sprint_double(buf,*(uint64_t*)(&a)); printf("%s should be: -1.1E110\n",buf); a = -0.375; sprint_double(buf,*(uint64_t*)(&a)); printf("%s should be: -0.011\n",buf); a = 2.75; sprint_double(buf,*(uint64_t*)(&a)); printf("%s should be: 10.11\n",buf); a = 0.0625; sprint_double(buf,*(uint64_t*)(&a)); printf("%s should be: 1.0E-100\n",buf); return 0; }