C ++中long double的精度是多少? [英] What is the precision of long double in C++?

查看:502
本文介绍了C ++中long double的精度是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道如何在特定平台上找出 long double 的精确度?我似乎失去了精确度后17个十进制数字,这是相同的,当我只是使用 double 。我希望得到更多,因为 double 在我的平台上用8个字节表示,而 long double 是12字节

Does anyone know how to find out the precision of long double on a specific platform? I appear to be losing precision after 17 decimal digits, which is the same as when I just use double. I would expect to get more, since double is represented with 8 bytes on my platform, while long double is 12 bytes.

在您提出之前,这是项目欧拉,所以是的我需要超过17个数字。 :)

Before you ask, this is for Project Euler, so yes I do need more than 17 digits. :)

编辑:感谢您的快速回复。我刚刚确认,我只能通过使用 long double 在我的系统上获得18个十进制数字。

Thanks for the quick replies. I just confirmed that I can only get 18 decimal digits by using long double on my system.

推荐答案

您可以使用 std :: numeric_limits 找到:

#include <iostream>     // std::cout
#include <limits>       // std::numeric_limits
int main(){
    std::cout << std::numeric_limits<long double>::digits10 << std::endl;
}

这篇关于C ++中long double的精度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆