Converting poly_ints#
A poly_int<n, T>
can be constructed from up to
n
individual T
coefficients, with the remaining coefficients
being implicitly zero. In particular, this means that every
poly_int<n, T>
can be constructed from a single
scalar T
, or something compatible with T
.
Also, a poly_int<n, T>
can be constructed from
a poly_int<n, U>
if T
can be constructed
from U
.
The following functions provide other forms of conversion, or test whether such a conversion would succeed.
value.is_constant ()
Return true if
poly_int
value
is a compile-time constant.value.is_constant (&c1)
Return true if
poly_int
value
is a compile-time constant, storing it inc1
if so.c1
must be able to hold all constant values ofvalue
without loss of precision.value.to_constant ()
Assert that
value
is a compile-time constant and return its value. When using this function, please add a comment explaining why the condition is known to hold (for example, because an earlier phase of analysis rejected non-constants).value.to_shwi (&p2)
Return true if
poly_int<N, T>
value
can be represented without loss of precision as apoly_int<N, ``HOST_WIDE_INT`
>`, storing it in that form inp2
if so.value.to_uhwi (&p2)
Return true if
poly_int<N, T>
value
can be represented without loss of precision as apoly_int<N, ``unsigned HOST_WIDE_INT`
>`, storing it in that form inp2
if so.value.force_shwi ()
Forcibly convert each coefficient of
poly_int<N, T>
value
toHOST_WIDE_INT
, truncating any that are out of range. Return the result as apoly_int<N, ``HOST_WIDE_INT`
>`.value.force_uhwi ()
Forcibly convert each coefficient of
poly_int<N, T>
value
tounsigned HOST_WIDE_INT
, truncating any that are out of range. Return the result as apoly_int<N, ``unsigned HOST_WIDE_INT`
>`.wi::shwi (value, precision)
Return a
poly_int
with the same value asvalue
, but with the coefficients converted fromHOST_WIDE_INT
towide_int
.precision
specifies the precision of thewide_int
cofficients; if this is wider than aHOST_WIDE_INT
, the coefficients ofvalue
will be sign-extended to fit.wi::uhwi (value, precision)
Like
wi::shwi
, except thatvalue
has coefficients of typeunsigned HOST_WIDE_INT
. Ifprecision
is wider than aHOST_WIDE_INT
, the coefficients ofvalue
will be zero-extended to fit.wi::sext (value, precision)
Return a
poly_int
of the same type asvalue
, sign-extending every coefficient from the lowprecision
bits. This in effect applieswi::sext
to each coefficient individually.wi::zext (value, precision)
Like
wi::sext
, but for zero extension.poly_wide_int::from (value, precision, sign)
Convert
value
to apoly_wide_int
in which each coefficient hasprecision
bits. Extend the coefficients according tosign
if the coefficients have fewer bits.poly_offset_int::from (value, sign)
Convert
value
to apoly_offset_int
, extending its coefficients according tosign
if they have fewer bits thanoffset_int
.poly_widest_int::from (value, sign)
Convert
value
to apoly_widest_int
, extending its coefficients according tosign
if they have fewer bits thanwidest_int
.