std::ratio_subtract

来自cppreference.com
< cpp‎ | numeric‎ | ratio
2012年10月25日 (四) 16:15P12讨论 | 贡献的版本

 
 
元编程库
类型特征
类型类别
(C++11)
(C++11)(DR*)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11) 
(C++11)
(C++11)
类型属性
(C++11)
(C++11)
(C++14)
(C++11)(C++26 弃用)
(C++11)(C++20 前*)
(C++11)(C++20 弃用)
(C++11)
类型特征常量
元函数
(C++17)
受支持操作
关系与属性查询
类型修改
(C++11)(C++11)(C++11)
类型变换
(C++11)(C++23 弃用)
(C++11)(C++23 弃用)
(C++11)
(C++11)(C++20 前*)(C++17)

(C++11)
(C++17)
编译时有理数算术
编译时整数序列
 
编译时有理数算术
(C++11)
算术
(C++11)
ratio_subtract
(C++11)
比较
(C++11)
 
<tr class="t-dsc-header"> <td>
在标头 <ratio> 定义
</td>

<td></td> <td></td> </tr> <tr class="t-dcl ">

<td class="t-dcl-nopad">
template< class R1, class R2 >
using ratio_subtract = /* unspecified */;
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr>

。模板别名std::ratio_subtract表示std::ratio的实例所代表的两个精确合理的分数相减的​​结果R1R2,结果一个std::ratio例如std::ratio<Num, Denom>其中Num == R1::num * R2::den - R2::num * R1::denDenom == R1::den * R2::den.
原文:
The template alias std::ratio_subtract denotes the result of subtracting two exact rational fractions represented by the std::ratio instances R1 and R2. The result a std::ratio instance std::ratio<Num, Denom> where Num == R1::num * R2::den - R2::num * R1::den and Denom == R1::den * R2::den.
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

。会员类型。

。会员类型。
原文:
Member type
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。
Definition
type std::ratio<num, den>

。会员常数。

num
[静态]
constexpr类型的值std::intmax_t等于sign(Num) * sign(Denom) * abs(Num) / gcd(Num, Denom)
原文:
constexpr value of type std::intmax_t equal to sign(Num) * sign(Denom) * abs(Num) / gcd(Num, Denom)
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

(公开静态成员常量)
den
[静态]
constexpr类型的值std::intmax_t等于abs(Denom) / gcd(Num, Denom)
原文:
constexpr value of type std::intmax_t equal to abs(Denom) / gcd(Num, Denom)
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

(公开静态成员常量)

。为例。

#include <iostream>
#include <ratio>
 
int main()
{
    typedef std::ratio<2, 3> two_third;
    typedef std::ratio<1, 6> one_sixth;
 
    typedef std::ratio_subtract<two_third, one_sixth> diff;
    std::cout << "2/3 - 1/6 = " << diff::num << '/' << diff::den << '\n';
}

输出:

2/3 - 1/6 = 1/2