Skip to content

Commit

Permalink
gmpints: remove invalid ModInt return value treatment
Browse files Browse the repository at this point in the history
Before returning the computed result, ModInt checked whether it was
negative, it flipped the sign. This should (a) never be necessary,
because the preceding computations should always produce something
non-negative, and (b) would be mathematically incorrect.

Instead, we simply return the result untreated, and added an assertion
triggering if we ever see a negative result here (only enabled if
DEBUG_GMP is set).
  • Loading branch information
fingolfin committed Jan 4, 2017
1 parent 32d1993 commit 0b11a15
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/gmpints.c
Original file line number Diff line number Diff line change
Expand Up @@ -1864,12 +1864,10 @@ Obj ModInt ( Obj opL, Obj opR )
}

/* return the result */
if ( IS_INTNEG(mod) )
return NEW_INTPOS(mod);
else if ( IS_INTOBJ(mod) && 0 > INT_INTOBJ(mod) )
return INTOBJ_INT(-INT_INTOBJ(mod));
else
return mod;
#if DEBUG_GMP
assert( !IS_NEGATIVE(mod) );
#endif
return mod;
}


Expand Down

0 comments on commit 0b11a15

Please sign in to comment.