My idea is, if user enters t = 2.5, then I extract 2 and 0.5 separately in 2 different variables. But I am unable to do that.
Here is the code:
$ export LT_LEAK_START=1.5
$ echo $LT_LEAK_START
1.5
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
double d;
time_t t;
long nsec;
d=strtod(getenv("LT_LEAK_START"), NULL);
t=(time_t)d;
nsec=d-(double)((time_t)d); // Extract fractional part as time_t always whole no.
printf("d = %lf\n",d);
printf("t = %u, nsec = %f\n",d,nsec);
}
Output is:
# ./a.out
d = 1.500000
t = 0, nsec = 0.000000
Your output is broken. You’re actually writing the value of
dtwice in the following code:If you’d written this:
Then you’d have the output:
It’s now clearer that you have a rounding error. In this case, you cast away all the decimal places by assigning 0.5 to
nsec, along. Makensecafloatinstead.