下面的代码在使用 VC++ 的 Windows 上编译得很好:
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <iostream>
namespace mp = boost::multiprecision;
using BigFloat = mp::cpp_dec_float_50;
using BigInt = mp::uint256_t;
template <int decimals = 0, typename T> T floorBI(T const& v)
{
static const T scale = pow(T(10), decimals);
if (v.is_zero())
return v;
// ceil/floor is found via ADL and uses expression templates for
// optimization
if (v < 0)
return ceil(v * scale) / scale;
else
// floor is found via ADL and uses expression templates for optimization
return floor(v * scale) / scale;
}
int main()
{
BigFloat A = 3;
BigFloat B = 2;
static_cast<BigInt>(floorBI<0>(static_cast<BigFloat>(A) / static_cast<BigFloat>(B)));
return 0;
}
,但是对于 GCC(适用于 Android 和 iOS),模板似乎存在问题。
“应该”匹配的模板的特定错误
..\boost/multiprecision/detail/default_ops.hpp:3745:18:注意:候选模板被忽略:无法将“表达式”与“数字”匹配 UNARY_OP_FUNCTOR(ceil, number_kind_floating_point) ^ ..\boost/multiprecision/detail/default_ops .hpp:3745:18:注意:候选模板已忽略:无法将 1 与 0 匹配 ..\boost/multiprecision/detail/default_ops.hpp:3745:18:注意:候选模板已忽略:要求 'boost::multiprecision:: number_category<boost::multiprecision::backends::cpp_int_backend<256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void> >::value == number_kind_floating_point' 不满足 [with Backend = boost::multiprecision::backends::cpp_int_backend<256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>] ..\boost/multiprecision/detail/default_ops.hpp:3745:18:注意:候选模板被忽略:无法匹配 1 和 0
VC++ 处理所有这一切都“很好”。
等待@Sehe 出现;]