Skip to content

Commit

Permalink
Merge pull request #1503 from vneiger/nmod_poly_trunc_and_settrunc
Browse files Browse the repository at this point in the history
Simplify truncation for `nmod_poly`
  • Loading branch information
vneiger authored Oct 11, 2023
2 parents 0d05e3c + b57f2c6 commit c08c06b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 3 additions & 7 deletions src/nmod_poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 7 additions & 3 deletions src/nmod_poly/set_trunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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--;

Expand Down

0 comments on commit c08c06b

Please sign in to comment.