创建具有特定精度的新cpp_dec_float类型

时间:2015-11-15 12:23:41

标签: c++ boost multiprecision

我正在使用c ++运行物理模拟,为了获得精确的结果,我使用的是boost :: multiprecision。 到目前为止,我使用了cpp_dec_float_50类型,但是,现在我需要测试不同精度的不同变量的模拟。

那么,如何创建新类型,例如cpp_dec_float_27(27位精度)?

我尝试更改模板代码:

namespace boost{ namespace multiprecision{
template <unsigned Digits10, class ExponentType = boost::int32_t, class Allocator = void>
class cpp_dec_float;
typedef number<cpp_dec_float<50> > cpp_dec_float_50;
typedef number<cpp_dec_float<100> > cpp_dec_float_100;
}} // namespaces

但是我遇到了很多问题。

1 个答案:

答案 0 :(得分:1)

如果我理解正确你试图改变你的增强装置,你永远不应该这样做,因为其他增强源可能取决于它。

如果你想定义自己的精度,你需要一个简单的typedef:

typedef number<cpp_dec_float<27> > cpp_dec_float27;

你准备好了。

但是,如果您的函数依赖于类型cpp_dec_float100,您可能需要考虑使用这些函数的模板来接受多个精度。