0

我在cpp_dec_float源文件中找到了这一部分:

struct initializer
  {
     initializer()
     {
        cpp_dec_float<Digits10, ExponentType, Allocator>::nan();
        cpp_dec_float<Digits10, ExponentType, Allocator>::inf();
        (cpp_dec_float<Digits10, ExponentType, Allocator>::min)();
        (cpp_dec_float<Digits10, ExponentType, Allocator>::max)();
        cpp_dec_float<Digits10, ExponentType, Allocator>::zero();
        cpp_dec_float<Digits10, ExponentType, Allocator>::one();
        cpp_dec_float<Digits10, ExponentType, Allocator>::two();
        cpp_dec_float<Digits10, ExponentType, Allocator>::half();
        cpp_dec_float<Digits10, ExponentType, Allocator>::double_min();
        cpp_dec_float<Digits10, ExponentType, Allocator>::double_max();
        cpp_dec_float<Digits10, ExponentType, Allocator>::long_double_max();
        cpp_dec_float<Digits10, ExponentType, Allocator>::long_double_min();
        cpp_dec_float<Digits10, ExponentType, Allocator>::long_long_max();
        cpp_dec_float<Digits10, ExponentType, Allocator>::long_long_min();
        cpp_dec_float<Digits10, ExponentType, Allocator>::ulong_long_max();
        cpp_dec_float<Digits10, ExponentType, Allocator>::eps();
        cpp_dec_float<Digits10, ExponentType, Allocator>::pow2(0);
     }
     void do_nothing(){}
  };

我想使用其中一些值,例如zero, one, two,half而不是声明全局const变量。

是否可以内联使用这些值?如果是这样,怎么做?

示例

#include <boost/multiprecision/number.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <iostream>

namespace mp = boost::multiprecision;

int main()
{
    typedef mp::number<mp::cpp_dec_float<100>> mp_type;
    mp_type test_num("7.0710678");

    test_num *= mp_type.two();

    std::cout << test_num.str( 0, std::ios_base::scientific ) << '\n';
}
4

1 回答 1

2

boost::multiprecision::number repeats its first template argument as a public member type backend_type. So,

test_num = test_num * mp_type::backend_type::two();
于 2014-06-17T03:17:38.410 回答