bridge/class-master/depend/pari/src/basemath/nffactor.c
/*******************************************************************/
/*              RATIONAL RECONSTRUCTION (use ratlift)              */
/*******************************************************************/
/* NOT stack clean. a, b stay on the stack */
RATIONAL RECONSTRUCTION (use ratlift)
NOT stack clean. a, b stay on the stack
RATIONAL RECONSTRUCTION ( use ratlift ) NOT stack clean . a b stay on the stack
static GEN
lift_to_frac_tdenom(GEN t, GEN mod, GEN amax, GEN bmax, GEN denom, GEN tdenom)
{
  GEN a, b;
  if (signe(t) < 0) t = addii(t, mod); 
  if (tdenom)
  {
    pari_sp av = avma;
    a = Fp_center_i(Fp_mul(t, tdenom, mod), mod, shifti(mod,-1));
    if (abscmpii(a, amax) < 0)
    {
      GEN d = gcdii(a, tdenom);
      a = diviiexact(a, d);
      b = diviiexact(tdenom, d);
      if (is_pm1(b)) { return gerepileuptoint(av, a); }
      return gerepilecopy(av, mkfrac(a, b));
    }
    avma = av;
  }
  if (!Fp_ratlift(t, mod, amax,bmax, &a,&b)
     || (denom && !dvdii(denom,b))
     || !is_pm1(gcdii(a,b))) return NULL;
  if (is_pm1(b)) { cgiv(b); return a; }
  return mkfrac(a, b);
}
static GEN lift_to_frac_tdenom ( GEN t , GEN mod , GEN amax , GEN bmax , GEN denom , GEN tdenom ) { GEN a , b ; if ( signe ( t ) < 0 ) t = addii ( t , mod ) ; if ( tdenom ) { pari_sp av = avma ; a = Fp_center_i ( Fp_mul ( t , tdenom , mod ) , mod , shifti ( mod , -1 ) ) ; if ( abscmpii ( a , amax ) < 0 ) { GEN d = gcdii ( a , tdenom ) ; a = diviiexact ( a , d ) ; b = diviiexact ( tdenom , d ) ; if ( is_pm1 ( b ) ) { return gerepileuptoint ( av , a ) ; } return gerepilecopy ( av , mkfrac ( a , b ) ) ; } avma = av ; } if ( ! Fp_ratlift ( t , mod , amax , bmax , & a , & b ) || ( denom && ! dvdii ( denom , b ) ) || ! is_pm1 ( gcdii ( a , b ) ) ) return NULL ; if ( is_pm1 ( b ) ) { cgiv ( b ) ; return a ; } return mkfrac ( a , b ) ; }
RATIONAL RECONSTRUCTION (use ratlift)
NOT stack clean.
RATIONAL RECONSTRUCTION ( use ratlift ) NOT stack clean .
/* in case t is a centerlift */