Testing latest pari + WASM + node.js... and it works?! Wow.
License: GPL3
ubuntu2004
#line 2 "../src/kernel/none/level1.h"1/* Copyright (C) 2000 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/* This file defines "level 1" kernel functions.16* These functions can be inline; they are also defined externally in17* mpinl.c, which includes this file and never needs to be changed */1819INLINE long20evallg(long x)21{22if (x & ~LGBITS) pari_err_OVERFLOW("lg()");23return _evallg(x);24}25INLINE long26evalvalp(long x)27{28long v = _evalvalp(x);29if (v & ~VALPBITS) pari_err_OVERFLOW("valp()");30return v;31}32INLINE long33evalexpo(long x)34{35long v = _evalexpo(x);36if (v & ~EXPOBITS) pari_err_OVERFLOW("expo()");37return v;38}39INLINE long40evalprecp(long x)41{42long v = _evalprecp(x);43if (x & ~((1UL<<(BITS_IN_LONG-VALPnumBITS))-1)) pari_err_OVERFLOW("precp()");44return v;45}4647INLINE int48varncmp(long x, long y)49{50if (varpriority[x] < varpriority[y]) return 1;51if (varpriority[x] > varpriority[y]) return -1;52return 0;53}54INLINE long55varnmin(long x, long y)56{ return (varpriority[x] <= varpriority[y])? x: y; }57INLINE long58varnmax(long x, long y)59{ return (varpriority[x] >= varpriority[y])? x: y; }6061/* Inhibit some area gerepile-wise: declare it to be a non recursive62* type, of length l. Thus gerepile won't inspect the zone, just copy it.63* For the following situation:64* z = cgetg(t,a); av = avma; garbage(); ltop = avma;65* for (i=1; i<HUGE; i++) gel(z,i) = blah();66* stackdummy(av,ltop);67* loses (av-ltop) words but save a costly gerepile. */68INLINE void69stackdummy(pari_sp av, pari_sp ltop) {70long l = ((GEN)av) - ((GEN)ltop);71if (l > 0) {72GEN z = (GEN)ltop;73z[0] = evaltyp(t_VECSMALL) | evallg(l);74#ifdef DEBUG75{ long i; for (i = 1; i < l; i++) z[i] = 0; }76#endif77}78}79INLINE void80fixlg(GEN x, long ly) {81long lx = lg(x), l = lx - ly;82if (l > 0)83{ /* stackdummy(x+lx, x+ly) */84GEN z = x + ly;85z[0] = evaltyp(t_VECSMALL) | evallg(l);86setlg(x, ly);87#ifdef DEBUG88{ long i; for (i = 1; i < l; i++) z[i] = 0; }89#endif90}91}92/* update lg(z) before affrr(y, z) [ to cater for precision loss ]*/93INLINE void94affrr_fixlg(GEN y, GEN z) { fixlg(z, lg(y)); affrr(y, z); }9596/*******************************************************************/97/* */98/* ALLOCATE ON STACK */99/* */100/*******************************************************************/101INLINE void102set_avma(ulong av) { avma = av; }103104INLINE double105gc_double(pari_sp av, double d) { set_avma(av); return d; }106INLINE long107gc_long(pari_sp av, long s) { set_avma(av); return s; }108INLINE ulong109gc_ulong(pari_sp av, ulong s) { set_avma(av); return s; }110INLINE int111gc_bool(pari_sp av, int s) { set_avma(av); return s; }112INLINE int113gc_int(pari_sp av, int s) { set_avma(av); return s; }114INLINE GEN115gc_NULL(pari_sp av) { set_avma(av); return NULL; }116INLINE GEN117gc_const(pari_sp av, GEN x) { set_avma(av); return x; }118119INLINE GEN120new_chunk(size_t x) /* x is a number of longs */121{122GEN z = ((GEN) avma) - x;123CHECK_CTRLC124if (x > (avma-pari_mainstack->bot) / sizeof(long))125new_chunk_resize(x);126set_avma((pari_sp)z);127#ifdef MEMSTEP128if (DEBUGMEM>1 && pari_mainstack->memused != DISABLE_MEMUSED) {129long d = (long)pari_mainstack->memused - (long)z;130if (labs(d) > 4*MEMSTEP)131{132pari_mainstack->memused = (pari_sp)z;133err_printf("...%4.0lf Mbytes used\n",134(pari_mainstack->top-pari_mainstack->memused)/1048576.);135}136}137#endif138return z;139}140141INLINE char *142stack_malloc(size_t N)143{144long n = nchar2nlong(N);145return (char*)new_chunk(n);146}147148INLINE char *149stack_malloc_align(size_t N, long k)150{151ulong d = ((ulong)avma) % k, e = ((ulong)N) % k;152if (d) (void)new_chunk(d/sizeof(long));153if (e) N += k-e;154return (char*) new_chunk(nchar2nlong(N));155}156157INLINE char *158stack_calloc(size_t N)159{160char *p = stack_malloc(N);161memset(p, 0, N); return p;162}163164INLINE char *165stack_calloc_align(size_t N, long k)166{167ulong d = ((ulong)avma) % k, e = ((ulong)N) % k;168if (d) (void)new_chunk(d/sizeof(long));169if (e) N += k-e;170return stack_calloc(N);171}172173/* cgetg(lg(x), typ(x)), set *lx. Implicit unsetisclone() */174INLINE GEN175cgetg_copy(GEN x, long *plx) {176GEN y;177*plx = lg(x); y = new_chunk((size_t)*plx);178y[0] = x[0] & (TYPBITS|LGBITS); return y;179}180INLINE GEN181cgetg_block(long x, long y)182{183GEN z = newblock((size_t)x);184z[0] = CLONEBIT | evaltyp(y) | evallg(x);185return z;186}187INLINE GEN188cgetg(long x, long y)189{190GEN z = new_chunk((size_t)x);191z[0] = evaltyp(y) | evallg(x);192return z;193}194INLINE GEN195cgeti(long x)196{197GEN z = new_chunk((size_t)x);198z[0] = evaltyp(t_INT) | evallg(x);199return z;200}201INLINE GEN202cgetipos(long x)203{204GEN z = cgeti(x);205z[1] = evalsigne(1) | evallgefint(x);206return z;207}208INLINE GEN209cgetineg(long x)210{211GEN z = cgeti(x);212z[1] = evalsigne(-1) | evallgefint(x);213return z;214}215INLINE GEN216cgetr_block(long x)217{218GEN z = newblock((size_t)x);219z[0] = CLONEBIT | evaltyp(t_REAL) | evallg(x);220return z;221}222INLINE GEN223cgetr(long x)224{225GEN z = new_chunk((size_t)x);226z[0] = evaltyp(t_REAL) | evallg(x);227return z;228}229230/*******************************************************************/231/* */232/* COPY, NEGATION, ABSOLUTE VALUE */233/* */234/*******************************************************************/235/* cannot do memcpy because sometimes x and y overlap */236INLINE GEN237leafcopy(GEN x)238{239register long lx = lg(x);240GEN y = new_chunk(lx); /* can't use cgetg_copy, in case x,y overlap */241while (--lx > 0) y[lx] = x[lx];242y[0] = x[0] & (TYPBITS|LGBITS); return y;243}244INLINE GEN245icopy(GEN x)246{247long i = lgefint(x), lx = i;248GEN y = new_chunk(lx); /* can't use cgeti, in case x,y overlap */249while (--i > 0) y[i] = x[i];250y[0] = evaltyp(t_INT) | evallg(lx);251return y;252}253INLINE GEN254icopyspec(GEN x, long nx)255{256long i = nx+2, lx = i;257GEN y = new_chunk(lx); /* can't use cgeti, in case x,y overlap */258x -= 2; while (--i >= 2) y[i] = x[i];259y[1] = evalsigne(1) | evallgefint(lx);260y[0] = evaltyp(t_INT) | evallg(lx);261return y;262}263INLINE GEN rcopy(GEN x) { return leafcopy(x); }264INLINE GEN mpcopy(GEN x) { return leafcopy(x); }265266INLINE GEN267mpabs(GEN x) { GEN y = leafcopy(x); setabssign(y); return y; }268INLINE GEN269mpabs_shallow(GEN x) { return signe(x) < 0? mpabs(x): x; }270INLINE GEN absi(GEN x) { return mpabs(x); }271INLINE GEN absi_shallow(GEN x) { return signe(x) < 0? negi(x): x; }272INLINE GEN absr(GEN x) { return mpabs(x); }273274INLINE GEN275mpneg(GEN x) { GEN y = leafcopy(x); togglesign(y); return y; }276INLINE GEN negi(GEN x) { return mpneg(x); }277INLINE GEN negr(GEN x) { return mpneg(x); }278279/* negate in place */280INLINE void281togglesign(GEN x) { if (x[1] & SIGNBITS) { x[1] ^= HIGHBIT; } }282INLINE void283setabssign(GEN x) { x[1] &= ~HIGHBIT; }284/* negate in place, except universal constants */285INLINE void286togglesign_safe(GEN *px)287{288switch(*px - gen_1) /* gen_1, gen_2, gen_m1, gen_m2 */289{290case 0: *px = gen_m1; break;291case 3: *px = gen_m2; break;292case 6: *px = gen_1; break;293case 9: *px = gen_2; break;294default: togglesign(*px);295}296}297/* setsigne(y, signe(x)) */298INLINE void299affectsign(GEN x, GEN y)300{301y[1] = (x[1] & SIGNBITS) | (y[1] & ~SIGNBITS);302}303/* copies sign in place, except for universal constants */304INLINE void305affectsign_safe(GEN x, GEN *py)306{307if (((*py)[1] ^ x[1]) & HIGHBIT) togglesign_safe(py);308}309/*******************************************************************/310/* */311/* GEN -> LONG, LONG -> GEN */312/* */313/*******************************************************************/314/* assume x != 0, return -x as a t_INT */315INLINE GEN316utoineg(ulong x) { GEN y = cgetineg(3); y[2] = x; return y; }317/* assume x != 0, return utoi(x) */318INLINE GEN319utoipos(ulong x) { GEN y = cgetipos(3); y[2] = x; return y; }320INLINE GEN321utoi(ulong x) { return x? utoipos(x): gen_0; }322INLINE GEN323stoi(long x)324{325if (!x) return gen_0;326return x > 0? utoipos((ulong)x): utoineg((ulong)-x);327}328329/* x 2^BIL + y */330INLINE GEN331uutoi(ulong x, ulong y)332{333GEN z;334if (!x) return utoi(y);335z = cgetipos(4);336*int_W_lg(z, 1, 4) = x;337*int_W_lg(z, 0, 4) = y; return z;338}339/* - (x 2^BIL + y) */340INLINE GEN341uutoineg(ulong x, ulong y)342{343GEN z;344if (!x) return y? utoineg(y): gen_0;345z = cgetineg(4);346*int_W_lg(z, 1, 4) = x;347*int_W_lg(z, 0, 4) = y; return z;348}349350INLINE long351itos(GEN x)352{353long s = signe(x);354long u;355356if (!s) return 0;357u = x[2];358if (lgefint(x) > 3 || u < 0)359pari_err_OVERFLOW("t_INT-->long assignment");360return (s>0) ? u : -u;361}362/* as itos, but return 0 if too large. Cf is_bigint */363INLINE long364itos_or_0(GEN x) {365long n;366if (lgefint(x) != 3 || (n = x[2]) & HIGHBIT) return 0;367return signe(x) > 0? n: -n;368}369INLINE ulong370itou(GEN x)371{372switch(lgefint(x)) {373case 2: return 0;374case 3: return x[2];375default:376pari_err_OVERFLOW("t_INT-->ulong assignment");377return 0; /* LCOV_EXCL_LINE */378}379}380381/* as itou, but return 0 if too large. Cf is_bigint */382INLINE ulong383itou_or_0(GEN x) {384if (lgefint(x) != 3) return 0;385return (ulong)x[2];386}387388INLINE ulong389umuluu_or_0(ulong x, ulong y)390{391ulong z;392LOCAL_HIREMAINDER;393z = mulll(x, y);394return hiremainder? 0: z;395}396/* return x*y if <= n, else 0. Beware overflow */397INLINE ulong398umuluu_le(ulong x, ulong y, ulong n)399{400ulong z;401LOCAL_HIREMAINDER;402z = mulll(x, y);403return (hiremainder || z > n)? 0: z;404}405406INLINE GEN407real_0_bit(long bitprec) { GEN x=cgetr(2); x[1]=evalexpo(bitprec); return x; }408INLINE GEN409real_0(long prec) { return real_0_bit(-prec2nbits(prec)); }410INLINE GEN411real_1_bit(long bit) { return real_1(nbits2prec(bit)); }412INLINE GEN413real_1(long prec) {414GEN x = cgetr(prec);415long i;416x[1] = evalsigne(1) | _evalexpo(0);417x[2] = (long)HIGHBIT; for (i=3; i<prec; i++) x[i] = 0;418return x;419}420INLINE GEN421real_m1(long prec) {422GEN x = cgetr(prec);423long i;424x[1] = evalsigne(-1) | _evalexpo(0);425x[2] = (long)HIGHBIT; for (i=3; i<prec; i++) x[i] = 0;426return x;427}428429/* 2.^n */430INLINE GEN431real2n(long n, long prec) { GEN z = real_1(prec); setexpo(z, n); return z; }432INLINE GEN433real_m2n(long n, long prec) { GEN z = real_m1(prec); setexpo(z, n); return z; }434INLINE GEN435stor(long s, long prec) { GEN z = cgetr(prec); affsr(s,z); return z; }436INLINE GEN437utor(ulong s, long prec){ GEN z = cgetr(prec); affur(s,z); return z; }438INLINE GEN439itor(GEN x, long prec) { GEN z = cgetr(prec); affir(x,z); return z; }440INLINE GEN441rtor(GEN x, long prec) { GEN z = cgetr(prec); affrr(x,z); return z; }442443INLINE ulong int_bit(GEN x, long n)444{445long r, q = dvmdsBIL(n, &r);446return q < lgefint(x)-2?((ulong)*int_W(x,q) >> r) & 1UL:0;447}448449/*******************************************************************/450/* */451/* COMPARISON */452/* */453/*******************************************************************/454INLINE int455cmpss(long a, long b)456{ return a>b? 1: (a<b? -1: 0); }457458INLINE int459cmpuu(ulong a, ulong b)460{ return a>b? 1: (a<b? -1: 0); }461462INLINE int463cmpir(GEN x, GEN y)464{465pari_sp av;466GEN z;467468if (!signe(x)) return -signe(y);469if (!signe(y))470{471if (expo(y) >= expi(x)) return 0;472return signe(x);473}474av=avma; z = itor(x, realprec(y)); set_avma(av);475return cmprr(z,y); /* cmprr does no memory adjustment */476}477INLINE int478cmpri(GEN x, GEN y) { return -cmpir(y,x); }479INLINE int480cmpsr(long x, GEN y)481{482pari_sp av;483GEN z;484485if (!x) return -signe(y);486av=avma; z = stor(x, LOWDEFAULTPREC); set_avma(av);487return cmprr(z,y);488}489INLINE int490cmprs(GEN x, long y) { return -cmpsr(y,x); }491/* compare x and y */492INLINE int493cmpui(ulong x, GEN y)494{495ulong p;496if (!x) return -signe(y);497if (signe(y) <= 0) return 1;498if (lgefint(y) > 3) return -1;499p = y[2]; if (p == x) return 0;500return p < x ? 1 : -1;501}502INLINE int503cmpiu(GEN x, ulong y) { return -cmpui(y,x); }504/* compare x and |y| */505INLINE int506abscmpui(ulong x, GEN y)507{508long l = lgefint(y);509ulong p;510511if (!x) return (l > 2)? -1: 0;512if (l == 2) return 1;513if (l > 3) return -1;514p = y[2]; if (p == x) return 0;515return p < x ? 1 : -1;516}517INLINE int518abscmpiu(GEN x, ulong y) { return -abscmpui(y,x); }519INLINE int520cmpsi(long x, GEN y)521{522ulong p;523524if (!x) return -signe(y);525526if (x > 0)527{528if (signe(y)<=0) return 1;529if (lgefint(y)>3) return -1;530p = y[2]; if (p == (ulong)x) return 0;531return p < (ulong)x ? 1 : -1;532}533534if (signe(y)>=0) return -1;535if (lgefint(y)>3) return 1;536p = y[2]; if (p == (ulong)-x) return 0;537return p < (ulong)(-x) ? -1 : 1;538}539INLINE int540cmpis(GEN x, long y) { return -cmpsi(y,x); }541INLINE int542mpcmp(GEN x, GEN y)543{544if (typ(x)==t_INT)545return (typ(y)==t_INT) ? cmpii(x,y) : cmpir(x,y);546return (typ(y)==t_INT) ? -cmpir(y,x) : cmprr(x,y);547}548549/* x == y ? */550INLINE int551equalui(ulong x, GEN y)552{553if (!x) return !signe(y);554if (signe(y) <= 0 || lgefint(y) != 3) return 0;555return ((ulong)y[2] == (ulong)x);556}557/* x == y ? */558INLINE int559equalsi(long x, GEN y)560{561if (!x) return !signe(y);562if (x > 0)563{564if (signe(y) <= 0 || lgefint(y) != 3) return 0;565return ((ulong)y[2] == (ulong)x);566}567if (signe(y) >= 0 || lgefint(y) != 3) return 0;568return ((ulong)y[2] == (ulong)-x);569}570/* x == |y| ? */571INLINE int572absequalui(ulong x, GEN y)573{574if (!x) return !signe(y);575return (lgefint(y) == 3 && (ulong)y[2] == x);576}577INLINE int578absequaliu(GEN x, ulong y) { return absequalui(y,x); }579INLINE int580equalis(GEN x, long y) { return equalsi(y,x); }581INLINE int582equaliu(GEN x, ulong y) { return equalui(y,x); }583584/* assume x != 0, is |x| == 2^n ? */585INLINE int586absrnz_equal2n(GEN x) {587if ((ulong)x[2]==HIGHBIT)588{589long i, lx = lg(x);590for (i = 3; i < lx; i++)591if (x[i]) return 0;592return 1;593}594return 0;595}596/* assume x != 0, is |x| == 1 ? */597INLINE int598absrnz_equal1(GEN x) { return !expo(x) && absrnz_equal2n(x); }599600INLINE long601maxss(long x, long y) { return x>y?x:y; }602INLINE long603minss(long x, long y) { return x<y?x:y; }604INLINE long605minuu(ulong x, ulong y) { return x<y?x:y; }606INLINE long607maxuu(ulong x, ulong y) { return x>y?x:y; }608INLINE double609maxdd(double x, double y) { return x>y?x:y; }610INLINE double611mindd(double x, double y) { return x<y?x:y; }612613/*******************************************************************/614/* */615/* ADD / SUB */616/* */617/*******************************************************************/618INLINE GEN619subuu(ulong x, ulong y)620{621ulong z;622LOCAL_OVERFLOW;623z = subll(x, y);624return overflow? utoineg(-z): utoi(z);625}626INLINE GEN627adduu(ulong x, ulong y) { ulong t = x+y; return uutoi((t < x), t); }628629INLINE GEN630addss(long x, long y)631{632if (!x) return stoi(y);633if (!y) return stoi(x);634if (x > 0) return y > 0? adduu(x,y): subuu(x, -y);635636if (y > 0) return subuu(y, -x);637else { /* - adduu(-x, -y) */638ulong t = (-x)+(-y); return uutoineg((t < (ulong)(-x)), t);639}640}641INLINE GEN subss(long x, long y) { return addss(-y,x); }642643INLINE GEN644subii(GEN x, GEN y)645{646if (x==y) return gen_0; /* frequent with x = y = gen_0 */647return addii_sign(x, signe(x), y, -signe(y));648}649INLINE GEN650addii(GEN x, GEN y) { return addii_sign(x, signe(x), y, signe(y)); }651INLINE GEN652addrr(GEN x, GEN y) { return addrr_sign(x, signe(x), y, signe(y)); }653INLINE GEN654subrr(GEN x, GEN y) { return addrr_sign(x, signe(x), y, -signe(y)); }655INLINE GEN656addir(GEN x, GEN y) { return addir_sign(x, signe(x), y, signe(y)); }657INLINE GEN658subir(GEN x, GEN y) { return addir_sign(x, signe(x), y, -signe(y)); }659INLINE GEN660subri(GEN x, GEN y) { return addir_sign(y, -signe(y), x, signe(x)); }661INLINE GEN662addsi(long x, GEN y) { return addsi_sign(x, y, signe(y)); }663INLINE GEN664addui(ulong x, GEN y) { return addui_sign(x, y, signe(y)); }665INLINE GEN666subsi(long x, GEN y) { return addsi_sign(x, y, -signe(y)); }667INLINE GEN668subui(ulong x, GEN y) { return addui_sign(x, y, -signe(y)); }669670/*******************************************************************/671/* */672/* MOD, REM, DIV */673/* */674/*******************************************************************/675INLINE ulong mod2BIL(GEN x) { return *int_LSW(x); }676INLINE long mod64(GEN x) { return mod2BIL(x) & 63; }677INLINE long mod32(GEN x) { return mod2BIL(x) & 31; }678INLINE long mod16(GEN x) { return mod2BIL(x) & 15; }679INLINE long mod8(GEN x) { return mod2BIL(x) & 7; }680INLINE long mod4(GEN x) { return mod2BIL(x) & 3; }681INLINE long mod2(GEN x) { return mod2BIL(x) & 1; }682INLINE int683mpodd(GEN x) { return signe(x) && mod2(x); }684/* x mod 2^n, n < BITS_IN_LONG */685INLINE ulong686umodi2n(GEN x, long n)687{688long s = signe(x);689const ulong _2n = 1UL << n;690ulong m;691if (!s) return 0;692m = *int_LSW(x) & (_2n - 1);693if (s < 0 && m) m = _2n - m;694return m;695}696INLINE ulong Mod64(GEN x){ return umodi2n(x,6); }697INLINE ulong Mod32(GEN x){ return umodi2n(x,5); }698INLINE ulong Mod16(GEN x){ return umodi2n(x,4); }699INLINE ulong Mod8(GEN x) { return umodi2n(x,3); }700INLINE ulong Mod4(GEN x) { return umodi2n(x,2); }701INLINE ulong Mod2(GEN x) { return umodi2n(x,1); }702703INLINE GEN704truedivii(GEN a,GEN b) { return truedvmdii(a,b,NULL); }705INLINE GEN706truedivis(GEN a, long b) { return truedvmdis(a,b,NULL); }707INLINE GEN708truedivsi(long a, GEN b) { return truedvmdsi(a,b,NULL); }709710INLINE GEN711divii(GEN a, GEN b) { return dvmdii(a,b,NULL); }712INLINE GEN713remii(GEN a, GEN b) { return dvmdii(a,b,ONLY_REM); }714715INLINE GEN716divss(long x, long y) { return stoi(x / y); }717INLINE GEN718modss(long x, long y) { return utoi(smodss(x, y)); }719INLINE GEN720remss(long x, long y) { return stoi(x % y); }721INLINE long722smodss(long x, long y)723{724long r = x%y;725return (r >= 0)? r: labs(y) + r;726}727INLINE ulong728umodsu(long x, ulong y)729{730return x>=0 ? x%y: Fl_neg((-x)%y, y);731}732733INLINE long734sdivss_rem(long x, long y, long *r)735{736long q;737LOCAL_HIREMAINDER;738if (!y) pari_err_INV("sdivss_rem",gen_0);739hiremainder = 0; q = divll((ulong)labs(x),(ulong)labs(y));740if (x < 0) { hiremainder = -((long)hiremainder); q = -q; }741if (y < 0) q = -q;742*r = hiremainder; return q;743}744INLINE GEN745divss_rem(long x, long y, long *r) { return stoi(sdivss_rem(x,y,r)); }746INLINE ulong747udivuu_rem(ulong x, ulong y, ulong *r)748{749if (!y) pari_err_INV("udivuu_rem",gen_0);750*r = x % y; return x / y;751}752INLINE ulong753ceildivuu(ulong a, ulong b)754{755ulong c = a/b;756return (a%b)? c+1: c;757}758759INLINE ulong760uabsdivui_rem(ulong x, GEN y, ulong *r)761{762long q, s = signe(y);763LOCAL_HIREMAINDER;764765if (!s) pari_err_INV("uabsdivui_rem",gen_0);766if (!x || lgefint(y)>3) { *r = x; return 0; }767hiremainder=0; q = (long)divll(x, (ulong)y[2]);768if (s < 0) q = -q;769*r = hiremainder; return q;770}771772/* assume d != 0 and |n| / d can be represented as an ulong.773* Return |n|/d, set *r = |n| % d */774INLINE ulong775uabsdiviu_rem(GEN n, ulong d, ulong *r)776{777switch(lgefint(n))778{779case 2: *r = 0; return 0;780case 3:781{782ulong nn = n[2];783*r = nn % d; return nn / d;784}785default: /* 4 */786{787ulong n1, n0, q;788LOCAL_HIREMAINDER;789n0 = *int_W(n,0);790n1 = *int_W(n,1);791hiremainder = n1;792q = divll(n0, d);793*r = hiremainder; return q;794}795}796}797798INLINE long799sdivsi_rem(long x, GEN y, long *r)800{801long q, s = signe(y);802LOCAL_HIREMAINDER;803804if (!s) pari_err_INV("sdivsi_rem",gen_0);805if (!x || lgefint(y)>3 || ((long)y[2]) < 0) { *r = x; return 0; }806hiremainder=0; q = (long)divll(labs(x), (ulong)y[2]);807if (x < 0) { hiremainder = -((long)hiremainder); q = -q; }808if (s < 0) q = -q;809*r = hiremainder; return q;810}811INLINE GEN812divsi_rem(long s, GEN y, long *r) { return stoi(sdivsi_rem(s,y,r)); }813814INLINE long815sdivsi(long x, GEN y)816{817long q, s = signe(y);818819if (!s) pari_err_INV("sdivsi",gen_0);820if (!x || lgefint(y)>3 || ((long)y[2]) < 0) return 0;821q = labs(x) / y[2];822if (x < 0) q = -q;823if (s < 0) q = -q;824return q;825}826827INLINE GEN828dvmdss(long x, long y, GEN *z)829{830long r;831GEN q = divss_rem(x,y, &r);832*z = stoi(r); return q;833}834INLINE long835dvmdsBIL(long n, long *r) { *r = remsBIL(n); return divsBIL(n); }836INLINE ulong837dvmduBIL(ulong n, ulong *r) { *r = remsBIL(n); return divsBIL(n); }838INLINE GEN839dvmdsi(long x, GEN y, GEN *z)840{841long r;842GEN q = divsi_rem(x,y, &r);843*z = stoi(r); return q;844}845INLINE GEN846dvmdis(GEN x, long y, GEN *z)847{848long r;849GEN q = divis_rem(x,y, &r);850*z = stoi(r); return q;851}852853INLINE long854smodis(GEN x, long y)855{856pari_sp av = avma;857long r; (void)divis_rem(x,y, &r);858return gc_long(av, (r >= 0)? r: labs(y) + r);859}860INLINE GEN861modis(GEN x, long y) { return stoi(smodis(x,y)); }862INLINE GEN863modsi(long x, GEN y) {864long r; (void)sdivsi_rem(x, y, &r);865return (r >= 0)? stoi(r): addsi_sign(r, y, 1);866}867868INLINE ulong869umodui(ulong x, GEN y)870{871if (!signe(y)) pari_err_INV("umodui",gen_0);872if (!x || lgefint(y) > 3) return x;873return x % (ulong)y[2];874}875876INLINE ulong877ugcdiu(GEN x, ulong y) { return ugcd(umodiu(x,y), y); }878INLINE ulong879ugcdui(ulong y, GEN x) { return ugcd(umodiu(x,y), y); }880881INLINE GEN882remsi(long x, GEN y)883{ long r; (void)sdivsi_rem(x,y, &r); return stoi(r); }884INLINE GEN885remis(GEN x, long y)886{887pari_sp av = avma;888long r;889(void)divis_rem(x,y, &r); set_avma(av); return stoi(r);890}891892INLINE GEN893rdivis(GEN x, long y, long prec)894{895GEN z = cgetr(prec);896pari_sp av = avma;897affrr(divrs(itor(x,prec), y),z);898set_avma(av); return z;899}900INLINE GEN901rdivsi(long x, GEN y, long prec)902{903GEN z = cgetr(prec);904pari_sp av = avma;905affrr(divsr(x, itor(y,prec)), z);906set_avma(av); return z;907}908INLINE GEN909rdivss(long x, long y, long prec)910{911GEN z = cgetr(prec);912pari_sp av = avma;913affrr(divrs(stor(x, prec), y), z);914set_avma(av); return z;915}916917INLINE void918rdiviiz(GEN x, GEN y, GEN z)919{920long prec = realprec(z), lx = lgefint(x), ly = lgefint(y);921if (lx == 2) { affur(0, z); return; }922if (ly == 3)923{924affir(x, z); if (signe(y) < 0) togglesign(z);925affrr(divru(z, y[2]), z);926}927else if (lx > prec + 1 || ly > prec + 1)928{929affir(x,z); affrr(divri(z, y), z);930}931else932{933long b = bit_accuracy(prec) + expi(y) - expi(x) + 1;934GEN q = divii(b > 0? shifti(x, b): x, y);935affir(q, z); if (b > 0) shiftr_inplace(z, -b);936}937set_avma((ulong)z);938}939INLINE GEN940rdivii(GEN x, GEN y, long prec)941{ GEN z = cgetr(prec); rdiviiz(x, y, z); return z; }942INLINE GEN943fractor(GEN x, long prec)944{ return rdivii(gel(x,1), gel(x,2), prec); }945946INLINE int947dvdii(GEN x, GEN y)948{949pari_sp av = avma;950GEN r;951if (!signe(x)) return 1;952if (!signe(y)) return 0;953r = remii(x,y);954return gc_bool(av, r == gen_0);955}956INLINE int957dvdsi(long x, GEN y)958{959if (x == 0) return 1;960if (!signe(y)) return 0;961if (lgefint(y) != 3) return 0;962return x % y[2] == 0;963}964INLINE int965dvdui(ulong x, GEN y)966{967if (x == 0) return 1;968if (!signe(y)) return 0;969if (lgefint(y) != 3) return 0;970return x % y[2] == 0;971}972INLINE int973dvdis(GEN x, long y)974{ return y? smodis(x, y) == 0: signe(x) == 0; }975INLINE int976dvdiu(GEN x, ulong y)977{ return y? umodiu(x, y) == 0: signe(x) == 0; }978979INLINE int980dvdisz(GEN x, long y, GEN z)981{982const pari_sp av = avma;983long r;984GEN p1 = divis_rem(x,y, &r);985set_avma(av); if (r) return 0;986affii(p1,z); return 1;987}988INLINE int989dvdiuz(GEN x, ulong y, GEN z)990{991const pari_sp av = avma;992ulong r;993GEN p1 = absdiviu_rem(x,y, &r);994set_avma(av); if (r) return 0;995affii(p1,z); return 1;996}997INLINE int998dvdiiz(GEN x, GEN y, GEN z)999{1000const pari_sp av=avma;1001GEN p2, p1 = dvmdii(x,y,&p2);1002if (signe(p2)) return gc_bool(av,0);1003affii(p1,z); return gc_bool(av,1);1004}10051006INLINE ulong1007remlll_pre(ulong u2, ulong u1, ulong u0, ulong n, ulong ninv)1008{1009u1 = remll_pre(u2, u1, n, ninv);1010return remll_pre(u1, u0, n, ninv);1011}10121013INLINE ulong1014Fl_sqr_pre(ulong a, ulong p, ulong pi)1015{1016register ulong x;1017LOCAL_HIREMAINDER;1018x = mulll(a,a);1019return remll_pre(hiremainder, x, p, pi);1020}10211022INLINE ulong1023Fl_mul_pre(ulong a, ulong b, ulong p, ulong pi)1024{1025register ulong x;1026LOCAL_HIREMAINDER;1027x = mulll(a,b);1028return remll_pre(hiremainder, x, p, pi);1029}10301031INLINE ulong1032Fl_addmul_pre(ulong y0, ulong x0, ulong x1, ulong p, ulong pi)1033{1034ulong l0, h0;1035LOCAL_HIREMAINDER;1036hiremainder = y0;1037l0 = addmul(x0, x1); h0 = hiremainder;1038return remll_pre(h0, l0, p, pi);1039}10401041INLINE ulong1042Fl_addmulmul_pre(ulong x0, ulong y0, ulong x1, ulong y1, ulong p, ulong pi)1043{1044ulong l0, l1, h0, h1;1045LOCAL_OVERFLOW;1046LOCAL_HIREMAINDER;1047l0 = mulll(x0, y0); h0 = hiremainder;1048l1 = mulll(x1, y1); h1 = hiremainder;1049l0 = addll(l0, l1); h0 = addllx(h0, h1);1050return overflow ? remlll_pre(1, h0, l0, p, pi): remll_pre(h0, l0, p, pi);1051}10521053INLINE ulong1054Fl_ellj_pre(ulong a4, ulong a6, ulong p, ulong pi)1055{1056/* a43 = 4 a4^3 */1057ulong a43 = Fl_double(Fl_double(1058Fl_mul_pre(a4, Fl_sqr_pre(a4, p, pi), p, pi), p), p);1059/* a62 = 27 a6^2 */1060ulong a62 = Fl_mul_pre(Fl_sqr_pre(a6, p, pi), 27 % p, p, pi);1061ulong z1 = Fl_mul_pre(a43, 1728 % p, p, pi);1062ulong z2 = Fl_add(a43, a62, p);1063return Fl_div(z1, z2, p);1064}10651066/*******************************************************************/1067/* */1068/* MP (INT OR REAL) */1069/* */1070/*******************************************************************/1071INLINE GEN1072mptrunc(GEN x) { return typ(x)==t_INT? icopy(x): truncr(x); }1073INLINE GEN1074mpfloor(GEN x) { return typ(x)==t_INT? icopy(x): floorr(x); }1075INLINE GEN1076mpceil(GEN x) { return typ(x)==t_INT? icopy(x): ceilr(x); }1077INLINE GEN1078mpround(GEN x) { return typ(x) == t_INT? icopy(x): roundr(x); }10791080INLINE long1081mpexpo(GEN x) { return typ(x) == t_INT? expi(x): expo(x); }10821083INLINE GEN1084mpadd(GEN x, GEN y)1085{1086if (typ(x)==t_INT)1087return (typ(y)==t_INT) ? addii(x,y) : addir(x,y);1088return (typ(y)==t_INT) ? addir(y,x) : addrr(x,y);1089}1090INLINE GEN1091mpsub(GEN x, GEN y)1092{1093if (typ(x)==t_INT)1094return (typ(y)==t_INT) ? subii(x,y) : subir(x,y);1095return (typ(y)==t_INT) ? subri(x,y) : subrr(x,y);1096}1097INLINE GEN1098mpmul(GEN x, GEN y)1099{1100if (typ(x)==t_INT)1101return (typ(y)==t_INT) ? mulii(x,y) : mulir(x,y);1102return (typ(y)==t_INT) ? mulir(y,x) : mulrr(x,y);1103}1104INLINE GEN1105mpsqr(GEN x) { return (typ(x)==t_INT) ? sqri(x) : sqrr(x); }1106INLINE GEN1107mpdiv(GEN x, GEN y)1108{1109if (typ(x)==t_INT)1110return (typ(y)==t_INT) ? divii(x,y) : divir(x,y);1111return (typ(y)==t_INT) ? divri(x,y) : divrr(x,y);1112}11131114/*******************************************************************/1115/* */1116/* Z/nZ, n ULONG */1117/* */1118/*******************************************************************/1119INLINE ulong1120Fl_double(ulong a, ulong p)1121{1122ulong res = a << 1;1123return (res >= p || res < a) ? res - p : res;1124}1125INLINE ulong1126Fl_triple(ulong a, ulong p)1127{1128ulong res = a << 1;1129if (res >= p || res < a) res -= p;1130res += a;1131return (res >= p || res < a)? res - p: res;1132}1133INLINE ulong1134Fl_halve(ulong a, ulong p)1135{1136ulong ap, ap2;1137if ((a&1UL)==0) return a>>1;1138ap = a + p; ap2 = ap>>1;1139return ap>=a ? ap2: (ap2|HIGHBIT);1140}11411142INLINE ulong1143Fl_add(ulong a, ulong b, ulong p)1144{1145ulong res = a + b;1146return (res >= p || res < a) ? res - p : res;1147}1148INLINE ulong1149Fl_neg(ulong x, ulong p) { return x ? p - x: 0; }11501151INLINE ulong1152Fl_sub(ulong a, ulong b, ulong p)1153{1154ulong res = a - b;1155return (res > a) ? res + p: res;1156}11571158/* centerlift(u mod p) */1159INLINE long1160Fl_center(ulong u, ulong p, ulong ps2) { return (long) (u > ps2)? u - p: u; }11611162INLINE ulong1163Fl_mul(ulong a, ulong b, ulong p)1164{1165register ulong x;1166LOCAL_HIREMAINDER;1167x = mulll(a,b);1168if (!hiremainder) return x % p;1169(void)divll(x,p); return hiremainder;1170}1171INLINE ulong1172Fl_sqr(ulong a, ulong p)1173{1174register ulong x;1175LOCAL_HIREMAINDER;1176x = mulll(a,a);1177if (!hiremainder) return x % p;1178(void)divll(x,p); return hiremainder;1179}1180/* don't assume that p is prime: can't special case a = 0 */1181INLINE ulong1182Fl_div(ulong a, ulong b, ulong p)1183{ return Fl_mul(a, Fl_inv(b, p), p); }11841185/*******************************************************************/1186/* */1187/* DEFINED FROM EXISTING ONE EXPLOITING COMMUTATIVITY */1188/* */1189/*******************************************************************/1190INLINE GEN1191addri(GEN x, GEN y) { return addir(y,x); }1192INLINE GEN1193addis(GEN x, long s) { return addsi(s,x); }1194INLINE GEN1195addiu(GEN x, ulong s) { return addui(s,x); }1196INLINE GEN1197addrs(GEN x, long s) { return addsr(s,x); }11981199INLINE GEN1200subiu(GEN x, long y) { GEN z = subui(y, x); togglesign(z); return z; }1201INLINE GEN1202subis(GEN x, long y) { return addsi(-y,x); }1203INLINE GEN1204subrs(GEN x, long y) { return addsr(-y,x); }12051206INLINE GEN1207mulis(GEN x, long s) { return mulsi(s,x); }1208INLINE GEN1209muliu(GEN x, ulong s) { return mului(s,x); }1210INLINE GEN1211mulru(GEN x, ulong s) { return mulur(s,x); }1212INLINE GEN1213mulri(GEN x, GEN s) { return mulir(s,x); }1214INLINE GEN1215mulrs(GEN x, long s) { return mulsr(s,x); }12161217/*******************************************************************/1218/* */1219/* VALUATION, EXPONENT, SHIFTS */1220/* */1221/*******************************************************************/1222INLINE long1223vali(GEN x)1224{1225long i;1226GEN xp;12271228if (!signe(x)) return -1;1229xp=int_LSW(x);1230for (i=0; !*xp; i++) xp=int_nextW(xp);1231return vals(*xp) + i * BITS_IN_LONG;1232}12331234/* assume x > 0 */1235INLINE long1236expu(ulong x) { return (BITS_IN_LONG-1) - (long)bfffo(x); }12371238INLINE long1239expi(GEN x)1240{1241const long lx=lgefint(x);1242return lx==2? -(long)HIGHEXPOBIT: bit_accuracy(lx)-(long)bfffo(*int_MSW(x))-1;1243}12441245INLINE GEN1246shiftr(GEN x, long n)1247{1248const long e = evalexpo(expo(x)+n);1249const GEN y = rcopy(x);12501251if (e & ~EXPOBITS) pari_err_OVERFLOW("expo()");1252y[1] = (y[1]&~EXPOBITS) | e; return y;1253}1254INLINE GEN1255mpshift(GEN x,long s) { return (typ(x)==t_INT)?shifti(x,s):shiftr(x,s); }12561257/* FIXME: adapt/use mpn_[lr]shift instead */1258/* z2[imin..imax] := z1[imin..imax].f shifted left sh bits1259* (feeding f from the right). Assume sh > 0 */1260INLINE void1261shift_left(GEN z2, GEN z1, long imin, long imax, ulong f, ulong sh)1262{1263GEN sb = z1 + imin, se = z1 + imax, te = z2 + imax;1264ulong l, m = BITS_IN_LONG - sh, k = f >> m;1265while (se > sb) {1266l = *se--;1267*te-- = (l << sh) | k;1268k = l >> m;1269}1270*te = (((ulong)*se) << sh) | k;1271}1272/* z2[imin..imax] := f.z1[imin..imax-1] shifted right sh bits1273* (feeding f from the left). Assume sh > 0 */1274INLINE void1275shift_right(GEN z2, GEN z1, long imin, long imax, ulong f, ulong sh)1276{1277GEN sb = z1 + imin, se = z1 + imax, tb = z2 + imin;1278ulong k, l = *sb++, m = BITS_IN_LONG - sh;1279*tb++ = (l >> sh) | (f << m);1280while (sb < se) {1281k = l << m;1282l = *sb++;1283*tb++ = (l >> sh) | k;1284}1285}12861287/* Backward compatibility. Inefficient && unused */1288extern ulong hiremainder;1289INLINE ulong1290shiftl(ulong x, ulong y)1291{ hiremainder = x>>(BITS_IN_LONG-y); return (x<<y); }12921293INLINE ulong1294shiftlr(ulong x, ulong y)1295{ hiremainder = x<<(BITS_IN_LONG-y); return (x>>y); }12961297INLINE void1298shiftr_inplace(GEN z, long d)1299{1300setexpo(z, expo(z)+d);1301}13021303/*******************************************************************/1304/* */1305/* ASSIGNMENT */1306/* */1307/*******************************************************************/1308INLINE void1309affii(GEN x, GEN y)1310{1311long lx = lgefint(x);1312if (lg(y)<lx) pari_err_OVERFLOW("t_INT-->t_INT assignment");1313while (--lx) y[lx] = x[lx];1314}1315INLINE void1316affsi(long s, GEN x)1317{1318if (!s) x[1] = evalsigne(0) | evallgefint(2);1319else1320{1321if (s > 0) { x[1] = evalsigne( 1) | evallgefint(3); x[2] = s; }1322else { x[1] = evalsigne(-1) | evallgefint(3); x[2] = -s; }1323}1324}1325INLINE void1326affui(ulong u, GEN x)1327{1328if (!u) x[1] = evalsigne(0) | evallgefint(2);1329else { x[1] = evalsigne(1) | evallgefint(3); x[2] = u; }1330}13311332INLINE void1333affsr(long x, GEN y)1334{1335long sh, i, ly = lg(y);13361337if (!x)1338{1339y[1] = evalexpo(-prec2nbits(ly));1340return;1341}1342if (x < 0) {1343x = -x; sh = bfffo(x);1344y[1] = evalsigne(-1) | _evalexpo((BITS_IN_LONG-1)-sh);1345}1346else1347{1348sh = bfffo(x);1349y[1] = evalsigne(1) | _evalexpo((BITS_IN_LONG-1)-sh);1350}1351y[2] = ((ulong)x)<<sh; for (i=3; i<ly; i++) y[i]=0;1352}13531354INLINE void1355affur(ulong x, GEN y)1356{1357long sh, i, ly = lg(y);13581359if (!x)1360{1361y[1] = evalexpo(-prec2nbits(ly));1362return;1363}1364sh = bfffo(x);1365y[1] = evalsigne(1) | _evalexpo((BITS_IN_LONG-1)-sh);1366y[2] = x<<sh; for (i=3; i<ly; i++) y[i] = 0;1367}13681369INLINE void1370affiz(GEN x, GEN y) { if (typ(y)==t_INT) affii(x,y); else affir(x,y); }1371INLINE void1372affsz(long x, GEN y) { if (typ(y)==t_INT) affsi(x,y); else affsr(x,y); }1373INLINE void1374mpaff(GEN x, GEN y) { if (typ(x)==t_INT) affiz(x, y); else affrr(x,y); }13751376/*******************************************************************/1377/* */1378/* OPERATION + ASSIGNMENT */1379/* */1380/*******************************************************************/13811382INLINE void addiiz(GEN x, GEN y, GEN z)1383{ pari_sp av = avma; affii(addii(x,y),z); set_avma(av); }1384INLINE void addirz(GEN x, GEN y, GEN z)1385{ pari_sp av = avma; affrr(addir(x,y),z); set_avma(av); }1386INLINE void addriz(GEN x, GEN y, GEN z)1387{ pari_sp av = avma; affrr(addri(x,y),z); set_avma(av); }1388INLINE void addrrz(GEN x, GEN y, GEN z)1389{ pari_sp av = avma; affrr(addrr(x,y),z); set_avma(av); }1390INLINE void addsiz(long s, GEN y, GEN z)1391{ pari_sp av = avma; affii(addsi(s,y),z); set_avma(av); }1392INLINE void addsrz(long s, GEN y, GEN z)1393{ pari_sp av = avma; affrr(addsr(s,y),z); set_avma(av); }1394INLINE void addssz(long s, long y, GEN z)1395{ pari_sp av = avma; affii(addss(s,y),z); set_avma(av); }13961397INLINE void diviiz(GEN x, GEN y, GEN z)1398{ pari_sp av = avma; affii(divii(x,y),z); set_avma(av); }1399INLINE void divirz(GEN x, GEN y, GEN z)1400{ pari_sp av = avma; mpaff(divir(x,y),z); set_avma(av); }1401INLINE void divisz(GEN x, long y, GEN z)1402{ pari_sp av = avma; affii(divis(x,y),z); set_avma(av); }1403INLINE void divriz(GEN x, GEN y, GEN z)1404{ pari_sp av = avma; affrr(divri(x,y),z); set_avma(av); }1405INLINE void divrrz(GEN x, GEN y, GEN z)1406{ pari_sp av = avma; affrr(divrr(x,y),z); set_avma(av); }1407INLINE void divrsz(GEN y, long s, GEN z)1408{ pari_sp av = avma; affrr(divrs(y,s),z); set_avma(av); }1409INLINE void divsiz(long x, GEN y, GEN z)1410{ long junk; affsi(sdivsi_rem(x,y,&junk), z); }1411INLINE void divsrz(long s, GEN y, GEN z)1412{ pari_sp av = avma; mpaff(divsr(s,y),z); set_avma(av); }1413INLINE void divssz(long x, long y, GEN z)1414{ affsi(x/y, z); }14151416INLINE void modisz(GEN y, long s, GEN z)1417{ affsi(smodis(y,s),z); }1418INLINE void modsiz(long s, GEN y, GEN z)1419{ pari_sp av = avma; affii(modsi(s,y),z); set_avma(av); }1420INLINE void modssz(long s, long y, GEN z)1421{ affsi(smodss(s,y),z); }14221423INLINE void mpaddz(GEN x, GEN y, GEN z)1424{ pari_sp av = avma; mpaff(mpadd(x,y),z); set_avma(av); }1425INLINE void mpsubz(GEN x, GEN y, GEN z)1426{ pari_sp av = avma; mpaff(mpsub(x,y),z); set_avma(av); }1427INLINE void mpmulz(GEN x, GEN y, GEN z)1428{ pari_sp av = avma; mpaff(mpmul(x,y),z); set_avma(av); }14291430INLINE void muliiz(GEN x, GEN y, GEN z)1431{ pari_sp av = avma; affii(mulii(x,y),z); set_avma(av); }1432INLINE void mulirz(GEN x, GEN y, GEN z)1433{ pari_sp av = avma; mpaff(mulir(x,y),z); set_avma(av); }1434INLINE void mulriz(GEN x, GEN y, GEN z)1435{ pari_sp av = avma; mpaff(mulri(x,y),z); set_avma(av); }1436INLINE void mulrrz(GEN x, GEN y, GEN z)1437{ pari_sp av = avma; affrr(mulrr(x,y),z); set_avma(av); }1438INLINE void mulsiz(long s, GEN y, GEN z)1439{ pari_sp av = avma; affii(mulsi(s,y),z); set_avma(av); }1440INLINE void mulsrz(long s, GEN y, GEN z)1441{ pari_sp av = avma; mpaff(mulsr(s,y),z); set_avma(av); }1442INLINE void mulssz(long s, long y, GEN z)1443{ pari_sp av = avma; affii(mulss(s,y),z); set_avma(av); }14441445INLINE void remiiz(GEN x, GEN y, GEN z)1446{ pari_sp av = avma; affii(remii(x,y),z); set_avma(av); }1447INLINE void remisz(GEN y, long s, GEN z)1448{ pari_sp av = avma; affii(remis(y,s),z); set_avma(av); }1449INLINE void remsiz(long s, GEN y, GEN z)1450{ pari_sp av = avma; affii(remsi(s,y),z); set_avma(av); }1451INLINE void remssz(long s, long y, GEN z)1452{ pari_sp av = avma; affii(remss(s,y),z); set_avma(av); }14531454INLINE void subiiz(GEN x, GEN y, GEN z)1455{ pari_sp av = avma; affii(subii(x,y),z); set_avma(av); }1456INLINE void subirz(GEN x, GEN y, GEN z)1457{ pari_sp av = avma; affrr(subir(x,y),z); set_avma(av); }1458INLINE void subisz(GEN y, long s, GEN z)1459{ pari_sp av = avma; affii(addsi(-s,y),z); set_avma(av); }1460INLINE void subriz(GEN x, GEN y, GEN z)1461{ pari_sp av = avma; affrr(subri(x,y),z); set_avma(av); }1462INLINE void subrrz(GEN x, GEN y, GEN z)1463{ pari_sp av = avma; affrr(subrr(x,y),z); set_avma(av); }1464INLINE void subrsz(GEN y, long s, GEN z)1465{ pari_sp av = avma; affrr(addsr(-s,y),z); set_avma(av); }1466INLINE void subsiz(long s, GEN y, GEN z)1467{ pari_sp av = avma; affii(subsi(s,y),z); set_avma(av); }1468INLINE void subsrz(long s, GEN y, GEN z)1469{ pari_sp av = avma; affrr(subsr(s,y),z); set_avma(av); }1470INLINE void subssz(long x, long y, GEN z) { addssz(x,-y,z); }14711472INLINE void1473dvmdssz(long x, long y, GEN z, GEN t) {1474pari_sp av = avma;1475long r;1476affii(divss_rem(x,y, &r), z); set_avma(av); affsi(r,t);1477}1478INLINE void1479dvmdsiz(long x, GEN y, GEN z, GEN t) {1480pari_sp av = avma;1481long r;1482affii(divsi_rem(x,y, &r), z); set_avma(av); affsi(r,t);1483}1484INLINE void1485dvmdisz(GEN x, long y, GEN z, GEN t) {1486pari_sp av = avma;1487long r;1488affii(divis_rem(x,y, &r),z); set_avma(av); affsi(r,t);1489}1490INLINE void1491dvmdiiz(GEN x, GEN y, GEN z, GEN t) {1492pari_sp av = avma;1493GEN r;1494affii(dvmdii(x,y,&r),z); affii(r,t); set_avma(av);1495}149614971498