SQL numeric/decimal 提高多精度
SQL numeric/decimal to boost multiprecision
我正在寻找一些 C++ 中的(非字符串)类型,我们可以用它来存储 SQL numeric(18, 4)
(或 decimal(18, 4)
)值。我浏览了 boost 的文档 cpp_dec_float,但对于如何使用它仍然很困惑:
- 当文档说“小数位”时(例如,在“typedefs cpp_dec_float_50 和 cpp_dec_float_100 分别提供 50 位和 100 位小数位精度的算术类型”中),它指的是数字吗小数点右边的位数或 所有 有效数字?
std::numeric_limits<number<cpp_dec_float<50>>>::digits10
是 50 但 std::numeric_limits<number<cpp_dec_float<4>>>::digits10
是 9。这是为什么?
- 如果
Digits10
模板参数是所有个有效数字,是否意味着无法指定固定精度和比例(如SQL numeric(18, 4)
) 对于提升多精度类型?
When the doc says "decimal digits" (e.g. in "The typedefs cpp_dec_float_50 and cpp_dec_float_100 provide arithmetic types at 50 and 100 decimal digits precision respectively"), is it referring to the number of digits to the right of the decimal point or all the significant digits?
所有有效数字。
std::numeric_limits<number<cpp_dec_float<50>>>::digits10 is 50 but std::numeric_limits<number<cpp_dec_float<4>>>::digits10 is 9. Why is that?
这是一个实现细节。基本上,图书馆提供了向您提供承诺的 4 位数字所需的最低限度
If the Digits10 template parameter is the number of all significant digits, does it mean there is no way to specify a fixed precision and a scale (as in SQL numeric(18, 4)) for boost multiprecision types?
确实如此。简而言之,多精度库不提供任何定点类型(尽管您显然可以使用 cpp_int
)
我正在寻找一些 C++ 中的(非字符串)类型,我们可以用它来存储 SQL numeric(18, 4)
(或 decimal(18, 4)
)值。我浏览了 boost 的文档 cpp_dec_float,但对于如何使用它仍然很困惑:
- 当文档说“小数位”时(例如,在“typedefs cpp_dec_float_50 和 cpp_dec_float_100 分别提供 50 位和 100 位小数位精度的算术类型”中),它指的是数字吗小数点右边的位数或 所有 有效数字?
std::numeric_limits<number<cpp_dec_float<50>>>::digits10
是 50 但std::numeric_limits<number<cpp_dec_float<4>>>::digits10
是 9。这是为什么?- 如果
Digits10
模板参数是所有个有效数字,是否意味着无法指定固定精度和比例(如SQLnumeric(18, 4)
) 对于提升多精度类型?
When the doc says "decimal digits" (e.g. in "The typedefs cpp_dec_float_50 and cpp_dec_float_100 provide arithmetic types at 50 and 100 decimal digits precision respectively"), is it referring to the number of digits to the right of the decimal point or all the significant digits?
所有有效数字。
std::numeric_limits<number<cpp_dec_float<50>>>::digits10 is 50 but std::numeric_limits<number<cpp_dec_float<4>>>::digits10 is 9. Why is that?
这是一个实现细节。基本上,图书馆提供了向您提供承诺的 4 位数字所需的最低限度
If the Digits10 template parameter is the number of all significant digits, does it mean there is no way to specify a fixed precision and a scale (as in SQL numeric(18, 4)) for boost multiprecision types?
确实如此。简而言之,多精度库不提供任何定点类型(尽管您显然可以使用 cpp_int
)