9front - general discussion about 9front
 help / color / mirror / Atom feed
* mpmod aliasing
@ 2017-02-05  0:09 Julius Schmidt
  2017-02-05  0:26 ` [9front] " Nick Owens
  2017-02-05  1:40 ` cinap_lenrek
  0 siblings, 2 replies; 3+ messages in thread
From: Julius Schmidt @ 2017-02-05  0:09 UTC (permalink / raw)
  To: 9front

mpmod has a bug when n==r and x is negative.
my best attempt at a fix:

void
mpmod(mpint *x, mpint *n, mpint *r)
{
 	int sign;
 	mpint *ns;

 	sign = x->sign;
 	ns = sign < 0 && n == r ? mpcopy(n) : n;
 	if((n->flags & MPfield) == 0
 	|| ((Mfield*)n)->reduce((Mfield*)n, x, r) != 0)
 		mpdiv(x, n, nil, r);
 	if(sign < 0)
 		mpmagsub(ns, r, r);
 	if(ns != n) mpfree(ns);
}



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-02-05  1:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-05  0:09 mpmod aliasing Julius Schmidt
2017-02-05  0:26 ` [9front] " Nick Owens
2017-02-05  1:40 ` cinap_lenrek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).