Compiling C ++ code using __float128

I am trying to use __float128in my C ++ program.

However, I am having trouble compiling it.

Here is a simple C ++ code (test.cc):

#include <iostream>
#include <quadmath.h>

using namespace std;

int main(){
  __float128 r=0.0q;
  __float128 exp_d = expq(12.45q);

  cout << "r=" << (double)r << endl;
  cout << "exp_d=" << (double)exp_d << endl;
}

And I will compile this code with

g++ test.cc -lquadmath -std=c++11

which comes with the following error

error:unable to find numeric literal operator 'operateor"" q'

How can i fix this?

+4
source share
2 answers

Gcc-5 prints this useful additional note:

note: use -std=gnu++11 or -fext-numeric-literals to enable more built-in suffixes
+7
source

As I noted earlier, I think your problem is that handling C ++ 11 literal text prevents the GCC-specific CCC extension that handles the suffix q. Try providing the C ++ 11 operator - as shown below:

#include <iostream>
extern "C"
{
    #include <quadmath.h>
}

__float128 operator ""q(const char* p)
{
    return strtoflt128(p, NULL);
}

int main()
{
    __float128 x = expq(282.49q);
    char buffer[128];
    quadmath_snprintf(buffer, sizeof buffer, "%.36Qg\n", x);
    std::cout << buffer << '\n';
}
+1
source

All Articles