template <class R1, class R2> ratio_subtract;
1
2
template <typename R1, typename R2>
using ratio_subtract = std::ratio < R1::num*R2::den-R2::num*R1::den, R1::den*R2::den >;
| member constexpr | description |
|---|---|
| num | Numerator |
| den | Denominator |
| member type | definition | description |
|---|---|---|
| type | ratio<num,den> | The ratio type with the result of the subtraction. |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// ratio_subtract example
#include <iostream>
#include <ratio>
int main ()
{
typedef std::ratio<2,3> two_thirds;
typedef std::ratio<1,2> one_half;
typedef std::ratio_subtract<two_thirds,one_half> diff;
std::cout << "diff = " << diff::num << "/" << diff::den;
std::cout << " (which is: " << ( double(diff::num) / diff::den ) << ")" << std::endl;
return 0;
}
diff = 1/6 (which is: 0.166667)