首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“单位”-比率的方便度在哪里?

“单位”-比率的方便度在哪里?
EN

Stack Overflow用户
提问于 2020-10-20 08:06:55
回答 1查看 110关注 0票数 0

std::ratio为度量前缀(centi、deci、deca、hecto)提供了方便的类型。

代码语言:javascript
复制
yocto   std::ratio<1, 1000000000000000000000000>, if std::intmax_t can represent the denominator
zepto   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>, if std::intmax_t can represent the numerator
yotta   std::ratio<1000000000000000000000000, 1>, if std::intmax_t can represent the numerator 

少了什么?好吧..。单位比std::ratio<1,1>。我知道该单位没有正式的公制前缀名称,但这并不意味着它不存在。在[ratio.si]中,没有提到单元前缀。因此,我想知道:使用“单位”比率的最典型方式是什么?例如,当duration_cast-ing转到整秒时。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-20 08:49:22

使用“单位”比率最典型的方法是什么?

使用单位比率最实用的方法是不使用它。

这有点像问用1乘的最好方法是什么。你没有。

例如,持续时间为整秒时。

你会写std::chrono::duration_cast<std::chrono::seconds>

std::ratio<1,1>没有名称,因为您不需要它的名称。例如,std::duration的默认时间段为std::ratio<1,1>

如果你还想给它起个名字,你可以这样做:

代码语言:javascript
复制
using unit_ratio = std::ratio<1>;
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64440989

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档