Jeroen Demeyer on Thu, 22 Jul 2010 23:35:50 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
[PATCH] for gequal1 and gequalm1 |
Hello pari-dev, This patch has been sitting for a long time in my pari directory (and has been used by me for a long time). It "fixes" gequal1 and gequalm1 in the sense that these functions should become more consistent with gequal. I realize this patch might not cover all possible cases, but it surely goes in the right direction. Cheers, Jeroen.
Index: src/basemath/gen2.c =================================================================== --- src/basemath/gen2.c (revision 12530) +++ src/basemath/gen2.c (working copy) @@ -406,6 +406,8 @@ int gequal1(GEN x) { + long i; + switch(typ(x)) { case t_INT: @@ -432,8 +434,15 @@ case t_QUAD: return gequal1(gel(x,2)) && gequal0(gel(x,3)); + case t_SER: + if (valp(x) != 0) return 0; case t_POL: - return lg(x)==3 && gequal1(gel(x,2)); + if (lg(x) < 3 || !gequal1(gel(x,2))) return 0; + for (i = 3; i < lg(x); i++) if (!gequal0(gel(x,i))) return 0; + return 1; + + case t_RFRAC: + return gequal(gel(x,1), gel(x,2)); } return 0; } @@ -443,7 +452,7 @@ gequalm1(GEN x) { pari_sp av; - long y; + long i, y; GEN p1; switch(typ(x)) @@ -476,8 +485,15 @@ av=avma; p1 = gaddgs(gel(x,2), 1); y = signe(p1) && !gequal(p1,gel(x,1)); avma=av; return !y; + case t_SER: + if (valp(x) != 0) return 0; case t_POL: - return lg(x)==3 && gequalm1(gel(x,2)); + if (lg(x) < 3 || !gequalm1(gel(x,2))) return 0; + for (i = 3; i < lg(x); i++) if (!gequal0(gel(x,i))) return 0; + return 1; + + case t_RFRAC: + av = avma; y = gequal(gel(x,1), gneg(gel(x,2))); avma = av; return y; } return 0; }