Keep fundamental type behavior with fixed size boost multiprecision integers

Viewed 94

From the cpp_int documentation :

The type uses a sign-magnitude representation internally, so type int128_t has 128-bits of precision plus an extra sign bit. In this respect the behaviour of these types differs from fundamental (built-in) 2's complement types.

This behavior differs from fundamental types where the MSB indicates the sign.

In order to have a similar behavior to fundamental integers, the documentation proposes :

In might be tempting to use a 127-bit type instead, and indeed this does work, but behaviour is still slightly different from a 2's complement fundamental (built-in) type as the minimum and maximum values are identical.

How can I keep the exact same behavior that fundamental types have but with fixed size boost multiprecision integers, such as int512_t ? If this isn't possible with boost, do you suggest any other library for doing so ? Thanks.

0 Answers
Related