diff --git a/src/nmod_poly.h b/src/nmod_poly.h index 72817f4fc8..cb9a889f5c 100644 --- a/src/nmod_poly.h +++ b/src/nmod_poly.h @@ -206,18 +206,14 @@ void nmod_poly_one(nmod_poly_t res) res->coeffs[0] = 1; } +void nmod_poly_set_trunc(nmod_poly_t res, const nmod_poly_t poly, slong len); + NMOD_POLY_INLINE void nmod_poly_truncate(nmod_poly_t poly, slong len) { - if (poly->length > len) - { - poly->length = len; - _nmod_poly_normalise(poly); - } + nmod_poly_set_trunc(poly, poly, len); } -void nmod_poly_set_trunc(nmod_poly_t res, const nmod_poly_t poly, slong n); - void _nmod_poly_reverse(mp_ptr output, mp_srcptr input, slong len, slong m); void nmod_poly_reverse(nmod_poly_t output, const nmod_poly_t input, slong m); diff --git a/src/nmod_poly/set_trunc.c b/src/nmod_poly/set_trunc.c index 24572b3b82..ee220aa950 100644 --- a/src/nmod_poly/set_trunc.c +++ b/src/nmod_poly/set_trunc.c @@ -13,17 +13,21 @@ #include "nmod_poly.h" void -nmod_poly_set_trunc(nmod_poly_t res, const nmod_poly_t poly, slong n) +nmod_poly_set_trunc(nmod_poly_t res, const nmod_poly_t poly, slong len) { if (poly == res) { - nmod_poly_truncate(res, n); + if (res->length > len) + { + res->length = len; + _nmod_poly_normalise(res); + } } else { slong rlen; - rlen = FLINT_MIN(n, poly->length); + rlen = FLINT_MIN(len, poly->length); while (rlen > 0 && poly->coeffs[rlen - 1] == 0) rlen--;