Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Rounding Rules for Conversions

As a general rule, all conversions between unrelated types are performed using basic arithmetic operations, therefore conversions are either exact, or follow the same rounding rules as arithmetic for the type in question.

The following table summarises the situation for conversions from native types:

Backend

Rounding Rules

cpp_int

Conversions from integer types are exact if the target has sufficient precision, otherwise they truncate to the first 2^MaxBits bits (modulo arithmetic). Conversions from floating-point types are truncating to the nearest integer.

gmp_int

Conversions are performed by the GMP library except for conversion from long double which is truncating.

tom_int

Conversions from floating-point types are truncating, all others are performed by libtommath and are exact.

gmp_float

Conversions are performed by the GMP library except for conversion from long double which should be exact provided the target type has as much precision as a long double.

mpfr_float

All conversions are performed by the underlying MPFR library.

cpp_dec_float

All conversions are performed using basic arithmetic operations and are truncating.

gmp_rational

See gmp_int

cpp_rational

See cpp_int

tommath_rational

See tom_int


PrevUpHomeNext