Testing latest pari + WASM + node.js... and it works?! Wow.
License: GPL3
ubuntu2004
#line 2 "../src/kernel/gmp/gcd.c"1/* Copyright (C) 2000-2003 The PARI group.23This file is part of the PARI/GP package.45PARI/GP is free software; you can redistribute it and/or modify it under the6terms of the GNU General Public License as published by the Free Software7Foundation; either version 2 of the License, or (at your option) any later8version. It is distributed in the hope that it will be useful, but WITHOUT9ANY WARRANTY WHATSOEVER.1011Check the License for details. You should have received a copy of it, along12with the package; see the file 'COPYING'. If not, write to the Free Software13Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */1415/* assume y > x > 0. return y mod x */16static ulong17resiu(GEN y, ulong x)18{19return mpn_mod_1(LIMBS(y), NLIMBS(y), x);20}2122GEN23gcdii(GEN a, GEN b)24{25long v, w;26pari_sp av;27GEN t;2829switch (abscmpii(a,b))30{31case 0: return absi(a);32case -1: swap(a,b);33}34if (!signe(b)) return absi(a);35/* here |a|>|b|>0. Try single precision first */36if (lgefint(a)==3)37return igcduu((ulong)a[2], (ulong)b[2]);38if (lgefint(b)==3)39{40ulong u = resiu(a,(ulong)b[2]);41if (!u) return absi(b);42return igcduu((ulong)b[2], u);43}44/* larger than gcd: "set_avma(av)" gerepile (erasing t) is valid */45av = avma; (void)new_chunk(lgefint(b)+1); /* HACK */46t = remii(a,b);47if (!signe(t)) { set_avma(av); return absi(b); }4849a = b; b = t;50v = vali(a); a = shifti(a,-v); setabssign(a);51w = vali(b); b = shifti(b,-w); setabssign(b);52if (w < v) v = w;53switch(abscmpii(a,b))54{55case 0: set_avma(av); a=shifti(a,v); return a;56case -1: swap(a,b);57}58if (is_pm1(b)) { set_avma(av); return int2n(v); }59{60/* general case */61/*This serve two purposes: 1) mpn_gcd destroy its input and need an extra62* limb 2) this allows us to use icopy instead of gerepile later. NOTE: we63* must put u before d else the final icopy could fail.64*/65GEN res= cgeti(lgefint(a)+1);66GEN ca = icopy_ef(a,lgefint(a)+1);67GEN cb = icopy_ef(b,lgefint(b)+1);68long l = mpn_gcd(LIMBS(res), LIMBS(ca), NLIMBS(ca), LIMBS(cb), NLIMBS(cb));69res[1] = evalsigne(1)|evallgefint(l+2);70set_avma(av);71return shifti(res,v);72}73}747576