C++ (GCC) 中的四倍精度 [英] Quadruple Precision in C++ (GCC)

查看:25
本文介绍了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 中获得四精度浮点数的最佳方法是什么?现在,我可以对它们进行加减乘乘,但这对我来说毫无用处,考虑到我无法将它们转换为字符串或使用诸如 truncqfabsq<之类的函数/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) 中的四倍精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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