【问题标题】:How to use the C++ max function with boost 128 bit integer如何将 C++ max 函数与 boost 128 位整数一起使用
【发布时间】:2018-04-03 12:15:53
【问题描述】:

如果我有以下代码:

#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision


int main()
{
    int128_t a = Func_a()
    int128_t b = Func_b()

    std::cout << std::max(a, b) << std::endl;
    return 0;
}

如果我在 Ubuntu 上使用 g++ 编译,我会收到以下错误:

错误:无法在赋值中将“const boost::multiprecision::number >”转换为“int64 {aka long long int}”

比较两个 int128_t 数字以查看哪个更大的正确方法是什么?

编辑:我正在使用 std::max。

【问题讨论】:

  • 你在哪里使用max?这是某个功能,还是应该是std::max?
  • 它的意思是 std::max。现已更新。
  • 代码示例仍然太破碎,甚至无法考虑。而且这个问题格式不正确:coliru.stacked-crooked.com/a/c3675c01da00e0aa

标签: c++ boost multiprecision int128 boost-multiprecision


【解决方案1】:

您的代码(缺少分号除外)编译并运行没有错误。

但是,根据您的编译器消息,我怀疑在

int128_t a = Func_a(); // are you really sure it is int128_t?

左边不是boost::multiprecision::int128_t,因为编译器说它是一个int64。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-19
    • 2013-07-20
    • 2018-12-31
    • 2016-07-02
    • 2015-02-19
    • 2021-07-29
    • 1970-01-01
    相关资源
    最近更新 更多