2

I have a problem using cout and __float128.

Code is:

__float128 su1 = 0.33333333333333333q;         
cout << "1 / 3 = " << su1 << endl;

And error from g++ (GCC) 9.3.0 is:

g++ -std=gnu++17 -Wall -g -c -o third.o third.cc
third.cc: In function ‘int main()’:
third.cc:41:55: error: ambiguous overload for ‘operator<<’ (operand types are ‘std::basic_ostream<char>’ and ‘__float128’)
   41 |     cout << "1 / 3 = " << su1 << endl;
      |     ~~~~~~~~~~~~~~~~~~ ^~ ~~~~~
      |           |            |
      |           |             __float128
      |           std::basic_ostream<char>
In file included from /lib/gcc/x86_64-pc-cygwin/9.3.0/include/c++/iostream:39,
                 from third.cc:9:

Any ideas about the error?

  • 1
    The error seems to be simple, there exists no specialization of `<<` for `__float128`. Maybe one of these questions helps you: https://stackoverflow.com/questions/23654693/print-float128-without-using-quadmath-snprintf https://stackoverflow.com/questions/25114597/how-to-print-int128-in-g – Lukas-T Sep 25 '20 at 05:18
  • Thanks @churill . Those answers are helpful. – Chris Pollitt Sep 25 '20 at 05:30
  • Actually using the boost library was the best answer for me: `#include #include using namespace boost::multiprecision; float128 su1= 0.33333333333333333q;` – Chris Pollitt Sep 25 '20 at 06:54

0 Answers0