![]() |
Home | Libraries | People | FAQ | More |
Since few compilers implement a true 128-bit floating-point, and language features
like the suffix Q (which may need an option -fext-numeric-literals
to enable), and C++ Standard library functions are as-yet missing or incomplete
in C++11, this Boost.Math implementation wraps __float128
provided by the GCC compiler GCC
floating-point types or the _Quad
type provided by the Intel compiler.
This is provided to in order to demonstrate, and users to evaluate, the feasibility and benefits of higher-precision floating-point, especially to allow use of the full <cmath> and Boost.Math library of functions and distributions at high precision.
(It is also possible to use Boost.Math with Boost.Multiprecision decimal and binary, but since these are entirely software solutions, allowing much higher precision or arbitrary precision, they are likely to be slower).
We also provide (we believe full) support for <limits>, <cmath>, I/O stream operations in <iostream>, and <complex>.
As a prototype for a future C++ standard, we place all these in namespace std.
This contravenes the existing C++ standard of course, so selecting any compiler
that promises to check conformance will fail.
![]() |
Tip |
|---|---|
For GCC, compile with |
The __float128 type is provided
by the libquadmath
library on GCC or by Intel's FORTRAN library with Intel C++. THey also
provide a full set of <cmath> functions in namespace
std.
Example of using GCC Quad-Precision Math Library quadmath __float128
type, taking a square root with sqrtq, and output using quadmath_snprintf.
From GCC Quad-Precision Math Library, 3.2 quadmath_snprintf, Convert to string (pages 9 and 10).
Requires GCC linker option -lquadmath.
If this linker option is missing then you will get errors like:
/Cpp/float128/quadmath_snprintf/quadmath_snprintf.c:44: undefined reference to 'sqrtq'. /Cpp/float128/quadmath_snprintf/quadmath_snprintf.c:45: undefined reference to 'quadmath_snprintf'.
On one system, the header file (that contains all the extern
declarations), included, for example:
extern __float128 sqrtq (__float128) __quadmath_throw; extern __float128 strtoflt128 (const char *, char **) __quadmath_throw; extern int quadmath_snprintf (char *str, size_t size, const char *format, ...) __quadmath_throw;
An example of a location of quadmath.h is
C:\program files\gcc-6-win64\lib\gcc\x86_64-w64-mingw32\6.1.1\include\quadmath.h
and library at
C:\Program Files\gcc-6-win64\bin\libquadmath-0.dll
Command lines used (using CodeBLocks:
gcc.exe -Wall -g -c J:\Cpp\float128\quadmath_snprintf\main.c -o obj\Debug\main.o g++.exe -o bin\Debug\quadmath_snprintf.exe obj\Debug\main.o -lquadmath
The source code is at quadmath_snprintf.c.
float128 quadmath type
For C++ programs, you will want to use the C++ type float128
See example at cstdfloat_example.cpp.
A typical invocation of the compiler is
g++ -O3 -std=gnu++11 test.cpp -I/c/modular-boost -lquadmath -o test.exe
![]() |
Tip |
|---|---|
If you are trying to use the develop branch of Boost.Math, then make |
g++ -O3 -std=gnu++11 test.cpp -I/c/modular-boost/libs/math/include -I/c/modular-boost -lquadmath -o test.exe
![]() |
Note |
|---|---|
|
So far, the only missing detail that we had noted was in trying to use Link fails: undefined reference to typeinfo for __float128. See GCC Bug 43622 - no C++ typeinfo for __float128. But this is reported (Marc Glisse 2015-04-04 ) fixed in GCC 5 (and above). For example, with GCC6.1.1 this works as expected to a mangled string name, and output (if possible - not always). const std::type_info& tifu128 = typeid(__float128); // OK. //std::cout << tifu128.name() << std::endl; // On GCC, aborts (because not printable string). //std::cout << typeid(__float128).name() << std::endl; // Aborts - string name cannot be output. const std::type_info& tif128 = typeid(float128); // OK. std::cout << tif128.name() << std::endl; // OK. std::cout << typeid(float128).name() << std::endl; // OK. const std::type_info& tpi = typeid(pi1); // OK GCC 6.1.1 (from GCC 5 according to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43622) std::cout << tpi.name() << std::endl; // Output mangled name: // N5boost14multiprecision6numberINS0_8backends16float128_backendELNS0_26expression_template_optionE0EEE |