简体   繁体   English

无符号long long int到long double

[英]Unsigned long long int to long double

In the C programming language I'm having trouble getting accurate values reported for long double variables. 在C编程语言中,我很难获得报告的长双精度变量的准确值。

In order to calculate accurate averages of two unsigned long long variables I feel as though I need to use long double over standard double because standard double only handles 52 significant bits while the unsigned long long are 64 bits. 为了计算两个无符号的long long变量的准确平均值,我觉得我需要在标准双精度上使用long double,因为标准双精度只能处理52个有效位,而unsigned long long是64位。

Here is an example of the problem I am experiencing: 这是我遇到的问题的一个示例:

unsigned long long int x = 0x00000000FE5F06AC;
unsigned long long int y = 0x000FFFFFFFFFFFFF;
long double z = (x+y)/2.0;
printf("z = %lf", z);

Such a sample of code will always print 0.0000 for z and I can't really understand why this is happening. 这样的代码示例将始终为z打印0.0000,而我真的无法理解为什么会这样。

Is there underflow occurring, or some type of error in how I am formatting this? 是否存在下溢,或者在格式化时出现某种类型的错误?

I see couple of errors: 我看到几个错误:

  1. You have a G in the first number. 您的第一个数字中有一个G Hopefully that's just a typo or error in transcription. 希望这只是打字错误或抄写错误。

  2. The format for long double is %Lf , not %lf . long double的格式为%Lf ,而不是%lf

Here's a link to a working example: http://ideone.com/jWRHit 这是一个工作示例的链接: http : //ideone.com/jWRHit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM