Re: assign a large integer to a cpp_int
John Maddock via Boost-users <[email protected]> Sat, 27 May 2023 20:08:25 +0100
| Newsgroups | gmane.comp.lib.boost.user |
|---|---|
| Message-ID | <[email protected]> |
On 27/05/2023 19:15, Matthew Mawson via Boost-users wrote:
> I want to assign a large number to a cpp_int variable like this:
>
> cpp_int large = 30414093201713378043612608166064768844377641568960512000000000000;
>
> and I get this: error: integer literal is too large to be represented in any integer type.
You're compiler is correct, there are two ways around this, the first is
assignment from a string, which must be an explicit cast or construction:
cpp_int
large{"30414093201713378043612608166064768844377641568960512000000000000"};
Or you can create extended precision literals, but these must be in hex
format, see
https://www.boost.org/doc/libs/1_82_0/libs/multiprecision/doc/html/boost_multiprecision/tut/lits.html
John.