C++ 什么比双倍大?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/257353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 14:06:08  来源:igfitidea点击:

What's bigger than a double?

c++typesvariables

提问by baash05

Is there a native c++ variable type that's "bigger" than a double?
float is 7
double is 15 (of course depending on the compiler)
Is there anything bigger that's native, or even non-native?

是否有比双精度值“更大”的原生 C++ 变量类型?
float is 7
double is 15 (当然取决于编译器)
有没有更大的本地甚至非本地的东西?

回答by Chris Jester-Young

C++ has long double, but there is no guarantee that it's any more precise than a plain double. On an x86 platform, usually doubleis 64 bits, and long doubleis either 64 or 80 bits (which gives you 19 significant figures, if I remember right).

C++ 有long double,但不能保证它比普通的double. 在 x86 平台上,通常double是 64 位,long double可以是 64 位或 80 位(如果我没记错的话,它会给你 19 个有效数字)。

Your mileage may vary, especially if you're not on x86.

您的里程可能会有所不同,特别是如果您不在 x86 上。

回答by ysth

A long double typically only uses 10 bytes, but due to alignment may actually take up 12 or 16 (depending on the compiler and options) bytes in a structure.

long double 通常只使用 10 个字节,但由于对齐,实际上可能会在结构中占用 12 或 16 个(取决于编译器和选项)字节。

The 10 byte long double provides a 64-bit mantissa; this is very convenient for when you want to store 64 bit integers in floating point without loss of precision.

10 字节长的 double 提供 64 位尾数;当您想在不损失精度的情况下以浮点形式存储 64 位整数时,这非常方便。

回答by CesarB

You can use GNU MP. Its floating-point functionshave unlimited mantissa and 32-bit or 64-bit (depending on the native word size) exponent. It also comes with a C++ wrapper.

您可以使用GNU MP。它的浮点函数具有无限的尾数和 32 位或 64 位(取决于本机字大小)指数。它还带有一个C++ 包装器

回答by gilm

C++ has long double, but it's still quite limited. For good time try GNU's gmp library. You can set up numbers as big as you like, and it's quite fun and hackishly when you use gmp_add instead of a normal +. I'm sure there's a C++ wrapper somewhere.

C++ 有很长的 double,但它仍然非常有限。不妨试试 GNU 的 gmp 库。您可以设置任意大的数字,当您使用 gmp_add 而不是普通的 + 时,这会非常有趣而且很笨拙。我确定某处有一个 C++ 包装器。

回答by Dana the Sane

There are also some various bigfloat/bigint libraries around for C++ that allow arbitrary precision math. There's thislibrary on Microsoft Codeplex, but Googling will find you plenty of others.

还有一些用于 C++ 的各种 bigfloat/bigint 库,允许任意精度数学。Microsoft Codeplex 上有这个库,但谷歌搜索会发现很多其他库。

回答by Jake

long double, but it generally is still 15 places of precision too.

long double,但通常也有 15 位精度。

回答by Arron Brooks

long long double only some cpus will allow you to use it though...

long long double 只有一些 cpu 允许您使用它...

回答by Arron Brooks