conversion error in c program from s64 to double?

旧时模样 提交于 2019-12-11 21:25:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!