blob: e6a986d3f552cc303e05e209f59ae5458c8306f7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
#include <stdio.h>
#include <string.h> // Added for strlen
int main() {
double x = 1.0 / 3.0;
printf("x = %.15g\n", x);
printf("(long)x = %ld\n", (long)x);
printf("x == (long)x: %s\n", x == (long)x ? "true" : "false");
char buffer[128];
if (x == (long)x) {
snprintf(buffer, sizeof(buffer), "%ld", (long)x);
printf("Using integer format: '%s'\n", buffer);
} else {
snprintf(buffer, sizeof(buffer), "%.15g", x);
printf("Using float format: '%s'\n", buffer);
}
return 0;
}
|