Ciao Niels, 18 feb 2024, 10:10 da ni...@lysator.liu.se:
> marco.bodr...@tutanota.com writes: > >> What about; >> >> >> /* Arrange so that |s| < |u| / 2g */ >> mpz_add (s1, s0, s1); >> { >> int cmp = mpz_cmpabs (s0, s1); >> if (cmp >= 0) >> { >> mpz_swap (s0, s1); >> mpz_sub (t1, t0, t1); >> if (cmp != 0 || mpz_cmpabs (t0, t1) > 0) >> mpz_swap (t0, t1); >> } >> } >> > > I think swapping of s and t must go together? I've tried out this > similar variant > You are right, it's better with the two swaps together. > mpz_add (s1, s0, s1); > mpz_sub (t1, t0, t1); > cmp = mpz_cmpabs (s0, s1); > if (cmp > 0 || (cmp == 0 && mpz_cmpabs (t0, t1) > 0)) > { > mpz_swap (s0, s1); > mpz_swap (t0, t1); > } > The only reason why I prefer my solution is: when cmp<0, there is no need to compute mpz_sub (t1, t0, t1); > Seems to work fine, and it's a rather clear way to express the "lexical" > preference that we want the cofactor pair with the smallest of |s|, |s'|, but > in case of a tie, we choose the pair with smallest |t|, |t'|. > I agree. Ĝis, m _______________________________________________ gmp-bugs mailing list gmp-bugs@gmplib.org https://gmplib.org/mailman/listinfo/gmp-bugs