x86-64 长双精度

发布于 2024-08-31 21:17:33 字数 105 浏览 3 评论 0原文

Intel 64 位平台上 long double 的实际精度是多少? 是80位填充到128还是实际的128位?

如果是前者,除了gmp之外,还有其他选择来实现真正的128精度吗?

What is the actual precision of long double on Intel 64-bit platforms?
is it 80 bits padded to 128 or actual 128 bit?

if former, besides going gmp, is there another option to achieve true 128 precision?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一桥轻雨一伞开 2024-09-07 21:17:33

x86-64 精度与常规 x86 相同。 Extended double 是 80 位,使用 x87 ISA,添加了 6 个填充字节。没有 128 位 FP 硬件。

不过,四精度或扩展四精度的软件实现可能会受益于 x86-64 64x64=>128 整数乘法指​​令。

x86-64 precision is the same as regular x86. Extended double is 80 bits, using the x87 ISA, with 6 padding bytes added. There is no 128-bit FP hardware.

A software implementation of quad or extended quad precision might benefit from the x86-64 64x64 => 128 integer multiply instruction, though.

为你鎻心 2024-09-07 21:17:33

我建议使用 MPFR。它是一个更复杂的多精度浮点库,构建在 GMP 之上。

I would recommend using MPFR. It is a more sophisticated multiple-precision floating point library that is built on top of GMP.

允世 2024-09-07 21:17:33

很有可能两者都是 64 位(取决于编译器和操作系统),因为编译器发出标量 SSE2 而不是 x87 指令。

x86 不支持高于 80 位的精度,但如果您确实需要 64 位以上的 FP 算法,那么您很可能应该检查您的数字,而不是用暴力解决问题。

There is a good chance that it's 64 bit for both (depending on the compiler and OS), because the compiler is emitting scalar SSE2 instead of x87 instructions.

x86 doesn't support higher precision than 80 bits, but if you really need more than 64 bits for a FP algorithm most likely you should check your numerics instead of solving the problem with brute force.

幸福丶如此 2024-09-07 21:17:33

我推荐使用 MPFR 或 GMP 上的 Boost 包装器:

Boost 1.70:cpp_bin_float.

除了任意所需精度的任意类型外,还提供以下类型:

cpp_bin_float_single           (24 bits + mantissa = 32 bits)
cpp_bin_float_double           (53 bits + mantissa = 64 bits)
cpp_bin_float_double_extended  (64 bits + mantissa)
cpp_bin_float_quad             (113 bits + mantissa = 128 bits)
cpp_bin_float_oct              (237 bits) + mantissa = 256 bits)

Boost 提供几乎开箱即用的功能。编译后,所需要做的就是在 Visual Studio 项目中添加一个指向包含目录和库目录的指针。

使用 Visual Studio 2017 + Boost v1.70 进行测试。

请参阅编译 boost 的说明

I recommend the Boost wrappers over MPFR or GMP:

Boost 1.70: cpp_bin_float.

As well as arbitrary types to any desired precision, the following types are provided:

cpp_bin_float_single           (24 bits + mantissa = 32 bits)
cpp_bin_float_double           (53 bits + mantissa = 64 bits)
cpp_bin_float_double_extended  (64 bits + mantissa)
cpp_bin_float_quad             (113 bits + mantissa = 128 bits)
cpp_bin_float_oct              (237 bits) + mantissa = 256 bits)

Boost offers almost out-of-the-box functionality. Once compiled, all one needs to do is add a pointer within the Visual Studio project to the include and library directories.

Tested with Visual Studio 2017 + Boost v1.70.

See instructions to compile boost.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文