2 problems:
sscanf_s(str, "%lf", &n);
expects a char *
, not a char **
. Enable all compiler warnings to see such problems and be sure to cut/paste problems correctly.
const char *str[] = {"37107287533902102798797998220837590246510135740250"};
Did you mean the following?
const char *str = {"37107287533902102798797998220837590246510135740250"};
A double
usually can exactly encode about 264 different values as a double
is often a 64-bit piece of data.
37107287533902 102798797998220837590246510135740250 is not one of them.
Output like the following is reasonable:
37107287533902 1043110257403....
37107287533902 104311025740304689820495323650000000.0 is the closest representable double
.
37107287533902 099118728881769862191964827320000000.0 would have been the next best choice.
Notice in this range, exact double
are 2112 apart (about 5.2*1033). Such is the binary nature of most double
encodings.