Skip to content

Instantly share code, notes, and snippets.

@cloudwu
Created October 10, 2016 05:25
Show Gist options
  • Save cloudwu/b268f7362ec29790c0f92a0917fa0e69 to your computer and use it in GitHub Desktop.
Save cloudwu/b268f7362ec29790c0f92a0917fa0e69 to your computer and use it in GitHub Desktop.
float
#include <stdio.h>
int
main() {
double f = 1.0/3.0;
double f2;
char tmp[100];
sprintf(tmp, "%lf", f);
sscanf(tmp, "%lf", &f2);
printf("f = %lf f2 = %lf , %d\n", f, f2, (f2 == f)); // should be 0 (false)
sprintf(tmp, "%la", f);
sscanf(tmp, "%la", &f2);
printf("f = %la f2 = %la , %d\n", f, f2, (f2 == f)); // should be 1 (true)
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment