Testing latest pari + WASM + node.js... and it works?! Wow.
License: GPL3
ubuntu2004
#line 2 "../src/kernel/none/cmp.c"1/* Copyright (C) 2002-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. */141516/********************************************************************/17/** **/18/** Comparison routines **/19/** **/20/********************************************************************/2122/*They depend on cmpiispec and equaliispec in mp.c*/2324int25equalii(GEN x, GEN y)26{27if ((x[1] & (LGBITS|SIGNBITS)) != (y[1] & (LGBITS|SIGNBITS))) return 0;28return equaliispec(x+2, y+2, lgefint(x)-2, lgefint(y)-2);29}3031int32cmpii(GEN x, GEN y)33{34const long sx = signe(x), sy = signe(y);35if (sx<sy) return -1;36if (sx>sy) return 1;37if (!sx) return 0;38if (sx>0)39return cmpiispec(x+2, y+2, lgefint(x)-2, lgefint(y)-2);40else41return -cmpiispec(x+2, y+2, lgefint(x)-2, lgefint(y)-2);42}4344int45equalrr(GEN x, GEN y)46{47long lx, ly, i;4849if (!signe(x)) {50if (!signe(y)) return 1; /* all zeroes are equal */51return expo(x) >= expo(y);52}53if (!signe(y))54return expo(y) >= expo(x);5556if (x[1] != y[1]) return 0;5758lx = lg(x);59ly = lg(y);60if (lx < ly)61{62i=2; while (i<lx && x[i]==y[i]) i++;63if (i<lx) return 0;64for (; i < ly; i++) if (y[i]) return 0;65}66else67{68i=2; while (i<ly && x[i]==y[i]) i++;69if (i<ly) return 0;70for (; i < lx; i++) if (x[i]) return 0;71}72return 1;73}7475int76cmprr(GEN x, GEN y)77{78const long sx = signe(x), sy = signe(y);79long ex,ey,lx,ly,lz,i;8081if (!sx) {82if (!sy || expo(x) >= expo(y)) return 0;83return sy > 0? -1: 1;84}85if (!sy) {86if (expo(y) >= expo(x)) return 0;87return sx > 0? 1: -1;88}89if (sx<sy) return -1;90if (sx>sy) return 1;9192ex=expo(x); ey=expo(y);93if (ex>ey) return sx;94if (ex<ey) return -sx;9596lx=lg(x); ly=lg(y); lz = (lx<ly)?lx:ly;97i=2; while (i<lz && x[i]==y[i]) i++;98if (i<lz) return ((ulong)x[i] > (ulong)y[i]) ? sx : -sx;99if (lx>=ly)100{101while (i<lx && !x[i]) i++;102return (i==lx) ? 0 : sx;103}104while (i<ly && !y[i]) i++;105return (i==ly) ? 0 : -sx;106}107108/* x and y are integers. Return 1 if |x| == |y|, 0 otherwise */109int110absequalii(GEN x, GEN y)111{112if (!signe(x)) return !signe(y);113if (!signe(y)) return 0;114return equaliispec(x+2, y+2, lgefint(x)-2, lgefint(y)-2);115}116117/* x and y are integers. Return sign(|x| - |y|) */118int119abscmpii(GEN x, GEN y)120{121if (!signe(x)) return signe(y)? -1: 0;122if (!signe(y)) return 1;123return cmpiispec(x+2, y+2, lgefint(x)-2, lgefint(y)-2);124}125126/* x and y are reals. Return sign(|x| - |y|) */127int128abscmprr(GEN x, GEN y)129{130long ex,ey,lx,ly,lz,i;131132if (!signe(x)) return signe(y)? -1: 0;133if (!signe(y)) return 1;134135ex=expo(x); ey=expo(y);136if (ex>ey) return 1;137if (ex<ey) return -1;138139lx=lg(x); ly=lg(y); lz = (lx<ly)?lx:ly;140i=2; while (i<lz && x[i]==y[i]) i++;141if (i<lz) return ((ulong)x[i] > (ulong)y[i])? 1: -1;142if (lx>=ly)143{144while (i<lx && !x[i]) i++;145return (i==lx)? 0: 1;146}147while (i<ly && !y[i]) i++;148return (i==ly)? 0: -1;149}150151152153