chrono有不同的时间段? [英] chrono with different time periods?
问题描述
目前我使用 boost :: rational< std :: uint64>
在我的应用程序中跟踪。
基本上,我有一个运行很长一段时间的时钟,并将由不同的时间分辨率的不同组件,例如1 / 50s,1 / 30s,1001 / 30000s等...我想保持完美的精度,即没有浮点。 boost :: rational
适用于此目的,但我认为这将是更好的设计使用 std :: chrono :: duration
为此。
我的问题是,我如何使用 std :: chrono :: duration
这里?因为它使用了一个编译时间段,我不知道如何在我需要保持精度的情况下使用它。
您可以将期间设为 1
,并为 Rep
使用浮点类型。 p>
我可疑,您可以使用 boost :: rational
执行相同的操作,必须仔细观察 std :: chrono
,我没有这样做。查看 treat_as_floating_point
和 duration_values
。还可以尝试通过算术类型或类仿真算术类型的类来确定标准的含义。
可能合理地认为如果 boost :: rational
不会模拟算术类型,那么它不会完成它的工作。但它不一定遵循它真的做的一切 std :: chrono :: duration
预期。
Currently I am using boost::rational<std::uint64>
to keep track in my application.
Basically I have a clock that runs over a very long period of time and will be tick by different components of different time resolutions, e.g. 1/50s, 1/30s, 1001/30000s etc... I want to maintain perfect precision, i.e. no floating point. boost::rational
works well for this purpose, however I think it would be better design to use std::chrono::duration
for this.
My problem though is, how can I use std::chrono::duration
here? Since it uses a compile time period I don't quite see how I can use it in my scenario where I need to maintain precision?
You're allowed to set the period to 1
and use a floating point type for Rep
.
I suspect that you can do the same thing with boost::rational
, but you'll have to look quite closely at std::chrono
, which I haven't done. Look at treat_as_floating_point
and duration_values
. Also try to figure out what the standard means by "An arithmetic type or a class emulating an arithmetic type".
One might reasonably argue that if boost::rational
doesn't emulate an arithmetic type, then it's not doing its job. But it doesn't necessarily follow that it really does everything std::chrono::duration
expects.
这篇关于chrono有不同的时间段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!