C++ (GCC) 中的四倍精度

Quadruple Precision in C++ (GCC)(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 中获得四精度浮点数的最佳方法是什么?现在,我可以对它们进行加减乘乘,但这对我来说毫无用处,考虑到我无法将它们转换为字符串或使用诸如 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) 中的四倍精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)