Compile-time rational arithmetic
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
的类模板
std::ratio
和相关模板提供了编译时合理的算法支持。此模板的每个实例完全代表任何合理数量有限.原文:
The class template
std::ratio
and associated templates provide compile-time rational arithmetic support. Each instantiation of this template exactly represents any finite rational number.[编辑] 编译时的分数
在头文件
<ratio> 中定义 | |
代表确切的合理的部分 (类模板) |
由标准库提供了几个方便的typedef对应的SI比例的
原文:
Several convenience typedefs that correspond to the SI ratios are provided by the standard library:
在头文件
<ratio> 中定义 | |
类型
|
Definition |
yocto
|
std::ratio<1, 1000000000000000000000000>,如果std::intmax_t可以表示分母
原文: std::ratio<1, 1000000000000000000000000>, if std::intmax_t can represent the denominator |
zepto
|
std::ratio<1, 1000000000000000000000>,如果std::intmax_t可以表示分母
原文: std::ratio<1, 1000000000000000000000>, if std::intmax_t can represent the denominator |
atto
|
std::ratio<1, 1000000000000000000> |
femto
|
std::ratio<1, 1000000000000000> |
pico
|
std::ratio<1, 1000000000000> |
nano
|
std::ratio<1, 1000000000> |
micro
|
std::ratio<1, 1000000> |
milli
|
std::ratio<1, 1000> |
centi
|
std::ratio<1, 100> |
deci
|
std::ratio<1, 10> |
deca
|
std::ratio<10, 1> |
hecto
|
std::ratio<100, 1> |
kilo
|
std::ratio<1000, 1> |
mega
|
std::ratio<1000000, 1> |
giga
|
std::ratio<1000000000, 1> |
tera
|
std::ratio<1000000000000, 1> |
peta
|
std::ratio<1000000000000000, 1> |
exa
|
std::ratio<1000000000000000000, 1> |
zetta
|
std::ratio<1000000000000000000000, 1>,如果std::intmax_t可以代表的分子
原文: std::ratio<1000000000000000000000, 1>, if std::intmax_t can represent the numerator |
yotta
|
std::ratio<1000000000000000000000000, 1>,如果std::intmax_t可以代表的分子
原文: std::ratio<1000000000000000000000000, 1>, if std::intmax_t can represent the numerator |
[编辑] 编译时合理的算法
几类模板,执行算术运算
ratio
对象在编译时提供.原文:
Several class templates, that perform arithmetic operations on
ratio
objects at compile-time are provided. 在头文件
<ratio> 中定义 | |
(C++11) |
增加了两个 ratio 对象在编译时 原文: adds two ratio objects at compile-time (类模板) |
(C++11) |
在编译时减去两个 ratio 对象 原文: subtracts two ratio objects at compile-time (类模板) |
(C++11) |
将两个 ratio 对象在编译时 原文: multiplies two ratio objects at compile-time (类模板) |
(C++11) |
将两个 ratio 对象在编译时 原文: divides two ratio objects at compile-time (类模板) |
[编辑] 编译时的理性的比较
ratio
对象在编译时执行比较操作的几个类模板,提供.原文:
Several class templates, that perform comparison operations on
ratio
objects at compile-time are provided. 在头文件
<ratio> 中定义 | |
(C++11) |
比较两个 ratio 对象,在编译时的平等 原文: compares two ratio objects for equality at compile-time (类模板) |
(C++11) |
比较两个 ratio 不平等的对象,在编译时间 原文: compares two ratio objects for inequality at compile-time (类模板) |
(C++11) |
比较两个 ratio 对象为“小于”在编译时 原文: compares two ratio objects for less than at compile-time (类模板) |
(C++11) |
compares two ratio objects for less than or equal to at compile-time (类模板) |
(C++11) |
比较两个 ratio 对象为“大于”在编译时 原文: compares two ratio objects for greater than at compile-time (类模板) |
(C++11) |
比较两个 ratio 对象为“大于或等于”在编译时 原文: compares two ratio objects for greater than or equal to at compile-time (类模板) |