问题
In kernel : I am reading the time value as type extern s64 Latency;
In user space :
extern double latency;
//fp is reading the kernel value (i.e Latency)
fscanf (fp,"%lf", latency);
If I read s64 from kernel as double in the user space. Is there possibility of data loss ?? which data type should I use to get the complete value ??
回答1:
The short answer: Yes, there will definitely be data loss.
Think about it, both a signed 64 bit integer (s64
) and a double
has 64 bits of storage. But whereas the s64 only concerns itself with integers, a double
can also represent fractions. To do that it needs to utilize some of the bits for this information, so there is no way that it can also represent the full range of 64 bit integers.
You should use int64_t
from your toolchain's stdint.h
.
来源:https://stackoverflow.com/questions/23602887/conversion-error-in-c-program-from-s64-to-double