【发布时间】:2012-08-20 06:13:09
【问题描述】:
以下代码产生了所示的输出,我很困惑......我正在使用英特尔编译器版本 2013 beta update 2 /opt/intel/composer_xe_2013.0.030/bin/intel64/icpc:
// all good
int64_t fops_count1 = 719508467815;
long double fops_count2 = boost::static_cast<long double>(fops_count1);
printf("%" PRIu64 "\n", fops_count1); // OK outputs 719508467815
printf("%Le\n", fops_count2); // OK outputs 7.195085e+11
// bad! why this?
int64_t fops_count1 = 18446743496931269238;
long double fops_count2 = boost::static_cast<long double>(fops_count1);
printf("%" PRIu64 "\n", fops_count1); // OK outputs 18446743496931269238
printf("%Le\n", fops_count2); // FAIL outputs -5.767783e+11 <<<<<<<<<<<<<<<<< WHY?
【问题讨论】:
-
也许这个值对于长双倍来说也太大了?
-
这是什么
boost::static_cast?您不能使用关键字作为名称。 -
@H2CO3:它应该适合
long double就好了;但不在int64_t。 -
我假设这是针对 i386 或 x86_64 平台的,其中
long double具有 80 位精度。 (在许多平台上,大小各不相同。在某些平台上,long double不比double宽。为了完整起见,我提到这一点。)
标签: c++