Search code examples
c++gccfloating-pointquadruple-precision

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.


Solution

  • 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;
    }