Quadruple Precision in C++ (GCC)(C++ (GCC) 中的四倍精度)
问题描述
就在最近,GCC 4.6.0 与 libquadmath 一起问世.不幸的是,GNU 支持 Fortran,但不支持 C 或 C++(包含的只是 .so).我还没有找到在 C++ 中使用这些新功能的方法,但是,GNU C 确实支持 __float128
类型以保证四倍精度浮点数.GNU C 似乎不支持 libquadmath 中的数学函数,例如 fabsq
(绝对值,q
是 quad 的后缀).
Just recently, the GCC 4.6.0 came out along with libquadmath. Unfortunately, GNU has supported Fortran, but not C or C++ (all that is included is a .so). I have not found a way to use these new features in C++, however, GNU C does support the __float128
type for guaranteed quadruple-precision floats. GNU C does not seem to support the math functions in libquadmath, such fabsq
(absolute value, q
being the suffix for quad).
有什么方法可以让这些函数在 C++ 中运行,或者是否有一些替代库可以用于带有 __float128
的数学函数?在 GCC 中获得四精度浮点数的最佳方法是什么?现在,我可以对它们进行加减乘乘,但这对我来说毫无用处,考虑到我无法将它们转换为字符串或使用诸如 truncq
和 fabsq<之类的函数/code> 创建我自己的字符串函数.
Is there any way to get these functions working in C++, or is there some alternative library that I could use for math functions with __float128
? What is the best method for getting quadruple-precision floats working in the GCC? Right now, I can add, subtract, and multiply them, but this is useless to me, considering how I have no way to convert them to strings or use functions such as truncq
and fabsq
to create my own string function.
推荐答案
显然,这似乎是我的安装错误.
Apparently, this seems to have been an installation error on my part.
虽然 GCC 的核心 C/C++ 部分包括 libquadmath.so,但 Fortran 版本提供了 libquadmath.a 和 quadmath.h,可以包含它们以访问这些函数.
While the core C/C++ portion of the GCC includes libquadmath.so, the Fortran version supplies libquadmath.a and quadmath.h, which can be included to access the functions.
#include <quadmath.h>
#include <iostream>
int main()
{
char* y = new char[1000];
quadmath_snprintf(y, 1000, "%Qf", 1.0q);
std::cout << y << std::endl;
return 0;
}
这篇关于C++ (GCC) 中的四倍精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ (GCC) 中的四倍精度


基础教程推荐
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 这个宏可以转换成函数吗? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01