class template
<ratio>
std::ratio_addtemplate <class R1, class R2> ratio_add;
Add two ratios
This class template alias generates a ratio type that is the sum of the ratio types R1 and R2.The resulting type is the same as if ratio_add was defined as:
1
2
template <typename R1, typename R2>
using ratio_add = ratio < R1::num*R2::den+R2::num*R1::den, R1::den*R2::den >;
A program shall not cause any expression in the above definition to expand to values not representable as an
intmax_t.
Template parameters1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// ratio_add example
#include <iostream>
#include <ratio>
int main ()
{
typedef std::ratio<1,2> one_half;
typedef std::ratio<2,3> two_thirds;
typedef std::ratio_add<one_half,two_thirds> sum;
std::cout << "sum = " << sum::num << "/" << sum::den;
std::cout << " (which is: " << ( double(sum::num) / sum::den ) << ")" << std::endl;
return 0;
}
sum = 7/6 (which is: 1.166667)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4