GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
#include "typedef.h"12/**************************************************************************\3@---------------------------------------------------------------------------4@---------------------------------------------------------------------------5@ FILE: chin_remainder.c6@---------------------------------------------------------------------------7@---------------------------------------------------------------------------8@9\**************************************************************************/10/**************************************************************************\11@-------------------------------------------------------------------------12@ chinrest(x1, x2, p1, p2) calculates for positive primes p1,p213@ and integers x1, x2 an integer x with14@ -(p1*p2)/2 < x < (p1*p2)/2 and15@ x kongruent x1 modulo p1 and x konguent x2 modulo p216@-------------------------------------------------------------------------17\**************************************************************************/18int chin_remainder(x1, x2, p1, p2)19int x1, x2, p1, p2;20{2122int a1, a2;23double q, q1, q2, res, waste;24int y1, y2;2526a1 = p_inv(p2, p1);27a2 = p_inv(p1, p2);28q = ((double) p1) * ((double) p2);29q1 = ((double) p2) * ((double) a1);30q2 = ((double) p1) * ((double) a2);3132y1 = x1%p1;33if(2*y1 <= -p1)34y1 +=p1;35if(2*y1 > p1)36y1 -=p1;37y2 = x2%p2;38if(2*y2 <= -p2)39y2 +=p2;40if(2*y2 > p2)41y2 -=p2;42if(y1 == y2)43return(y1);44res = ((double) y1) * q1 + ((double) y2) * q2;45modf(res/q, &waste);46res = res - waste * q;47while( (res/q) > 0.5)48res = res -q;49while( (res/q) < -0.5)50res = res + q;51return(((int) res));52}535455