1

Is there a portable method of converting a uintmax_t to a mpz_t?

Compiling the following code with clang on OSX fails because there is no constructor for uint64_t for mpz_class.

const mpz_class maxUint64 = std::numeric_limits<uint64_t>::max();

error: conversion from 'type' (aka 'unsigned long long') to 'const mpz_class' (aka 'const __gmp_expr<__mpz_struct [1], __mpz_struct [1]>') is ambiguous
static const mpz_class maxUint64 = std::numeric_limits::max();

rsm
  • 2,530
  • 4
  • 26
  • 33
Han Wang
  • 11
  • 1
  • If all else fails, you can always go via `string`. – melpomene Apr 11 '18 at 06:35
  • 1
    Do you mean uintmax_t or uint64_t? If long is the same size as long long on your system, you can use that instead. Otherwise, it gets more complicated. For instance split the 64 bits into 32+32, convert the high part, shift it left, and add_ui the low part. – Marc Glisse Apr 13 '18 at 13:37
  • Possible duplicate of [mpz\_t to unsigned long long conversion (gmp lib)](https://stackoverflow.com/questions/6248723/mpz-t-to-unsigned-long-long-conversion-gmp-lib) – phuclv Apr 16 '18 at 15:36

0 Answers0