...one of the most highly
regarded and expertly designed C++ library projects in the
world. — Herb Sutter and Andrei
The functions in this library are all overloaded to accept mixed floating point (or mixed integer and floating point type) arguments. So for example:
foo(1.0, 2.0); foo(1.0f, 2); foo(1.0, 2L);
etc, are all valid calls, as long as "foo" is a function taking two floating-point arguments. But that leaves the question:
"Given a special function with N arguments of types T1, T2, T3 ... TN, then what type is the result?"
If all the arguments are of the same (floating point) type then the result is the same type as the arguments.
Otherwise, the type of the result is computed using the following logic:
doublefor the purposes of further analysis.
long double, then the result is of type
double, then the result is of type
double result, as does:
as in this case the integer first argument is treated as a
and takes precedence over the
second argument. To get a
result we would need all the arguments to be of type float:
When one or more of the arguments is not a template argument then it doesn't effect the return type at all, for example:
float, since the first
argument is not a template argument and so doesn't effect the result: without
this rule functions that take explicitly integer arguments could never return
And for user-defined types, typically Boost.Multiprecision,
All of the following return a
cyl_bessel_j(0, boost::multiprecision::cpp_bin_quad_float(2)); cyl_bessel_j(boost::multiprecision::cpp_bin_quad_float(2), 3); cyl_bessel_j(boost::multiprecision::cpp_bin_quad_float(2), boost::multiprecision::cpp_bin_quad_float(3));
but rely on the parameters provided being exactly representable, avoiding loss
of precision from construction from
All new projects should use Boost.Multiprecision.
During development of Boost.Math, NTL A Library for doing Number Theory was invaluable to create highly precise tables.
All of the following return an
cyl_bessel_j(0, NTL::RR(2)); cyl_bessel_j(NTL::RR(2), 3); cyl_bessel_j(NTL::quad_float(2), NTL::RR(3));
In the last case,
is convertible to
RR, but not
vice-versa, so the result will be an
that this assumes that you are using a patched
These rules are chosen to be compatible with the behaviour of ISO/IEC 9899:1999 Programming languages - C and with the Draft Technical Report on C++ Library Extensions, 2005-06-24, section 5.2.1, paragraph 5.