]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/doc/overview/result_type_calc.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / math / doc / overview / result_type_calc.qbk
1
2 [section:result_type Calculation of the Type of the Result]
3
4 The functions in this library are all overloaded to accept
5 mixed floating point (or mixed integer and floating point type)
6 arguments. So for example:
7
8 foo(1.0, 2.0);
9 foo(1.0f, 2);
10 foo(1.0, 2L);
11
12 etc, are all valid calls, as long as "foo" is a function taking two
13 floating-point arguments. But that leaves the question:
14
15 [blurb ['"Given a special function with N arguments of
16 types T1, T2, T3 ... TN, then what type is the result?"]]
17
18 [*If all the arguments are of the same (floating point) type then the
19 result is the same type as the arguments.]
20
21 Otherwise, the type of the result
22 is computed using the following logic:
23
24 # Any arguments that are not template arguments are disregarded from
25 further analysis.
26 # For each type in the argument list, if that type is an integer type
27 then it is treated as if it were of type double for the purposes of
28 further analysis.
29 # If any of the arguments is a user-defined class type, then the result type
30 is the first such class type that is constructible from all of the other
31 argument types.
32 # If any of the arguments is of type `long double`, then the result is of type
33 `long double`.
34 # If any of the arguments is of type `double`, then the result is of type
35 `double`.
36 # Otherwise the result is of type `float`.
37
38 For example:
39
40 cyl_bessel(2, 3.0);
41
42 Returns a `double` result, as does:
43
44 cyl_bessel(2, 3.0f);
45
46 as in this case the integer first argument is treated as a `double` and takes
47 precedence over the `float` second argument. To get a `float` result we would need
48 all the arguments to be of type float:
49
50 cyl_bessel_j(2.0f, 3.0f);
51
52 When one or more of the arguments is not a template argument then it
53 doesn't effect the return type at all, for example:
54
55 sph_bessel(2, 3.0f);
56
57 returns a `float`, since the first argument is not a template argument and
58 so doesn't effect the result: without this rule functions that take
59 explicitly integer arguments could never return `float`.
60
61 And for user-defined types, all of the following return an `NTL::RR` result:
62
63 cyl_bessel_j(0, NTL::RR(2));
64
65 cyl_bessel_j(NTL::RR(2), 3);
66
67 cyl_bessel_j(NTL::quad_float(2), NTL::RR(3));
68
69 In the last case, `quad_float` is convertible to `RR`, but not vice-versa, so
70 the result will be an `NTL::RR`. Note that this assumes that you are using
71 a [link math_toolkit.high_precision.use_ntl patched NTL library].
72
73 These rules are chosen to be compatible with the behaviour of
74 ['ISO/IEC 9899:1999 Programming languages - C]
75 and with the
76 [@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].
77
78 [endsect]
79
80 [/
81 Copyright 2006, 2012 John Maddock and Paul A. Bristow.
82 Distributed under the Boost Software License, Version 1.0.
83 (See accompanying file LICENSE_1_0.txt or copy at
84 http://www.boost.org/LICENSE_1_0.txt).
85 ]