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_intvalueis a compile-time constant.value.is_constant (&c1)Return true if
poly_intvalueis a compile-time constant, storing it inc1if so.c1must be able to hold all constant values ofvaluewithout loss of precision.value.to_constant ()Assert that
valueis 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>valuecan be represented without loss of precision as apoly_int<N, ``HOST_WIDE_INT`>`, storing it in that form inp2if so.value.to_uhwi (&p2)Return true if
poly_int<N, T>valuecan be represented without loss of precision as apoly_int<N, ``unsigned HOST_WIDE_INT`>`, storing it in that form inp2if so.value.force_shwi ()Forcibly convert each coefficient of
poly_int<N, T>valuetoHOST_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>valuetounsigned 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_intwith the same value asvalue, but with the coefficients converted fromHOST_WIDE_INTtowide_int.precisionspecifies the precision of thewide_intcofficients; if this is wider than aHOST_WIDE_INT, the coefficients ofvaluewill be sign-extended to fit.wi::uhwi (value, precision)Like
wi::shwi, except thatvaluehas coefficients of typeunsigned HOST_WIDE_INT. Ifprecisionis wider than aHOST_WIDE_INT, the coefficients ofvaluewill be zero-extended to fit.wi::sext (value, precision)Return a
poly_intof the same type asvalue, sign-extending every coefficient from the lowprecisionbits. This in effect applieswi::sextto each coefficient individually.wi::zext (value, precision)Like
wi::sext, but for zero extension.poly_wide_int::from (value, precision, sign)Convert
valueto apoly_wide_intin which each coefficient hasprecisionbits. Extend the coefficients according tosignif the coefficients have fewer bits.poly_offset_int::from (value, sign)Convert
valueto apoly_offset_int, extending its coefficients according tosignif they have fewer bits thanoffset_int.poly_widest_int::from (value, sign)Convert
valueto apoly_widest_int, extending its coefficients according tosignif they have fewer bits thanwidest_int.