Skip to content

Instantly share code, notes, and snippets.

@boredzo
Created February 16, 2013 01:07
Show Gist options
  • Select an option

  • Save boredzo/4964945 to your computer and use it in GitHub Desktop.

Select an option

Save boredzo/4964945 to your computer and use it in GitHub Desktop.
Demonstrating properties of hexadecimal floating-point literals
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
double one = 0x100p-8;
printf("one: %f\n", one);
printf("0x100p-8 == 0x1p+0: %d\n", 0x100p-8 == 0x1p+0);
printf("0x100p-8 == 1.0: %d\n", 0x100p-8 == 1.0);
double n = 0xe5p-8, d = 0xffp-8;
printf("%f/%f = %f\n", n, d, n/d);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment