Okay, so I have already proved that the answer is -7.98392238758e-07 in python in about 20 seconds, but why can I not receive the same answer in C (I get zero).
double x = 1255060;
double y = -1571985829941;
double z = x/y;
printf("\nZ is %f", z);
Originally I thought that the issue was that I needed to use a long long instead of a double, but I still receive the same answer of 0.
I am very intrigued to know the solution to this annoying problem.
The example gives the expected answer (under clang):
Z is -0.000001
(which is the same as -7.98392238758e-07 rounded upwards)
You can use the %e
format placeholder in printf
to make it use scientific notation, in the same manner as what python uses.
double x = 1255060;
double y = -1571985829941;
double z = x/y;
printf("\nX is %f", x);
printf("\nY is %f", y);
printf("\nZ is %e", z);
Output
X is 1255060.000000
Y is -1571985829941.000000
Z is -7.983914e-07
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments