"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/basemath/trans1.c" between
pari-2.13.0.tar.gz and pari-2.13.1.tar.gz

About: PARI/GP is a computer algebra system designed for fast computations in number theory (factorizations, algebraic number theory, elliptic curves...), but also contains a large number of other mathematical functions.

trans1.c  (pari-2.13.0):trans1.c  (pari-2.13.1)
skipping to change at line 1220 skipping to change at line 1220
if (lg(x) == 2) return gerepilecopy(av, x); /* O(1) */ if (lg(x) == 2) return gerepilecopy(av, x); /* O(1) */
return gerepileupto(av, ser_pow(x, n, prec)); return gerepileupto(av, ser_pow(x, n, prec));
} }
if (gequal0(x)) return gpow0(x, n, prec); if (gequal0(x)) return gpow0(x, n, prec);
if (tn == t_FRAC) if (tn == t_FRAC)
{ {
GEN p, z, a = gel(n,1), d = gel(n,2); GEN p, z, a = gel(n,1), d = gel(n,2);
switch (tx) switch (tx)
{ {
case t_INT: case t_INT:
if (signe(x) < 0)
{
if (equaliu(d, 2) && Z_issquareall(negi(x), &z))
return gerepilecopy(av, mkcomplex(gen_0, powgi(z, a)));
break;
}
if (ispower(x, d, &z)) return powgi(z, a);
break;
case t_FRAC: case t_FRAC:
if (signe(gel(x,1)) < 0)
{
if (equaliu(d, 2) && ispower(absfrac(x), d, &z))
return gerepilecopy(av, mkcomplex(gen_0, powgi(z, a)));
break;
}
if (ispower(x, d, &z)) return powgi(z, a); if (ispower(x, d, &z)) return powgi(z, a);
break; break;
case t_INTMOD: case t_INTMOD:
p = gel(x,1); p = gel(x,1);
if (!BPSW_psp(p)) pari_err_PRIME("gpow",p); if (!BPSW_psp(p)) pari_err_PRIME("gpow",p);
y = cgetg(3,t_INTMOD); gel(y,1) = icopy(p); y = cgetg(3,t_INTMOD); gel(y,1) = icopy(p);
av = avma; av = avma;
z = Fp_sqrtn(gel(x,2), d, p, NULL); z = Fp_sqrtn(gel(x,2), d, p, NULL);
if (!z) pari_err_SQRTN("gpow",x); if (!z) pari_err_SQRTN("gpow",x);
skipping to change at line 1249 skipping to change at line 1263
return gerepileupto(av,FF_pow(FF_sqrtn(x,d,NULL),a)); return gerepileupto(av,FF_pow(FF_sqrtn(x,d,NULL),a));
} }
z = powfrac(x, n, prec); z = powfrac(x, n, prec);
if (z) return gerepileupto(av, z); if (z) return gerepileupto(av, z);
} }
if (tn == t_COMPLEX && is_real_t(typ(x)) && gsigne(x) > 0) if (tn == t_COMPLEX && is_real_t(typ(x)) && gsigne(x) > 0)
{ {
long p = powcx_prec(fabs(dbllog2(x)), n, prec); long p = powcx_prec(fabs(dbllog2(x)), n, prec);
return gerepileupto(av, powcx(x, glog(x, p), n, prec)); return gerepileupto(av, powcx(x, glog(x, p), n, prec));
} }
if (tn == t_PADIC) x = gcvtop(x, gel(n,2), precp(n));
i = precision(n); i = precision(n);
if (i) prec = i; if (i) prec = i;
prec0 = prec; prec0 = prec;
if (!gprecision(x)) if (!gprecision(x))
{ {
long e = gexpo_safe(n); /* avoided if n = 0 or gexpo not defined */ long e = gexpo_safe(n); /* avoided if n = 0 or gexpo not defined */
if (e > 2) prec += nbits2extraprec(e); if (e > 2) prec += nbits2extraprec(e);
} }
y = gmul(n, glog(x,prec)); y = gmul(n, glog(x,prec));
y = gexp(y,prec); y = gexp(y,prec);
skipping to change at line 3893 skipping to change at line 3908
{ {
pari_sp av = avma; pari_sp av = avma;
GEN s, c; GEN s, c;
mpsincos(x,&s,&c); mpsincos(x,&s,&c);
if (!signe(c)) if (!signe(c))
pari_err_DOMAIN("tan", "argument", "=", strtoGENstr("Pi/2 + kPi"),x); pari_err_DOMAIN("tan", "argument", "=", strtoGENstr("Pi/2 + kPi"),x);
return gerepileuptoleaf(av, divrr(s,c)); return gerepileuptoleaf(av, divrr(s,c));
} }
/* If exp(-|im(x)|) << 1, avoid overflow in sincos(x) */
static int
tan_huge_im(GEN ix, long prec)
{
long b, p = precision(ix);
if (!p) p = prec;
b = bit_accuracy(p);
return (gexpo(ix) > b || fabs(gtodouble(ix)) > (M_LN2 / 2) * b);
}
/* \pm I */
static GEN
real_I(long s, long prec)
{
GEN z = cgetg(3, t_COMPLEX);
gel(z,1) = real_0(prec);
gel(z,2) = s > 0? real_1(prec): real_m1(prec); return z;
}
GEN GEN
gtan(GEN x, long prec) gtan(GEN x, long prec)
{ {
pari_sp av; pari_sp av;
GEN y, s, c; GEN y, s, c;
switch(typ(x)) switch(typ(x))
{ {
case t_REAL: return mptan(x); case t_REAL: return mptan(x);
case t_COMPLEX: { case t_COMPLEX: {
if (isintzero(gel(x,1))) retmkcomplex(gen_0,gtanh(gel(x,2),prec)); if (isintzero(gel(x,1))) retmkcomplex(gen_0,gtanh(gel(x,2),prec));
if (tan_huge_im(gel(x,2), prec)) return real_I(gsigne(gel(x,2)), prec);
av = avma; y = mulcxmI(gtanh(mulcxI(x), prec)); /* tan x = -I th(I x) */ av = avma; y = mulcxmI(gtanh(mulcxI(x), prec)); /* tan x = -I th(I x) */
gel(y,1) = gcopy(gel(y,1)); gel(y,1) = gcopy(gel(y,1)); return gerepileupto(av, y);
return gerepileupto(av, y);
} }
case t_INT: case t_FRAC: case t_INT: case t_FRAC:
y = cgetr(prec); av = avma; y = cgetr(prec); av = avma;
affrr_fixlg(mptan(tofp_safe(x,prec)), y); return gc_const(av,y); affrr_fixlg(mptan(tofp_safe(x,prec)), y); return gc_const(av,y);
case t_PADIC: case t_PADIC:
av = avma; av = avma;
return gerepileupto(av, gdiv(gsin(x,prec), gcos(x,prec))); return gerepileupto(av, gdiv(gsin(x,prec), gcos(x,prec)));
default: default:
skipping to change at line 3952 skipping to change at line 3985
GEN y, s, c; GEN y, s, c;
switch(typ(x)) switch(typ(x))
{ {
case t_REAL: case t_REAL:
return mpcotan(x); return mpcotan(x);
case t_COMPLEX: case t_COMPLEX:
if (isintzero(gel(x,1))) { if (isintzero(gel(x,1))) {
GEN z = cgetg(3, t_COMPLEX); GEN z = cgetg(3, t_COMPLEX);
gel(z,1) = gen_0; gel(z,1) = gen_0; av = avma;
av = avma;
gel(z,2) = gerepileupto(av, gneg(ginv(gtanh(gel(x,2),prec)))); gel(z,2) = gerepileupto(av, gneg(ginv(gtanh(gel(x,2),prec))));
return z; return z;
} }
av = avma; if (tan_huge_im(gel(x,2), prec)) return real_I(-gsigne(gel(x,2)), prec);
gsincos(x,&s,&c,prec); av = avma; gsincos(x,&s,&c,prec);
return gerepileupto(av, gdiv(c,s)); return gerepileupto(av, gdiv(c,s));
case t_INT: case t_FRAC: case t_INT: case t_FRAC:
y = cgetr(prec); av = avma; y = cgetr(prec); av = avma;
affrr_fixlg(mpcotan(tofp_safe(x,prec)), y); return gc_const(av,y); affrr_fixlg(mpcotan(tofp_safe(x,prec)), y); return gc_const(av,y);
case t_PADIC: case t_PADIC:
av = avma; av = avma;
return gerepileupto(av, gdiv(gcos(x,prec), gsin(x,prec))); return gerepileupto(av, gdiv(gcos(x,prec), gsin(x,prec)));
 End of changes. 8 change blocks. 
6 lines changed or deleted 38 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)