Testing latest pari + WASM + node.js... and it works?! Wow.
License: GPL3
ubuntu2004
/* Copyright (C) 2000 The PARI group.12This file is part of the PARI/GP package.34PARI/GP is free software; you can redistribute it and/or modify it under the5terms of the GNU General Public License as published by the Free Software6Foundation; either version 2 of the License, or (at your option) any later7version. It is distributed in the hope that it will be useful, but WITHOUT8ANY WARRANTY WHATSOEVER.910Check the License for details. You should have received a copy of it, along11with the package; see the file 'COPYING'. If not, write to the Free Software12Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */1314/* This file is a slight adaptation of source code extracted from gmp-3.1.115(from T. Granlund), files longlong.h and gmp-impl.h1617Copyright (C) 2000 Free Software Foundation, Inc.1819* FIXME: This file is unused until somebody implements20* invert_word(x) = return floor( 2^(2*BIL)/x ) */2122extern ulong invert_word(ulong);2324#define sub_ddmmss(sh, sl, ah, al, bh, bl) \25do { \26ulong __x; \27__x = (al) - (bl); \28(sh) = (ah) - (bh) - (__x > (al)); \29(sl) = __x; \30} while (0)3132#ifdef __GNUC__3334#define divll(x, y) \35__extension__ ({ \36register ulong _di, _x = (x), _y = (y), _q, _ql, _r; \37register ulong _xh, _xl, _k, __hire; \38\39if (_y & 0x8000000000000000UL) \40{ _k = 0; __hire = hiremainder; } \41else \42{ \43_k = bfffo(_y); \44__hire = (hiremainder << _k) | (_x >> (64 - _k)); \45_x <<= _k; _y <<= _k; \46} \47_di = invert_word(_y); \48_ql = mulll (__hire, _di); \49_q = __hire + hiremainder; \50_xl = mulll(_q, _y); _xh = hiremainder; \51sub_ddmmss (_xh, _r, __hire, _x, _xh, _xl); \52if (_xh != 0) \53{ \54sub_ddmmss (_xh, _r, _xh, _r, 0, _y); _q += 1; \55if (_xh != 0) \56{ sub_ddmmss (_xh, _r, _xh, _r, 0, _y); _q += 1; } \57} \58if (_r >= _y) \59{ _r -= _y; _q += 1; } \60hiremainder = _r >> _k; \61_q; \62})6364#else /* __GNUC__ */6566static ulong67divll(ulong x, ulong y)68{69register ulong _di, _x = (x), _y = (y), _q, _ql, _r;70register ulong _xh, _xl, _k, __hire;7172if (_y & 0x8000000000000000UL)73{ _k = 0; __hire = hiremainder; }74else75{76_k = bfffo(_y);77__hire = (hiremainder << _k) | (_x >> (64 - _k));78_x <<= _k; _y <<= _k;79}80_di = invert_word(_y);81_ql = mulll (__hire, _di);82_q = __hire + hiremainder;83_xl = mulll(_q, _y); _xh = hiremainder;84sub_ddmmss (_xh, _r, __hire, _x, _xh, _xl);85if (_xh != 0)86{87sub_ddmmss (_xh, _r, _xh, _r, 0, _y); _q += 1;88if (_xh != 0)89{ sub_ddmmss (_xh, _r, _xh, _r, 0, _y); _q += 1; }90}91if (_r >= _y)92{ _r -= _y; _q += 1; }93hiremainder = _r >> _k;94return _q;95}9697#endif /* __GNUC__ */9899100