Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quadruple Precision in C++ (GCC)

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).

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.

like image 952
RétroX Avatar asked Mar 27 '11 18:03

RétroX


People also ask

Does GCC support long double?

GCC versions 4.0 and higher support 128-bit quad precision floating point values. The XL compilers now provide the -qfloat=gcclongdouble option to be compatible with GCC's representation of 128-bit quad precision floating point values.

What is Libquadmath?

libquadmath, the GCC Quad-Precision Math Library Application Programming Interface (API)


1 Answers

Apparently, this seems to have been an installation error on my part.

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;
}
like image 139
RétroX Avatar answered Oct 11 '22 21:10

RétroX