1 [section:result_type Calculation of the Type of the Result]
3 The functions in this library are all overloaded to accept
4 mixed floating point (or mixed integer and floating point type)
5 arguments. So for example:
11 etc, are all valid calls, as long as "foo" is a function taking two
12 floating-point arguments. But that leaves the question:
14 [blurb ['"Given a special function with N arguments of
15 types T1, T2, T3 ... TN, then what type is the result?"]]
17 [*If all the arguments are of the same (floating point) type then the
18 result is the same type as the arguments.]
20 Otherwise, the type of the result
21 is computed using the following logic:
23 # Any arguments that are not template arguments are disregarded from
25 # For each type in the argument list, if that type is an integer type
26 then it is treated as if it were of type `double` for the purposes of
28 # If any of the arguments is a user-defined class type, then the result type
29 is the first such class type that is constructible from all of the other
31 # If any of the arguments is of type `long double`, then the result is of type
33 # If any of the arguments is of type `double`, then the result is of type
35 # Otherwise the result is of type `float`.
41 Returns a `double` result, as does:
45 as in this case the integer first argument is treated as a `double` and takes
46 precedence over the `float` second argument. To get a `float` result we would need
47 all the arguments to be of type float:
49 cyl_bessel_j(2.0f, 3.0f);
51 When one or more of the arguments is not a template argument then it
52 doesn't effect the return type at all, for example:
56 returns a `float`, since the first argument is not a template argument and
57 so doesn't effect the result: without this rule functions that take
58 explicitly integer arguments could never return `float`.
60 And for user-defined types, typically __multiprecision,
62 All of the following return a `boost::multiprecision::cpp_bin_quad_float` result:
64 cyl_bessel_j(0, boost::multiprecision::cpp_bin_quad_float(2));
66 cyl_bessel_j(boost::multiprecision::cpp_bin_quad_float(2), 3);
68 cyl_bessel_j(boost::multiprecision::cpp_bin_quad_float(2), boost::multiprecision::cpp_bin_quad_float(3));
70 but rely on the parameters provided being exactly representable, avoiding loss of precision from construction from `double`.
72 [tip All new projects should use Boost.Multiprecision.]
74 During development of Boost.Math, __NTL was invaluable to create highly precise tables.
76 All of the following return an `NTL::RR` result:
78 cyl_bessel_j(0, NTL::RR(2));
80 cyl_bessel_j(NTL::RR(2), 3);
82 cyl_bessel_j(NTL::quad_float(2), NTL::RR(3));
84 In the last case, `quad_float` is convertible to `RR`, but not vice-versa, so
85 the result will be an `NTL::RR`. Note that this assumes that you are using
86 a [link math_toolkit.high_precision.use_ntl patched NTL library].
89 These rules are chosen to be compatible with the behaviour of
90 ['ISO/IEC 9899:1999 Programming languages - C]
92 [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf Draft Technical Report on C++ Library Extensions, 2005-06-24, section 5.2.1, paragraph 5].
94 [endsect] [/section:result_type Calculation of the Type of the Result]
97 Copyright 2006, 2012 John Maddock and Paul A. Bristow.
98 Distributed under the Boost Software License, Version 1.0.
99 (See accompanying file LICENSE_1_0.txt or copy at
100 http://www.boost.org/LICENSE_1_0.txt).