arb/acb/atan.c

82 lines
1.7 KiB
C
Raw Normal View History

/*
2015-01-14 15:17:38 +01:00
Copyright (C) 2015 Fredrik Johansson
This file is part of Arb.
Arb is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. See <http://www.gnu.org/licenses/>.
*/
2015-01-14 15:17:38 +01:00
#include "acb.h"
/* branch cuts are on (+/-i)*[1,inf] */
int
acb_atan_on_branch_cut(const acb_t z)
{
arb_t unit;
int result;
if (!acb_is_finite(z))
return 1;
if (arb_is_nonzero(acb_realref(z)))
return 0;
if (arb_contains_si(acb_imagref(z), 1) || arb_contains_si(acb_imagref(z), -1))
return 1;
arb_init(unit);
mag_one(arb_radref(unit));
result = !arb_contains(unit, acb_imagref(z));
arb_clear(unit);
return result;
}
void
2015-11-05 17:43:36 +00:00
acb_atan(acb_t r, const acb_t z, slong prec)
2015-01-14 15:17:38 +01:00
{
if (arb_is_zero(acb_imagref(z)))
{
arb_atan(acb_realref(r), acb_realref(z), prec);
arb_zero(acb_imagref(r));
}
else if (!acb_is_finite(z))
{
acb_indeterminate(r);
}
else
{
acb_t t, u;
acb_init(t);
acb_init(u);
if (acb_atan_on_branch_cut(z))
{
acb_mul_onei(u, z);
acb_neg(t, u);
acb_log1p(t, t, prec);
acb_log1p(u, u, prec);
acb_sub(t, t, u, prec);
}
else
{
acb_onei(t);
acb_sub(t, t, z, prec);
acb_div(t, z, t, prec);
acb_mul_2exp_si(t, t, 1);
acb_log1p(t, t, prec);
}
acb_mul_onei(t, t);
acb_mul_2exp_si(r, t, -1);
acb_clear(t);
acb_clear(u);
}
}