编译时有理数算术
来自cppreference.com
元编程库
类型特性 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
编译时有理数算术 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
编译时整数序列 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C++14)
|
编译时有理数算术
(C++11)
|
||||
算术 | ||||
(C++11)
|
||||
(C++11)
|
||||
(C++11)
|
||||
(C++11)
|
||||
比较 | ||||
(C++11)
|
||||
(C++11)
|
||||
(C++11)
|
||||
(C++11)
|
||||
(C++11)
|
||||
(C++11)
|
类模板 std::ratio
及相关的模板提供编译时有理数算术支持。此模板的每个实例化都准确表示任一有限有理数。
编译时分数
在标头
<ratio>
定义 |
|
表示准确的分数 (类模板) |
标准库为提供数种对应 SI 比例的便利 typedef :
在标头
<ratio>
定义 |
|
类型 | 定义 |
yocto
|
std::ratio<1, 1000000000000000000000000> ,若 std::intmax_t 能表示分母 |
zepto
|
std::ratio<1, 1000000000000000000000> ,若 std::intmax_t 能表示分母 |
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 能表示分子 |
yotta
|
std::ratio<1000000000000000000000000, 1> ,若 std::intmax_t 能表示分子 |
编译时有理数算术
提供数个别名模板,它们在编译时进行 ratio
实例上的算术。
在标头
<ratio>
定义 |
|
(C++11)
|
在编译时相加两个 ratio 对象 (别名模板) |
(C++11)
|
在编译时相减两个 ratio 对象 (别名模板) |
(C++11)
|
在编译时相乘两个 ratio 对象 (别名模板) |
(C++11)
|
在编译时相除两个 ratio 对象 (别名模板) |
编译时有理数比较
提供数个类模板,它们在编译时进行 ratio
实例上的比较运算。
在标头
<ratio>
定义 |
|
(C++11)
|
在编译时比较两个 ratio 对象的相等性 (类模板) |
(C++11)
|
在编译时比较两个 ratio 对象的不相等性 (类模板) |
(C++11)
|
在编译时比较两个 ratio 对象的小于关系 (类模板) |
(C++11)
|
在编译时比较两个 ratio 对象的小于或等于关系 (类模板) |
(C++11)
|
在编译时比较两个 ratio 对象的大于关系 (类模板) |
(C++11)
|
在编译时比较两个 ratio 对象的大于或等于关系 (类模板) |