void subg(giant a, giant b) /* b := b - a, any signs, any result. */ { int asgn = a->sign, bsgn = b->sign; if (asgn == 0) return; if (bsgn == 0) { gtog(a, b); negg(b); return; } if ((asgn < 0) != (bsgn < 0)) { if (bsgn > 0) { negg(a); normal_addg(a, b); negg(a); return; } negg(b); normal_addg(a, b); negg(b); return; } if (bsgn > 0) { if (gcompg(b, a) >= 0) { normal_subg(a, b); return; } reverse_subg(a, b); negg(b); return; } negg(a); negg(b); if (gcompg(b, a) >= 0) { normal_subg(a, b); negg(a); negg(b); return; } reverse_subg(a, b); negg(a); return; }
void addg(giant a, giant b) /* b := b + a, any signs any result. */ { int asgn = a->sign, bsgn = b->sign; if(asgn == 0) return; if(bsgn == 0) { gtog(a,b); return; } if((asgn < 0) == (bsgn < 0)) { if(bsgn > 0) { normal_addg(a,b); return; } negg(a); if(a != b) negg(b); normal_addg(a,b); /* Fix REC 1 Dec 98. */ negg(a); if(a != b) negg(b); return; /* Fix REC 1 Dec 98. */ } if(bsgn > 0) { negg(a); if(gcompg(b,a) >= 0) { normal_subg(a,b); negg(a); return; } reverse_subg(a,b); negg(a); negg(b); return; } negg(b); if(gcompg(b,a) < 0) { reverse_subg(a,b); return; } normal_subg(a,b); negg(b); return; }