mirror of
https://github.com/vale981/arb
synced 2025-03-04 17:01:40 -05:00
more work on ball arithmetic
This commit is contained in:
parent
decf8ca7e6
commit
48ddeea5ef
40 changed files with 3406 additions and 60 deletions
650
arb.h
650
arb.h
|
@ -48,8 +48,12 @@ typedef const arb_struct * arb_srcptr;
|
|||
#define ARB_MIDREF(x) (&(x)->mid)
|
||||
#define ARB_RADREF(x) (&(x)->rad)
|
||||
|
||||
#define arb_midref ARB_MIDREF
|
||||
#define arb_radref ARB_RADREF
|
||||
|
||||
#define ARB_IS_LAGOM(x) (ARF_IS_LAGOM(ARB_MIDREF(x)) && MAG_IS_LAGOM(ARB_RADREF(x)))
|
||||
|
||||
#define ARB_RND ARF_RND_DOWN
|
||||
|
||||
static __inline__ void
|
||||
arb_init(arb_t x)
|
||||
|
@ -65,11 +69,25 @@ arb_clear(arb_t x)
|
|||
mag_clear(ARB_RADREF(x));
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_zero(arb_t x)
|
||||
static __inline__ arb_ptr
|
||||
_arb_vec_init(long n)
|
||||
{
|
||||
arf_zero(ARB_MIDREF(x));
|
||||
mag_zero(ARB_RADREF(x));
|
||||
long i;
|
||||
arb_ptr v = (arb_ptr) flint_malloc(sizeof(arb_struct) * n);
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
arb_init(v + i);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
_arb_vec_clear(arb_ptr v, long n)
|
||||
{
|
||||
long i;
|
||||
for (i = 0; i < n; i++)
|
||||
arb_clear(v + i);
|
||||
flint_free(v);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
|
@ -86,20 +104,630 @@ arb_get_fmprb(fmprb_t x, const arb_t y)
|
|||
mag_get_fmpr(fmprb_radref(x), ARB_RADREF(y));
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_printd(const arb_t y, long d)
|
||||
static __inline__ int
|
||||
arb_is_exact(const arb_t x)
|
||||
{
|
||||
fmprb_t t;
|
||||
fmprb_init(t);
|
||||
arb_get_fmprb(t, y);
|
||||
fmprb_printd(t, d);
|
||||
fmprb_clear(t);
|
||||
return mag_is_zero(arb_radref(x));
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
arb_equal(const arb_t x, const arb_t y)
|
||||
{
|
||||
return arf_equal(arb_midref(x), arb_midref(y)) &&
|
||||
mag_equal(arb_radref(x), arb_radref(y));
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_zero(arb_t x)
|
||||
{
|
||||
arf_zero(arb_midref(x));
|
||||
mag_zero(arb_radref(x));
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
arb_is_zero(const arb_t x)
|
||||
{
|
||||
return arf_is_zero(arb_midref(x)) && mag_is_zero(arb_radref(x));
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_pos_inf(arb_t x)
|
||||
{
|
||||
arf_pos_inf(arb_midref(x));
|
||||
mag_zero(arb_radref(x));
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_neg_inf(arb_t x)
|
||||
{
|
||||
arf_neg_inf(arb_midref(x));
|
||||
mag_zero(arb_radref(x));
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_zero_pm_inf(arb_t x)
|
||||
{
|
||||
arf_zero(arb_midref(x));
|
||||
mag_inf(arb_radref(x));
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_indeterminate(arb_t x)
|
||||
{
|
||||
arf_nan(arb_midref(x));
|
||||
mag_inf(arb_radref(x));
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
arb_is_finite(const arb_t x)
|
||||
{
|
||||
return arf_is_finite(arb_midref(x)) && mag_is_finite(arb_radref(x));
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_set(arb_t x, const arb_t y)
|
||||
{
|
||||
arf_set(arb_midref(x), arb_midref(y));
|
||||
mag_set(arb_radref(x), arb_radref(y));
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_swap(arb_t x, arb_t y)
|
||||
{
|
||||
arb_struct t = *x;
|
||||
*x = *y;
|
||||
*y = t;
|
||||
}
|
||||
|
||||
void arb_set_round(arb_t z, const arb_t x, long prec);
|
||||
|
||||
void arb_trim(arb_t y, const arb_t x);
|
||||
|
||||
static __inline__ void
|
||||
arb_neg(arb_t x, const arb_t y)
|
||||
{
|
||||
arf_neg(arb_midref(x), arb_midref(y));
|
||||
mag_set(arb_radref(x), arb_radref(y));
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_neg_round(arb_t x, const arb_t y, long prec)
|
||||
{
|
||||
arb_set_round(x, y, prec);
|
||||
arb_neg(x, x);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_abs(arb_t x, const arb_t y)
|
||||
{
|
||||
arf_abs(arb_midref(x), arb_midref(y));
|
||||
mag_set(arb_radref(x), arb_radref(y));
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_set_arf(arb_t x, const arf_t y)
|
||||
{
|
||||
arf_set(arb_midref(x), y);
|
||||
mag_zero(arb_radref(x));
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_set_si(arb_t x, long y)
|
||||
{
|
||||
arf_set_si(arb_midref(x), y);
|
||||
mag_zero(arb_radref(x));
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_set_ui(arb_t x, ulong y)
|
||||
{
|
||||
arf_set_ui(arb_midref(x), y);
|
||||
mag_zero(arb_radref(x));
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_set_fmpz(arb_t x, const fmpz_t y)
|
||||
{
|
||||
arf_set_fmpz(arb_midref(x), y);
|
||||
mag_zero(arb_radref(x));
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_set_fmpz_2exp(arb_t x, const fmpz_t y, const fmpz_t exp)
|
||||
{
|
||||
arf_set_fmpz_2exp(arb_midref(x), y, exp);
|
||||
mag_zero(arb_radref(x));
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_set_round_fmpz_2exp(arb_t y, const fmpz_t x, const fmpz_t exp, long prec)
|
||||
{
|
||||
int inexact;
|
||||
inexact = arf_set_round_fmpz_2exp(arb_midref(y), x, exp, prec, ARB_RND);
|
||||
|
||||
if (inexact)
|
||||
arf_mag_set_ulp(arb_radref(y), arb_midref(y), prec);
|
||||
else
|
||||
mag_zero(arb_radref(y));
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_set_round_fmpz(arb_t y, const fmpz_t x, long prec)
|
||||
{
|
||||
int inexact;
|
||||
inexact = arf_set_round_fmpz(arb_midref(y), x, prec, ARB_RND);
|
||||
|
||||
if (inexact)
|
||||
arf_mag_set_ulp(arb_radref(y), arb_midref(y), prec);
|
||||
else
|
||||
mag_zero(arb_radref(y));
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
arb_is_one(const arb_t f)
|
||||
{
|
||||
return arf_is_one(arb_midref(f)) && mag_is_zero(arb_radref(f));
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_one(arb_t f)
|
||||
{
|
||||
arb_set_ui(f, 1UL);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_print(const arb_t x)
|
||||
{
|
||||
arf_print(arb_midref(x));
|
||||
printf(" +/- ");
|
||||
mag_print(arb_radref(x));
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_printd(const arb_t x, long digits)
|
||||
{
|
||||
arf_printd(arb_midref(x), FLINT_ABS(digits));
|
||||
if (digits > 0)
|
||||
{
|
||||
printf(" +/- ");
|
||||
mag_printd(arb_radref(x), 5);
|
||||
}
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_mul_2exp_si(arb_t y, const arb_t x, long e)
|
||||
{
|
||||
arf_mul_2exp_si(arb_midref(y), arb_midref(x), e);
|
||||
mag_mul_2exp_si(arb_radref(y), arb_radref(x), e);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_mul_2exp_fmpz(arb_t y, const arb_t x, const fmpz_t e)
|
||||
{
|
||||
arf_mul_2exp_fmpz(arb_midref(y), arb_midref(x), e);
|
||||
mag_mul_2exp_fmpz(arb_radref(y), arb_radref(x), e);
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
arb_is_int(const arb_t x)
|
||||
{
|
||||
return mag_is_zero(arb_radref(x)) &&
|
||||
arf_is_int(arb_midref(x));
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
arb_contains_zero(const arb_t x)
|
||||
{
|
||||
return arf_cmpabs_mag(arb_midref(x), arb_radref(x)) <= 0;
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
arb_is_nonzero(const arb_t x)
|
||||
{
|
||||
return !arb_contains_zero(x);
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
arb_is_positive(const arb_t x)
|
||||
{
|
||||
return (arf_sgn(arb_midref(x)) > 0) &&
|
||||
(arf_mag_cmpabs(arb_radref(x), arb_midref(x)) < 0) &&
|
||||
!arf_is_nan(arb_midref(x));
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
arb_is_nonnegative(const arb_t x)
|
||||
{
|
||||
return (arf_sgn(arb_midref(x)) >= 0) &&
|
||||
(arf_mag_cmpabs(arb_radref(x), arb_midref(x)) <= 0) &&
|
||||
!arf_is_nan(arb_midref(x));
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
arb_is_negative(const arb_t x)
|
||||
{
|
||||
return (arf_sgn(arb_midref(x)) < 0) &&
|
||||
(arf_mag_cmpabs(arb_radref(x), arb_midref(x)) < 0) &&
|
||||
!arf_is_nan(arb_midref(x));
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
arb_is_nonpositive(const arb_t x)
|
||||
{
|
||||
return (arf_sgn(arb_midref(x)) <= 0) &&
|
||||
(arf_mag_cmpabs(arb_radref(x), arb_midref(x)) <= 0) &&
|
||||
!arf_is_nan(arb_midref(x));
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
arb_contains_negative(const arb_t x)
|
||||
{
|
||||
return (arf_sgn(arb_midref(x)) < 0) ||
|
||||
(arf_mag_cmpabs(arb_radref(x), arb_midref(x)) > 0)
|
||||
|| arf_is_nan(arb_midref(x));
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
arb_contains_nonpositive(const arb_t x)
|
||||
{
|
||||
return (arf_sgn(arb_midref(x)) <= 0) ||
|
||||
(arf_mag_cmpabs(arb_radref(x), arb_midref(x)) >= 0)
|
||||
|| arf_is_nan(arb_midref(x));
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
arb_contains_positive(const arb_t x)
|
||||
{
|
||||
return (arf_sgn(arb_midref(x)) > 0) ||
|
||||
(arf_mag_cmpabs(arb_radref(x), arb_midref(x)) > 0)
|
||||
|| arf_is_nan(arb_midref(x));
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
arb_contains_nonnegative(const arb_t x)
|
||||
{
|
||||
return (arf_sgn(arb_midref(x)) >= 0) ||
|
||||
(arf_mag_cmpabs(arb_radref(x), arb_midref(x)) >= 0)
|
||||
|| arf_is_nan(arb_midref(x));
|
||||
}
|
||||
|
||||
/* TODO: get/set mag versions */
|
||||
|
||||
static __inline__ void
|
||||
arb_get_abs_ubound_arf(arf_t u, const arb_t x, long prec)
|
||||
{
|
||||
arf_t t;
|
||||
arf_init_set_mag_shallow(t, arb_radref(x));
|
||||
|
||||
if (arf_sgn(arb_midref(x)) < 0)
|
||||
arf_sub(u, arb_midref(x), t, prec, ARF_RND_UP);
|
||||
else
|
||||
arf_add(u, arb_midref(x), t, prec, ARF_RND_UP);
|
||||
|
||||
arf_abs(u, u);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arb_get_abs_lbound_fmpr(arf_t u, const arb_t x, long prec)
|
||||
{
|
||||
arf_t t;
|
||||
arf_init_set_mag_shallow(t, arb_radref(x));
|
||||
|
||||
if (arf_sgn(arb_midref(x)) > 0)
|
||||
{
|
||||
arf_sub(u, arb_midref(x), t, prec, ARF_RND_UP);
|
||||
}
|
||||
else
|
||||
{
|
||||
arf_add(u, arb_midref(x), t, prec, ARF_RND_UP);
|
||||
arf_neg(u, u);
|
||||
}
|
||||
|
||||
if (arf_sgn(u) < 0)
|
||||
arf_zero(u);
|
||||
}
|
||||
|
||||
static __inline__ long
|
||||
arb_rel_error_bits(const arb_t x)
|
||||
{
|
||||
fmpz_t midmag, radmag;
|
||||
arf_t t;
|
||||
long result;
|
||||
|
||||
if (mag_is_zero(arb_radref(x)))
|
||||
return -ARF_PREC_EXACT;
|
||||
if (arf_is_special(arb_midref(x)) || mag_is_inf(arb_radref(x)))
|
||||
return ARF_PREC_EXACT;
|
||||
|
||||
fmpz_init(midmag);
|
||||
fmpz_init(radmag);
|
||||
|
||||
arf_abs_bound_lt_2exp_fmpz(midmag, arb_midref(x));
|
||||
|
||||
arf_init_set_mag_shallow(t, arb_radref(x)); /* no need to free */
|
||||
arf_abs_bound_lt_2exp_fmpz(radmag, t);
|
||||
fmpz_add_ui(radmag, radmag, 1);
|
||||
|
||||
result = _fmpz_sub_small(radmag, midmag);
|
||||
|
||||
fmpz_clear(midmag);
|
||||
fmpz_clear(radmag);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static __inline__ long
|
||||
arb_rel_accuracy_bits(const arb_t x)
|
||||
{
|
||||
return -arb_rel_error_bits(x);
|
||||
}
|
||||
|
||||
static __inline__ long
|
||||
arb_bits(const arb_t x)
|
||||
{
|
||||
return arf_bits(arb_midref(x));
|
||||
}
|
||||
|
||||
|
||||
/* vector functions */
|
||||
|
||||
static __inline__ void
|
||||
_arb_vec_zero(arb_ptr A, long n)
|
||||
{
|
||||
long i;
|
||||
for (i = 0; i < n; i++)
|
||||
arb_zero(A + i);
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
_arb_vec_is_zero(arb_srcptr vec, long len)
|
||||
{
|
||||
long i;
|
||||
for (i = 0; i < len; i++)
|
||||
if (!arb_is_zero(vec + i))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
_arb_vec_set(arb_ptr res, arb_srcptr vec, long len)
|
||||
{
|
||||
long i;
|
||||
for (i = 0; i < len; i++)
|
||||
arb_set(res + i, vec + i);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
_arb_vec_set_round(arb_ptr res, arb_srcptr vec, long len, long prec)
|
||||
{
|
||||
long i;
|
||||
for (i = 0; i < len; i++)
|
||||
arb_set_round(res + i, vec + i, prec);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
_arb_vec_swap(arb_ptr res, arb_ptr vec, long len)
|
||||
{
|
||||
long i;
|
||||
for (i = 0; i < len; i++)
|
||||
arb_swap(res + i, vec + i);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
_arb_vec_neg(arb_ptr B, arb_srcptr A, long n)
|
||||
{
|
||||
long i;
|
||||
for (i = 0; i < n; i++)
|
||||
arb_neg(B + i, A + i);
|
||||
}
|
||||
|
||||
/*
|
||||
static __inline__ void
|
||||
_arb_vec_sub(arb_ptr C, arb_srcptr A,
|
||||
arb_srcptr B, long n, long prec)
|
||||
{
|
||||
long i;
|
||||
for (i = 0; i < n; i++)
|
||||
arb_sub(C + i, A + i, B + i, prec);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
_arb_vec_add(arb_ptr C, arb_srcptr A,
|
||||
arb_srcptr B, long n, long prec)
|
||||
{
|
||||
long i;
|
||||
for (i = 0; i < n; i++)
|
||||
arb_add(C + i, A + i, B + i, prec);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
_arb_vec_scalar_mul(arb_ptr res, arb_srcptr vec,
|
||||
long len, const arb_t c, long prec)
|
||||
{
|
||||
long i;
|
||||
for (i = 0; i < len; i++)
|
||||
arb_mul(res + i, vec + i, c, prec);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
_arb_vec_scalar_div(arb_ptr res, arb_srcptr vec,
|
||||
long len, const arb_t c, long prec)
|
||||
{
|
||||
long i;
|
||||
for (i = 0; i < len; i++)
|
||||
arb_div(res + i, vec + i, c, prec);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
_arb_vec_scalar_mul_fmpz(arb_ptr res, arb_srcptr vec,
|
||||
long len, const fmpz_t c, long prec)
|
||||
{
|
||||
long i;
|
||||
arf_t t;
|
||||
arf_init(t);
|
||||
arf_set_fmpz(t, c);
|
||||
for (i = 0; i < len; i++)
|
||||
arb_mul_arf(res + i, vec + i, t, prec);
|
||||
arf_clear(t);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
_arb_vec_scalar_mul_2exp_si(arb_ptr res, arb_srcptr src, long len, long c)
|
||||
{
|
||||
long i;
|
||||
for (i = 0; i < len; i++)
|
||||
arb_mul_2exp_si(res + i, src + i, c);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
_arb_vec_scalar_addmul(arb_ptr res, arb_srcptr vec,
|
||||
long len, const arb_t c, long prec)
|
||||
{
|
||||
long i;
|
||||
for (i = 0; i < len; i++)
|
||||
arb_addmul(res + i, vec + i, c, prec);
|
||||
}
|
||||
*/
|
||||
|
||||
/* TODO: mag version? */
|
||||
static __inline__ void
|
||||
_arb_vec_get_abs_ubound_arf(arf_t bound, arb_srcptr vec,
|
||||
long len, long prec)
|
||||
{
|
||||
arf_t t;
|
||||
long i;
|
||||
|
||||
if (len < 1)
|
||||
{
|
||||
arf_zero(bound);
|
||||
}
|
||||
else
|
||||
{
|
||||
arb_get_abs_ubound_arf(bound, vec, prec);
|
||||
arf_init(t);
|
||||
for (i = 1; i < len; i++)
|
||||
{
|
||||
arb_get_abs_ubound_arf(t, vec + i, prec);
|
||||
if (arf_cmp(t, bound) > 0)
|
||||
arf_set(bound, t);
|
||||
}
|
||||
arf_clear(t);
|
||||
}
|
||||
}
|
||||
|
||||
static __inline__ long
|
||||
_arb_vec_bits(arb_srcptr x, long len)
|
||||
{
|
||||
long i, b, c;
|
||||
|
||||
b = 0;
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
c = arb_bits(x + i);
|
||||
b = FLINT_MAX(b, c);
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
/*
|
||||
static __inline__ void
|
||||
_arb_vec_set_powers(arb_ptr xs, const arb_t x, long len, long prec)
|
||||
{
|
||||
long i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
arb_one(xs + i);
|
||||
else if (i == 1)
|
||||
arb_set_round(xs + i, x, prec);
|
||||
else if (i % 2 == 0)
|
||||
arb_mul(xs + i, xs + i / 2, xs + i / 2, prec);
|
||||
else
|
||||
arb_mul(xs + i, xs + i - 1, x, prec);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/* TODO: mag verision ? */
|
||||
/*
|
||||
static __inline__ void
|
||||
_arb_vec_add_error_arf_vec(arb_ptr res, arf_srcptr err, long len)
|
||||
{
|
||||
long i;
|
||||
for (i = 0; i < len; i++)
|
||||
arb_add_error_arf(res + i, err + i);
|
||||
}
|
||||
*/
|
||||
|
||||
static __inline__ void
|
||||
_arb_vec_indeterminate(arb_ptr vec, long len)
|
||||
{
|
||||
long i;
|
||||
for (i = 0; i < len; i++)
|
||||
arb_indeterminate(vec + i);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
_arb_vec_trim(arb_ptr res, arb_srcptr vec, long len)
|
||||
{
|
||||
long i;
|
||||
for (i = 0; i < len; i++)
|
||||
arb_trim(res + i, vec + i);
|
||||
}
|
||||
|
||||
void arb_mul(arb_t z, const arb_t x, const arb_t y, long prec);
|
||||
|
||||
void arb_addmul(arb_t z, const arb_t x, const arb_t y, long prec);
|
||||
|
||||
/*
|
||||
static __inline__ void
|
||||
arb_set_fmpq(arb_t y, const fmpq_t x, long prec)
|
||||
{
|
||||
arb_fmpz_div_fmpz(y, fmpq_numref(x), fmpq_denref(x), prec);
|
||||
}
|
||||
*/
|
||||
|
||||
void arb_randtest_exact(arb_t x, flint_rand_t state, long prec, long mag_bits);
|
||||
|
||||
void arb_randtest_wide(arb_t x, flint_rand_t state, long prec, long mag_bits);
|
||||
|
||||
void arb_randtest_precise(arb_t x, flint_rand_t state, long prec, long mag_bits);
|
||||
|
||||
void arb_randtest(arb_t x, flint_rand_t state, long prec, long mag_bits);
|
||||
|
||||
void arb_randtest_special(arb_t x, flint_rand_t state, long prec, long mag_bits);
|
||||
|
||||
void arb_add_error_arf(arb_t x, const arf_t err);
|
||||
|
||||
void arb_add_error_2exp_si(arb_t x, long err);
|
||||
|
||||
void arb_add_error_2exp_fmpz(arb_t x, const fmpz_t err);
|
||||
|
||||
void arb_add_error(arb_t x, const arb_t error);
|
||||
|
||||
int arb_contains_arf(const arb_t x, const arf_t y);
|
||||
|
||||
int arb_contains_fmpq(const arb_t x, const fmpq_t y);
|
||||
|
||||
int arb_contains_fmpz(const arb_t x, const fmpz_t y);
|
||||
|
||||
int arb_contains_si(const arb_t x, long y);
|
||||
|
||||
int arb_contains_mpfr(const arb_t x, const mpfr_t y);
|
||||
|
||||
int arb_overlaps(const arb_t x, const arb_t y);
|
||||
|
||||
int arb_contains(const arb_t x, const arb_t y);
|
||||
|
||||
void arb_get_interval_fmpz_2exp(fmpz_t a, fmpz_t b, fmpz_t exp, const arb_t x);
|
||||
int arb_get_unique_fmpz(fmpz_t z, const arb_t x);
|
||||
void arb_set_interval_arf(arb_t x, const arf_t a, const arf_t b, long prec);
|
||||
void arb_union(arb_t z, const arb_t x, const arb_t y, long prec);
|
||||
void arb_get_rand_fmpq(fmpq_t q, flint_rand_t state, const arb_t x, long bits);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
34
arb/addmul.c
34
arb/addmul.c
|
@ -25,34 +25,6 @@
|
|||
|
||||
#include "arb.h"
|
||||
|
||||
void mag_add_arf_ulp(mag_t r, const arf_t z, long prec)
|
||||
{
|
||||
if (ARF_IS_SPECIAL(z))
|
||||
{
|
||||
printf("error: ulp error not defined for special value!\n");
|
||||
abort();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* todo: speed up case r is special here */
|
||||
fmpz_t e;
|
||||
fmpz_init(e);
|
||||
_fmpz_add_fast(e, ARF_EXPREF(z), -prec);
|
||||
mag_add_2exp_fmpz(r, r, e);
|
||||
fmpz_clear(e);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
mag_print(const mag_t x)
|
||||
{
|
||||
fmpr_t t;
|
||||
fmpr_init(t);
|
||||
mag_get_fmpr(t, x);
|
||||
fmpr_printd(t, 5);
|
||||
fmpr_clear(t);
|
||||
}
|
||||
|
||||
void
|
||||
arb_addmul_slow(arb_t z, const arb_t x, const arb_t y, long prec)
|
||||
{
|
||||
|
@ -71,9 +43,9 @@ arb_addmul_slow(arb_t z, const arb_t x, const arb_t y, long prec)
|
|||
prec, ARF_RND_DOWN);
|
||||
|
||||
if (inexact)
|
||||
mag_add_arf_ulp(zr, ARB_MIDREF(z), prec);
|
||||
|
||||
mag_set(ARB_RADREF(z), zr); /* swap? */
|
||||
arf_mag_add_ulp(ARB_RADREF(z), zr, ARB_MIDREF(z), prec);
|
||||
else
|
||||
mag_set(ARB_RADREF(z), zr);
|
||||
|
||||
mag_clear(zr);
|
||||
mag_clear(xm);
|
||||
|
|
47
arb/contains.c
Normal file
47
arb/contains.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012, 2013 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
int
|
||||
arb_contains(const arb_t x, const arb_t y)
|
||||
{
|
||||
fmprb_t t, u;
|
||||
int result;
|
||||
|
||||
fmprb_init(t);
|
||||
fmprb_init(u);
|
||||
|
||||
arb_get_fmprb(t, x);
|
||||
arb_get_fmprb(u, y);
|
||||
|
||||
result = fmprb_contains(t, u);
|
||||
|
||||
fmprb_clear(t);
|
||||
fmprb_clear(u);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
48
arb/contains_arf.c
Normal file
48
arb/contains_arf.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
int
|
||||
arb_contains_arf(const arb_t x, const arf_t y)
|
||||
{
|
||||
fmprb_t t;
|
||||
fmpr_t u;
|
||||
int result;
|
||||
|
||||
fmprb_init(t);
|
||||
fmpr_init(u);
|
||||
|
||||
arb_get_fmprb(t, x);
|
||||
arf_get_fmpr(u, y);
|
||||
|
||||
result = fmprb_contains_fmpr(t, u);
|
||||
|
||||
fmprb_clear(t);
|
||||
fmpr_clear(u);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
44
arb/contains_fmpq.c
Normal file
44
arb/contains_fmpq.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
int
|
||||
arb_contains_fmpq(const arb_t x, const fmpq_t y)
|
||||
{
|
||||
fmprb_t t;
|
||||
int result;
|
||||
|
||||
fmprb_init(t);
|
||||
|
||||
arb_get_fmprb(t, x);
|
||||
|
||||
result = fmprb_contains_fmpq(t, y);
|
||||
|
||||
fmprb_clear(t);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
39
arb/contains_fmpz.c
Normal file
39
arb/contains_fmpz.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
int
|
||||
arb_contains_fmpz(const arb_t x, const fmpz_t y)
|
||||
{
|
||||
int ans;
|
||||
arf_t t;
|
||||
arf_init(t);
|
||||
arf_set_fmpz(t, y);
|
||||
ans = arb_contains_arf(x, t);
|
||||
arf_clear(t);
|
||||
return ans;
|
||||
}
|
||||
|
38
arb/contains_mpfr.c
Normal file
38
arb/contains_mpfr.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
int
|
||||
arb_contains_mpfr(const arb_t x, const mpfr_t y)
|
||||
{
|
||||
int ans;
|
||||
arf_t t;
|
||||
arf_init(t);
|
||||
arf_set_mpfr(t, y);
|
||||
ans = arb_contains_arf(x, t);
|
||||
arf_clear(t);
|
||||
return ans;
|
||||
}
|
39
arb/contains_si.c
Normal file
39
arb/contains_si.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
int
|
||||
arb_contains_si(const arb_t x, long y)
|
||||
{
|
||||
int ans;
|
||||
arf_t t;
|
||||
arf_init(t);
|
||||
arf_set_si(t, y);
|
||||
ans = arb_contains_arf(x, t);
|
||||
arf_clear(t);
|
||||
return ans;
|
||||
}
|
||||
|
36
arb/get_interval_fmpz_2exp.c
Normal file
36
arb/get_interval_fmpz_2exp.c
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
void
|
||||
arb_get_interval_fmpz_2exp(fmpz_t a, fmpz_t b, fmpz_t exp, const arb_t x)
|
||||
{
|
||||
fmprb_t t;
|
||||
fmprb_init(t);
|
||||
arb_get_fmprb(t, x);
|
||||
fmprb_get_interval_fmpz_2exp(a, b, exp, t);
|
||||
fmprb_clear(t);
|
||||
}
|
37
arb/get_rand_fmpq.c
Normal file
37
arb/get_rand_fmpq.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
void
|
||||
arb_get_rand_fmpq(fmpq_t q, flint_rand_t state, const arb_t x, long bits)
|
||||
{
|
||||
fmprb_t t;
|
||||
fmprb_init(t);
|
||||
arb_get_fmprb(t, x);
|
||||
fmprb_get_rand_fmpq(q, state, t, bits);
|
||||
fmprb_clear(t);
|
||||
}
|
||||
|
42
arb/get_unique_fmpz.c
Normal file
42
arb/get_unique_fmpz.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
int
|
||||
arb_get_unique_fmpz(fmpz_t z, const arb_t x)
|
||||
{
|
||||
fmprb_t t;
|
||||
int ans;
|
||||
|
||||
fmprb_init(t);
|
||||
arb_get_fmprb(t, x);
|
||||
|
||||
ans = fmprb_get_unique_fmpz(z, t);
|
||||
|
||||
fmprb_clear(t);
|
||||
return ans;
|
||||
}
|
||||
|
47
arb/overlaps.c
Normal file
47
arb/overlaps.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
int
|
||||
arb_overlaps(const arb_t x, const arb_t y)
|
||||
{
|
||||
fmprb_t t, u;
|
||||
int ans;
|
||||
|
||||
fmprb_init(t);
|
||||
fmprb_init(u);
|
||||
|
||||
arb_get_fmprb(t, x);
|
||||
arb_get_fmprb(u, y);
|
||||
|
||||
ans = fmprb_overlaps(t, u);
|
||||
|
||||
fmprb_clear(t);
|
||||
fmprb_clear(u);
|
||||
|
||||
return ans;
|
||||
}
|
||||
|
104
arb/randtest.c
Normal file
104
arb/randtest.c
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
void
|
||||
arb_randtest_exact(arb_t x, flint_rand_t state, long prec, long mag_bits)
|
||||
{
|
||||
arf_randtest(arb_midref(x), state, prec, mag_bits);
|
||||
mag_zero(arb_radref(x));
|
||||
}
|
||||
|
||||
void
|
||||
arb_randtest_wide(arb_t x, flint_rand_t state, long prec, long mag_bits)
|
||||
{
|
||||
arf_randtest(arb_midref(x), state, prec, mag_bits);
|
||||
mag_randtest(arb_radref(x), state, mag_bits);
|
||||
}
|
||||
|
||||
void
|
||||
arb_randtest_precise(arb_t x, flint_rand_t state, long prec, long mag_bits)
|
||||
{
|
||||
arf_randtest(arb_midref(x), state, prec, mag_bits);
|
||||
|
||||
if (arf_is_zero(arb_midref(x)) || (n_randint(state, 8) == 0))
|
||||
{
|
||||
mag_zero(arb_radref(x));
|
||||
}
|
||||
else
|
||||
{
|
||||
mag_randtest(arb_radref(x), state, 0);
|
||||
|
||||
if (!mag_is_zero(arb_radref(x)))
|
||||
{
|
||||
fmpz_add_si(MAG_EXPREF(arb_radref(x)),
|
||||
ARF_EXPREF(arb_midref(x)),
|
||||
-prec + 2 - n_randint(state, 8));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
arb_randtest(arb_t x, flint_rand_t state, long prec, long mag_bits)
|
||||
{
|
||||
switch (n_randint(state, 8))
|
||||
{
|
||||
case 0:
|
||||
arb_randtest_exact(x, state, prec, mag_bits);
|
||||
break;
|
||||
case 1:
|
||||
arb_randtest_wide(x, state, prec, mag_bits);
|
||||
break;
|
||||
default:
|
||||
arb_randtest_precise(x, state, prec, mag_bits);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
arb_randtest_special(arb_t x, flint_rand_t state, long prec, long mag_bits)
|
||||
{
|
||||
arb_randtest(x, state, prec, mag_bits);
|
||||
|
||||
if (n_randint(state, 10) == 0)
|
||||
mag_inf(arb_radref(x));
|
||||
|
||||
switch (n_randint(state, 10))
|
||||
{
|
||||
case 0:
|
||||
arf_pos_inf(arb_midref(x));
|
||||
break;
|
||||
case 1:
|
||||
arf_neg_inf(arb_midref(x));
|
||||
break;
|
||||
case 2:
|
||||
arf_nan(arb_midref(x));
|
||||
mag_inf(arb_radref(x));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
49
arb/set_interval_arf.c
Normal file
49
arb/set_interval_arf.c
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2013 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
void
|
||||
arb_set_interval_arf(arb_t x, const arf_t a, const arf_t b, long prec)
|
||||
{
|
||||
fmprb_t t;
|
||||
fmpr_t u, v;
|
||||
|
||||
fmprb_init(t);
|
||||
fmpr_init(u);
|
||||
fmpr_init(v);
|
||||
|
||||
arf_get_fmpr(u, a);
|
||||
arf_get_fmpr(v, b);
|
||||
|
||||
fmprb_set_interval_fmpr(t, u, v, prec);
|
||||
|
||||
arb_set_fmprb(x, t);
|
||||
|
||||
fmprb_clear(t);
|
||||
fmpr_clear(u);
|
||||
fmpr_clear(v);
|
||||
}
|
||||
|
40
arb/set_round.c
Normal file
40
arb/set_round.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012-2014 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
void
|
||||
arb_set_round(arb_t z, const arb_t x, long prec)
|
||||
{
|
||||
int inexact;
|
||||
|
||||
inexact = arf_set_round(arb_midref(z), arb_midref(x), prec, ARB_RND);
|
||||
|
||||
if (inexact)
|
||||
arf_mag_add_ulp(arb_radref(z), arb_radref(x), arb_midref(z), prec);
|
||||
else
|
||||
mag_set(arb_radref(z), arb_radref(x));
|
||||
}
|
||||
|
102
arb/test/t-contains.c
Normal file
102
arb/test/t-contains.c
Normal file
|
@ -0,0 +1,102 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
long iter;
|
||||
flint_rand_t state;
|
||||
|
||||
printf("contains....");
|
||||
fflush(stdout);
|
||||
|
||||
flint_randinit(state);
|
||||
|
||||
for (iter = 0; iter < 100000; iter++)
|
||||
{
|
||||
arb_t a, b;
|
||||
fmpq_t am, ar, bm, br, t, u;
|
||||
int c1, c2;
|
||||
|
||||
arb_init(a);
|
||||
arb_init(b);
|
||||
|
||||
fmpq_init(am);
|
||||
fmpq_init(ar);
|
||||
fmpq_init(bm);
|
||||
fmpq_init(br);
|
||||
fmpq_init(t);
|
||||
fmpq_init(u);
|
||||
|
||||
arb_randtest(a, state, 1 + n_randint(state, 500), 14);
|
||||
arb_randtest(b, state, 1 + n_randint(state, 500), 14);
|
||||
|
||||
arf_get_fmpq(am, arb_midref(a));
|
||||
mag_get_fmpq(ar, arb_radref(a));
|
||||
arf_get_fmpq(bm, arb_midref(b));
|
||||
mag_get_fmpq(br, arb_radref(b));
|
||||
|
||||
c1 = arb_contains(a, b);
|
||||
|
||||
fmpq_sub(t, am, ar);
|
||||
fmpq_sub(u, bm, br);
|
||||
c2 = fmpq_cmp(t, u) <= 0;
|
||||
|
||||
fmpq_add(t, am, ar);
|
||||
fmpq_add(u, bm, br);
|
||||
c2 = c2 && (fmpq_cmp(t, u) >= 0);
|
||||
|
||||
if (c1 != c2)
|
||||
{
|
||||
printf("FAIL:\n\n");
|
||||
printf("a = "); arb_print(a); printf("\n\n");
|
||||
printf("b = "); arb_print(b); printf("\n\n");
|
||||
printf("am = "); fmpq_print(am); printf("\n\n");
|
||||
printf("ar = "); fmpq_print(ar); printf("\n\n");
|
||||
printf("bm = "); fmpq_print(bm); printf("\n\n");
|
||||
printf("br = "); fmpq_print(br); printf("\n\n");
|
||||
printf("t = "); fmpq_print(t); printf("\n\n");
|
||||
printf("u = "); fmpq_print(u); printf("\n\n");
|
||||
printf("c1 = %d, c2 = %d\n\n", c1, c2);
|
||||
abort();
|
||||
}
|
||||
|
||||
arb_clear(a);
|
||||
arb_clear(b);
|
||||
|
||||
fmpq_clear(am);
|
||||
fmpq_clear(ar);
|
||||
fmpq_clear(bm);
|
||||
fmpq_clear(br);
|
||||
fmpq_clear(t);
|
||||
fmpq_clear(u);
|
||||
}
|
||||
|
||||
flint_randclear(state);
|
||||
flint_cleanup();
|
||||
printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
94
arb/test/t-contains_arf.c
Normal file
94
arb/test/t-contains_arf.c
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
long iter;
|
||||
flint_rand_t state;
|
||||
|
||||
printf("contains_arf....");
|
||||
fflush(stdout);
|
||||
|
||||
flint_randinit(state);
|
||||
|
||||
for (iter = 0; iter < 10000; iter++)
|
||||
{
|
||||
arb_t a;
|
||||
arf_t b;
|
||||
fmpq_t am, ar, bm, t;
|
||||
int c1, c2;
|
||||
|
||||
arb_init(a);
|
||||
arf_init(b);
|
||||
|
||||
fmpq_init(am);
|
||||
fmpq_init(ar);
|
||||
fmpq_init(bm);
|
||||
fmpq_init(t);
|
||||
|
||||
arb_randtest(a, state, 1 + n_randint(state, 500), 14);
|
||||
arf_randtest(b, state, 1 + n_randint(state, 500), 14);
|
||||
|
||||
arf_get_fmpq(am, arb_midref(a));
|
||||
mag_get_fmpq(ar, arb_radref(a));
|
||||
arf_get_fmpq(bm, b);
|
||||
|
||||
c1 = arb_contains_arf(a, b);
|
||||
|
||||
fmpq_sub(t, am, ar);
|
||||
c2 = fmpq_cmp(t, bm) <= 0;
|
||||
|
||||
fmpq_add(t, am, ar);
|
||||
c2 = c2 && (fmpq_cmp(t, bm) >= 0);
|
||||
|
||||
if (c1 != c2)
|
||||
{
|
||||
printf("FAIL:\n\n");
|
||||
printf("a = "); arb_print(a); printf("\n\n");
|
||||
printf("b = "); arf_print(b); printf("\n\n");
|
||||
printf("am = "); fmpq_print(am); printf("\n\n");
|
||||
printf("ar = "); fmpq_print(ar); printf("\n\n");
|
||||
printf("bm = "); fmpq_print(bm); printf("\n\n");
|
||||
printf("t = "); fmpq_print(t); printf("\n\n");
|
||||
printf("c1 = %d, c2 = %d\n\n", c1, c2);
|
||||
abort();
|
||||
}
|
||||
|
||||
arb_clear(a);
|
||||
arf_clear(b);
|
||||
|
||||
fmpq_clear(am);
|
||||
fmpq_clear(ar);
|
||||
fmpq_clear(bm);
|
||||
fmpq_clear(t);
|
||||
}
|
||||
|
||||
flint_randclear(state);
|
||||
flint_cleanup();
|
||||
printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
84
arb/test/t-get_interval_fmpz_2exp.c
Normal file
84
arb/test/t-get_interval_fmpz_2exp.c
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
long iter;
|
||||
flint_rand_t state;
|
||||
|
||||
printf("get_interval_fmpz_2exp....");
|
||||
fflush(stdout);
|
||||
flint_randinit(state);
|
||||
|
||||
for (iter = 0; iter < 100000; iter++)
|
||||
{
|
||||
arb_t x;
|
||||
arf_t y;
|
||||
fmpz_t a, b, exp;
|
||||
|
||||
arb_init(x);
|
||||
arf_init(y);
|
||||
fmpz_init(a);
|
||||
fmpz_init(b);
|
||||
fmpz_init(exp);
|
||||
|
||||
arb_randtest(x, state, 200, 10);
|
||||
|
||||
arb_get_interval_fmpz_2exp(a, b, exp, x);
|
||||
|
||||
arf_set_fmpz_2exp(y, a, exp);
|
||||
if (!arb_contains_arf(x, y))
|
||||
{
|
||||
printf("FAIL:\n\n");
|
||||
printf("x = "); arb_print(x); printf("\n\n");
|
||||
printf("a = "); fmpz_print(a);
|
||||
printf(" exp = "); fmpz_print(exp); printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
arf_set_fmpz_2exp(y, b, exp);
|
||||
if (!arb_contains_arf(x, y))
|
||||
{
|
||||
printf("FAIL:\n\n");
|
||||
printf("x = "); arb_print(x); printf("\n\n");
|
||||
printf("b = "); fmpz_print(b);
|
||||
printf(" exp = "); fmpz_print(exp); printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
arb_clear(x);
|
||||
arf_clear(y);
|
||||
fmpz_clear(a);
|
||||
fmpz_clear(b);
|
||||
fmpz_clear(exp);
|
||||
}
|
||||
|
||||
flint_randclear(state);
|
||||
flint_cleanup();
|
||||
printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
64
arb/test/t-get_rand_fmpq.c
Normal file
64
arb/test/t-get_rand_fmpq.c
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
long iter;
|
||||
flint_rand_t state;
|
||||
|
||||
printf("get_rand_fmpq....");
|
||||
fflush(stdout);
|
||||
flint_randinit(state);
|
||||
|
||||
for (iter = 0; iter < 100000; iter++)
|
||||
{
|
||||
arb_t x;
|
||||
fmpq_t q;
|
||||
|
||||
arb_init(x);
|
||||
fmpq_init(q);
|
||||
|
||||
arb_randtest(x, state, 1 + n_randint(state, 200), 10);
|
||||
arb_get_rand_fmpq(q, state, x, 1 + n_randint(state, 200));
|
||||
|
||||
if (!arb_contains_fmpq(x, q) || !fmpq_is_canonical(q))
|
||||
{
|
||||
printf("FAIL:\n\n");
|
||||
printf("x = "); arb_print(x); printf("\n\n");
|
||||
printf("q = "); fmpq_print(q); printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
arb_clear(x);
|
||||
fmpq_clear(q);
|
||||
}
|
||||
|
||||
flint_randclear(state);
|
||||
flint_cleanup();
|
||||
printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
124
arb/test/t-get_unique_fmpz.c
Normal file
124
arb/test/t-get_unique_fmpz.c
Normal file
|
@ -0,0 +1,124 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
long iter;
|
||||
flint_rand_t state;
|
||||
|
||||
printf("get_unique_fmpz....");
|
||||
fflush(stdout);
|
||||
flint_randinit(state);
|
||||
|
||||
for (iter = 0; iter < 100000; iter++)
|
||||
{
|
||||
arb_t x, z;
|
||||
fmpz_t y, a, b, exp;
|
||||
int unique, unique2;
|
||||
|
||||
arb_init(x);
|
||||
arb_init(z);
|
||||
fmpz_init(y);
|
||||
fmpz_init(a);
|
||||
fmpz_init(b);
|
||||
fmpz_init(exp);
|
||||
|
||||
arb_randtest(x, state, 2000, 10);
|
||||
|
||||
unique = arb_get_unique_fmpz(y, x);
|
||||
|
||||
arb_get_interval_fmpz_2exp(a, b, exp, x);
|
||||
if (fmpz_sgn(exp) >= 0)
|
||||
{
|
||||
fmpz_mul_2exp(a, a, fmpz_get_si(exp));
|
||||
fmpz_mul_2exp(b, b, fmpz_get_si(exp));
|
||||
}
|
||||
else
|
||||
{
|
||||
fmpz_cdiv_q_2exp(a, a, -fmpz_get_si(exp));
|
||||
fmpz_fdiv_q_2exp(b, b, -fmpz_get_si(exp));
|
||||
}
|
||||
unique2 = fmpz_equal(a, b);
|
||||
|
||||
if ((unique != unique2) || (unique && !fmpz_equal(y, a)))
|
||||
{
|
||||
printf("FAIL:\n\n");
|
||||
printf("x = "); arb_print(x); printf("\n\n");
|
||||
printf("unique = %d, unique2 = %d\n\n", unique, unique2);
|
||||
printf("y = "); fmpz_print(y); printf("\n\n");
|
||||
printf("a = "); fmpz_print(a); printf("\n\n");
|
||||
printf("b = "); fmpz_print(b); printf("\n\n");
|
||||
printf(" exp = "); fmpz_print(exp); printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (unique)
|
||||
{
|
||||
arb_set_fmpz(z, y);
|
||||
arb_set_round(z, z, 2 + n_randint(state, 1000));
|
||||
|
||||
if (!arb_overlaps(x, z))
|
||||
{
|
||||
printf("FAIL (overlap):\n\n");
|
||||
printf("x = "); arb_print(x); printf("\n\n");
|
||||
printf("y = "); fmpz_print(y); printf("\n\n");
|
||||
printf("z = "); arb_print(z); printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_add_ui(b, y, 1);
|
||||
if (arb_contains_fmpz(x, b))
|
||||
{
|
||||
printf("FAIL (contains a + 1):\n\n");
|
||||
printf("x = "); arb_print(x); printf("\n\n");
|
||||
printf("y = "); fmpz_print(y); printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_sub_ui(b, y, 1);
|
||||
if (arb_contains_fmpz(x, b))
|
||||
{
|
||||
printf("FAIL (contains a - 1):\n\n");
|
||||
printf("x = "); arb_print(x); printf("\n\n");
|
||||
printf("y = "); fmpz_print(y); printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
arb_clear(x);
|
||||
arb_clear(z);
|
||||
fmpz_clear(y);
|
||||
fmpz_clear(a);
|
||||
fmpz_clear(b);
|
||||
fmpz_clear(exp);
|
||||
}
|
||||
|
||||
flint_randclear(state);
|
||||
flint_cleanup();
|
||||
printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
100
arb/test/t-overlaps.c
Normal file
100
arb/test/t-overlaps.c
Normal file
|
@ -0,0 +1,100 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
long iter;
|
||||
flint_rand_t state;
|
||||
|
||||
printf("overlaps....");
|
||||
fflush(stdout);
|
||||
|
||||
flint_randinit(state);
|
||||
|
||||
for (iter = 0; iter < 100000; iter++)
|
||||
{
|
||||
arb_t a, b;
|
||||
fmpq_t am, ar, bm, br, t, u;
|
||||
int c1, c2;
|
||||
|
||||
arb_init(a);
|
||||
arb_init(b);
|
||||
|
||||
fmpq_init(am);
|
||||
fmpq_init(ar);
|
||||
fmpq_init(bm);
|
||||
fmpq_init(br);
|
||||
fmpq_init(t);
|
||||
fmpq_init(u);
|
||||
|
||||
arb_randtest(a, state, 1 + n_randint(state, 500), 14);
|
||||
arb_randtest(b, state, 1 + n_randint(state, 500), 14);
|
||||
|
||||
arf_get_fmpq(am, arb_midref(a));
|
||||
mag_get_fmpq(ar, arb_radref(a));
|
||||
arf_get_fmpq(bm, arb_midref(b));
|
||||
mag_get_fmpq(br, arb_radref(b));
|
||||
|
||||
fmpq_sub(t, am, bm);
|
||||
fmpz_abs(fmpq_numref(t), fmpq_numref(t));
|
||||
fmpq_add(u, ar, br);
|
||||
|
||||
c1 = arb_overlaps(a, b);
|
||||
|
||||
c2 = (fmpq_cmp(t, u) <= 0);
|
||||
|
||||
if (c1 != c2)
|
||||
{
|
||||
printf("FAIL:\n\n");
|
||||
printf("a = "); arb_print(a); printf("\n\n");
|
||||
printf("b = "); arb_print(b); printf("\n\n");
|
||||
printf("am = "); fmpq_print(am); printf("\n\n");
|
||||
printf("ar = "); fmpq_print(ar); printf("\n\n");
|
||||
printf("bm = "); fmpq_print(bm); printf("\n\n");
|
||||
printf("br = "); fmpq_print(br); printf("\n\n");
|
||||
printf("t = "); fmpq_print(t); printf("\n\n");
|
||||
printf("u = "); fmpq_print(u); printf("\n\n");
|
||||
printf("c1 = %d, c2 = %d\n\n", c1, c2);
|
||||
abort();
|
||||
}
|
||||
|
||||
arb_clear(a);
|
||||
arb_clear(b);
|
||||
|
||||
fmpq_clear(am);
|
||||
fmpq_clear(ar);
|
||||
fmpq_clear(bm);
|
||||
fmpq_clear(br);
|
||||
fmpq_clear(t);
|
||||
fmpq_clear(u);
|
||||
}
|
||||
|
||||
flint_randclear(state);
|
||||
flint_cleanup();
|
||||
printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
72
arb/test/t-set_interval_fmpr.c
Normal file
72
arb/test/t-set_interval_fmpr.c
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
long iter;
|
||||
flint_rand_t state;
|
||||
|
||||
printf("set_interval_arf....");
|
||||
fflush(stdout);
|
||||
flint_randinit(state);
|
||||
|
||||
for (iter = 0; iter < 100000; iter++)
|
||||
{
|
||||
arb_t x;
|
||||
arf_t a, b;
|
||||
|
||||
arb_init(x);
|
||||
arf_init(a);
|
||||
arf_init(b);
|
||||
|
||||
arf_randtest_special(a, state, 200, 10);
|
||||
arf_randtest_special(b, state, 200, 10);
|
||||
if (arf_cmp(a, b) > 0)
|
||||
arf_swap(a, b);
|
||||
|
||||
arb_set_interval_arf(x, a, b, 2 + n_randint(state, 200));
|
||||
|
||||
if (!arb_contains_arf(x, a) || !arb_contains_arf(x, b))
|
||||
{
|
||||
printf("FAIL:\n\n");
|
||||
printf("x = "); arb_print(x); printf("\n\n");
|
||||
printf("a = "); arf_print(a); printf("\n\n");
|
||||
printf("b = "); arf_print(b); printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
arb_clear(x);
|
||||
arf_clear(a);
|
||||
arf_clear(b);
|
||||
}
|
||||
|
||||
flint_randclear(state);
|
||||
flint_cleanup();
|
||||
printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
639
arb/test/t-special.c
Normal file
639
arb/test/t-special.c
Normal file
|
@ -0,0 +1,639 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2013 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
#define ASSERT(cond) if (!(cond)) { printf("FAIL: %d\n", __LINE__); abort(); }
|
||||
|
||||
int main()
|
||||
{
|
||||
#if 0
|
||||
arb_t zero, pos, neg, pos_inf, neg_inf, pos_inf_err, neg_inf_err,
|
||||
zero_pm_inf, pos_pm_inf, neg_pm_inf,
|
||||
indet_exact, indet_pos_rad, indet_inf_rad;
|
||||
#endif
|
||||
|
||||
printf("special....");
|
||||
fflush(stdout);
|
||||
|
||||
printf(" [NOT YET IMPLEMENTED] ");
|
||||
|
||||
#if 0
|
||||
|
||||
arb_init(zero);
|
||||
arb_init(pos);
|
||||
arb_init(neg);
|
||||
arb_init(pos_inf);
|
||||
arb_init(neg_inf);
|
||||
arb_init(pos_inf_err);
|
||||
arb_init(neg_inf_err);
|
||||
arb_init(zero_pm_inf);
|
||||
arb_init(pos_pm_inf);
|
||||
arb_init(neg_pm_inf);
|
||||
arb_init(indet_exact);
|
||||
arb_init(indet_pos_rad);
|
||||
arb_init(indet_inf_rad);
|
||||
|
||||
arb_set_si(pos, 3); arb_div_ui(pos, pos, 5, 53);
|
||||
arb_neg(neg, pos);
|
||||
arb_pos_inf(pos_inf);
|
||||
arb_neg_inf(neg_inf);
|
||||
arb_pos_inf(pos_inf_err); arf_set_ui(arb_radref(pos_inf_err), 3);
|
||||
arb_neg(neg_inf_err, pos_inf_err);
|
||||
arb_zero_pm_inf(zero_pm_inf);
|
||||
arf_set_si(arb_midref(pos_pm_inf), 3); arf_pos_inf(arb_radref(pos_pm_inf));
|
||||
arf_set_si(arb_midref(neg_pm_inf), -3); arf_pos_inf(arb_radref(neg_pm_inf));
|
||||
arf_nan(arb_midref(indet_exact)); arf_zero(arb_radref(indet_exact));
|
||||
arf_nan(arb_midref(indet_pos_rad)); arf_set_si(arb_radref(indet_pos_rad), 3);
|
||||
arf_nan(arb_midref(indet_inf_rad)); arf_pos_inf(arb_radref(indet_inf_rad));
|
||||
|
||||
ASSERT(arb_is_zero(zero));
|
||||
ASSERT(!arb_is_zero(pos));
|
||||
ASSERT(!arb_is_zero(neg));
|
||||
ASSERT(!arb_is_zero(pos_inf));
|
||||
ASSERT(!arb_is_zero(neg_inf));
|
||||
ASSERT(!arb_is_zero(pos_inf_err));
|
||||
ASSERT(!arb_is_zero(neg_inf_err));
|
||||
ASSERT(!arb_is_zero(zero_pm_inf));
|
||||
ASSERT(!arb_is_zero(pos_pm_inf));
|
||||
ASSERT(!arb_is_zero(neg_pm_inf));
|
||||
ASSERT(!arb_is_zero(indet_exact));
|
||||
ASSERT(!arb_is_zero(indet_pos_rad));
|
||||
ASSERT(!arb_is_zero(indet_inf_rad));
|
||||
|
||||
ASSERT(!arb_is_nonzero(zero));
|
||||
ASSERT(arb_is_nonzero(pos));
|
||||
ASSERT(arb_is_nonzero(neg));
|
||||
ASSERT(arb_is_nonzero(pos_inf));
|
||||
ASSERT(arb_is_nonzero(neg_inf));
|
||||
ASSERT(arb_is_nonzero(pos_inf_err));
|
||||
ASSERT(arb_is_nonzero(neg_inf_err));
|
||||
ASSERT(!arb_is_nonzero(zero_pm_inf));
|
||||
ASSERT(!arb_is_nonzero(pos_pm_inf));
|
||||
ASSERT(!arb_is_nonzero(neg_pm_inf));
|
||||
ASSERT(!arb_is_nonzero(indet_exact));
|
||||
ASSERT(!arb_is_nonzero(indet_pos_rad));
|
||||
ASSERT(!arb_is_nonzero(indet_inf_rad));
|
||||
|
||||
|
||||
ASSERT(!arb_is_positive(zero));
|
||||
ASSERT(arb_is_positive(pos));
|
||||
ASSERT(!arb_is_positive(neg));
|
||||
ASSERT(arb_is_positive(pos_inf));
|
||||
ASSERT(!arb_is_positive(neg_inf));
|
||||
ASSERT(arb_is_positive(pos_inf_err));
|
||||
ASSERT(!arb_is_positive(neg_inf_err));
|
||||
ASSERT(!arb_is_positive(zero_pm_inf));
|
||||
ASSERT(!arb_is_positive(pos_pm_inf));
|
||||
ASSERT(!arb_is_positive(neg_pm_inf));
|
||||
ASSERT(!arb_is_positive(indet_exact));
|
||||
ASSERT(!arb_is_positive(indet_pos_rad));
|
||||
ASSERT(!arb_is_positive(indet_inf_rad));
|
||||
|
||||
ASSERT(!arb_is_negative(zero));
|
||||
ASSERT(!arb_is_negative(pos));
|
||||
ASSERT(arb_is_negative(neg));
|
||||
ASSERT(!arb_is_negative(pos_inf));
|
||||
ASSERT(arb_is_negative(neg_inf));
|
||||
ASSERT(!arb_is_negative(pos_inf_err));
|
||||
ASSERT(arb_is_negative(neg_inf_err));
|
||||
ASSERT(!arb_is_negative(zero_pm_inf));
|
||||
ASSERT(!arb_is_negative(pos_pm_inf));
|
||||
ASSERT(!arb_is_negative(neg_pm_inf));
|
||||
ASSERT(!arb_is_negative(indet_exact));
|
||||
ASSERT(!arb_is_negative(indet_pos_rad));
|
||||
ASSERT(!arb_is_negative(indet_inf_rad));
|
||||
|
||||
ASSERT(arb_is_nonnegative(zero));
|
||||
ASSERT(arb_is_nonnegative(pos));
|
||||
ASSERT(!arb_is_nonnegative(neg));
|
||||
ASSERT(arb_is_nonnegative(pos_inf));
|
||||
ASSERT(!arb_is_nonnegative(neg_inf));
|
||||
ASSERT(arb_is_nonnegative(pos_inf_err));
|
||||
ASSERT(!arb_is_nonnegative(neg_inf_err));
|
||||
ASSERT(!arb_is_nonnegative(zero_pm_inf));
|
||||
ASSERT(!arb_is_nonnegative(pos_pm_inf));
|
||||
ASSERT(!arb_is_nonnegative(neg_pm_inf));
|
||||
ASSERT(!arb_is_nonnegative(indet_exact));
|
||||
ASSERT(!arb_is_nonnegative(indet_pos_rad));
|
||||
ASSERT(!arb_is_nonnegative(indet_inf_rad));
|
||||
|
||||
ASSERT(arb_is_nonpositive(zero));
|
||||
ASSERT(!arb_is_nonpositive(pos));
|
||||
ASSERT(arb_is_nonpositive(neg));
|
||||
ASSERT(!arb_is_nonpositive(pos_inf));
|
||||
ASSERT(arb_is_nonpositive(neg_inf));
|
||||
ASSERT(!arb_is_nonpositive(pos_inf_err));
|
||||
ASSERT(arb_is_nonpositive(neg_inf_err));
|
||||
ASSERT(!arb_is_nonpositive(zero_pm_inf));
|
||||
ASSERT(!arb_is_nonpositive(pos_pm_inf));
|
||||
ASSERT(!arb_is_nonpositive(neg_pm_inf));
|
||||
ASSERT(!arb_is_nonpositive(indet_exact));
|
||||
ASSERT(!arb_is_nonpositive(indet_pos_rad));
|
||||
ASSERT(!arb_is_nonpositive(indet_inf_rad));
|
||||
|
||||
ASSERT(!arb_contains_negative(zero));
|
||||
ASSERT(!arb_contains_negative(pos));
|
||||
ASSERT(arb_contains_negative(neg));
|
||||
ASSERT(!arb_contains_negative(pos_inf));
|
||||
ASSERT(arb_contains_negative(neg_inf));
|
||||
ASSERT(!arb_contains_negative(pos_inf_err));
|
||||
ASSERT(arb_contains_negative(neg_inf_err));
|
||||
ASSERT(arb_contains_negative(zero_pm_inf));
|
||||
ASSERT(arb_contains_negative(pos_pm_inf));
|
||||
ASSERT(arb_contains_negative(neg_pm_inf));
|
||||
ASSERT(arb_contains_negative(indet_exact));
|
||||
ASSERT(arb_contains_negative(indet_pos_rad));
|
||||
ASSERT(arb_contains_negative(indet_inf_rad));
|
||||
|
||||
ASSERT(arb_contains_nonpositive(zero));
|
||||
ASSERT(!arb_contains_nonpositive(pos));
|
||||
ASSERT(arb_contains_nonpositive(neg));
|
||||
ASSERT(!arb_contains_nonpositive(pos_inf));
|
||||
ASSERT(arb_contains_nonpositive(neg_inf));
|
||||
ASSERT(!arb_contains_nonpositive(pos_inf_err));
|
||||
ASSERT(arb_contains_nonpositive(neg_inf_err));
|
||||
ASSERT(arb_contains_nonpositive(zero_pm_inf));
|
||||
ASSERT(arb_contains_nonpositive(pos_pm_inf));
|
||||
ASSERT(arb_contains_nonpositive(neg_pm_inf));
|
||||
ASSERT(arb_contains_nonpositive(indet_exact));
|
||||
ASSERT(arb_contains_nonpositive(indet_pos_rad));
|
||||
ASSERT(arb_contains_nonpositive(indet_inf_rad));
|
||||
|
||||
ASSERT(!arb_contains_positive(zero));
|
||||
ASSERT(arb_contains_positive(pos));
|
||||
ASSERT(!arb_contains_positive(neg));
|
||||
ASSERT(arb_contains_positive(pos_inf));
|
||||
ASSERT(!arb_contains_positive(neg_inf));
|
||||
ASSERT(arb_contains_positive(pos_inf_err));
|
||||
ASSERT(!arb_contains_positive(neg_inf_err));
|
||||
ASSERT(arb_contains_positive(zero_pm_inf));
|
||||
ASSERT(arb_contains_positive(pos_pm_inf));
|
||||
ASSERT(arb_contains_positive(neg_pm_inf));
|
||||
ASSERT(arb_contains_positive(indet_exact));
|
||||
ASSERT(arb_contains_positive(indet_pos_rad));
|
||||
ASSERT(arb_contains_positive(indet_inf_rad));
|
||||
|
||||
ASSERT(arb_contains_nonnegative(zero));
|
||||
ASSERT(arb_contains_nonnegative(pos));
|
||||
ASSERT(!arb_contains_nonnegative(neg));
|
||||
ASSERT(arb_contains_nonnegative(pos_inf));
|
||||
ASSERT(!arb_contains_nonnegative(neg_inf));
|
||||
ASSERT(arb_contains_nonnegative(pos_inf_err));
|
||||
ASSERT(!arb_contains_nonnegative(neg_inf_err));
|
||||
ASSERT(arb_contains_nonnegative(zero_pm_inf));
|
||||
ASSERT(arb_contains_nonnegative(pos_pm_inf));
|
||||
ASSERT(arb_contains_nonnegative(neg_pm_inf));
|
||||
ASSERT(arb_contains_nonnegative(indet_exact));
|
||||
ASSERT(arb_contains_nonnegative(indet_pos_rad));
|
||||
ASSERT(arb_contains_nonnegative(indet_inf_rad));
|
||||
|
||||
ASSERT(arb_is_finite(zero));
|
||||
ASSERT(arb_is_finite(pos));
|
||||
ASSERT(arb_is_finite(neg));
|
||||
ASSERT(!arb_is_finite(pos_inf));
|
||||
ASSERT(!arb_is_finite(neg_inf));
|
||||
ASSERT(!arb_is_finite(pos_inf_err));
|
||||
ASSERT(!arb_is_finite(neg_inf_err));
|
||||
ASSERT(!arb_is_finite(zero_pm_inf));
|
||||
ASSERT(!arb_is_finite(pos_pm_inf));
|
||||
ASSERT(!arb_is_finite(neg_pm_inf));
|
||||
ASSERT(!arb_is_finite(indet_exact));
|
||||
ASSERT(!arb_is_finite(indet_pos_rad));
|
||||
ASSERT(!arb_is_finite(indet_inf_rad));
|
||||
|
||||
ASSERT(arb_contains(zero, zero));
|
||||
ASSERT(!arb_contains(zero, pos));
|
||||
ASSERT(!arb_contains(zero, neg));
|
||||
ASSERT(!arb_contains(zero, pos_inf));
|
||||
ASSERT(!arb_contains(zero, neg_inf));
|
||||
ASSERT(!arb_contains(zero, pos_inf_err));
|
||||
ASSERT(!arb_contains(zero, neg_inf_err));
|
||||
ASSERT(!arb_contains(zero, zero_pm_inf));
|
||||
ASSERT(!arb_contains(zero, pos_pm_inf));
|
||||
ASSERT(!arb_contains(zero, neg_pm_inf));
|
||||
ASSERT(!arb_contains(zero, indet_exact));
|
||||
ASSERT(!arb_contains(zero, indet_pos_rad));
|
||||
ASSERT(!arb_contains(zero, indet_inf_rad));
|
||||
ASSERT(!arb_contains(pos, zero));
|
||||
ASSERT(arb_contains(pos, pos));
|
||||
ASSERT(!arb_contains(pos, neg));
|
||||
ASSERT(!arb_contains(pos, pos_inf));
|
||||
ASSERT(!arb_contains(pos, neg_inf));
|
||||
ASSERT(!arb_contains(pos, pos_inf_err));
|
||||
ASSERT(!arb_contains(pos, neg_inf_err));
|
||||
ASSERT(!arb_contains(pos, zero_pm_inf));
|
||||
ASSERT(!arb_contains(pos, pos_pm_inf));
|
||||
ASSERT(!arb_contains(pos, neg_pm_inf));
|
||||
ASSERT(!arb_contains(pos, indet_exact));
|
||||
ASSERT(!arb_contains(pos, indet_pos_rad));
|
||||
ASSERT(!arb_contains(pos, indet_inf_rad));
|
||||
ASSERT(!arb_contains(neg, zero));
|
||||
ASSERT(!arb_contains(neg, pos));
|
||||
ASSERT(arb_contains(neg, neg));
|
||||
ASSERT(!arb_contains(neg, pos_inf));
|
||||
ASSERT(!arb_contains(neg, neg_inf));
|
||||
ASSERT(!arb_contains(neg, pos_inf_err));
|
||||
ASSERT(!arb_contains(neg, neg_inf_err));
|
||||
ASSERT(!arb_contains(neg, zero_pm_inf));
|
||||
ASSERT(!arb_contains(neg, pos_pm_inf));
|
||||
ASSERT(!arb_contains(neg, neg_pm_inf));
|
||||
ASSERT(!arb_contains(neg, indet_exact));
|
||||
ASSERT(!arb_contains(neg, indet_pos_rad));
|
||||
ASSERT(!arb_contains(neg, indet_inf_rad));
|
||||
ASSERT(!arb_contains(pos_inf, zero));
|
||||
ASSERT(!arb_contains(pos_inf, pos));
|
||||
ASSERT(!arb_contains(pos_inf, neg));
|
||||
ASSERT(arb_contains(pos_inf, pos_inf));
|
||||
ASSERT(!arb_contains(pos_inf, neg_inf));
|
||||
ASSERT(arb_contains(pos_inf, pos_inf_err));
|
||||
ASSERT(!arb_contains(pos_inf, neg_inf_err));
|
||||
ASSERT(!arb_contains(pos_inf, zero_pm_inf));
|
||||
ASSERT(!arb_contains(pos_inf, pos_pm_inf));
|
||||
ASSERT(!arb_contains(pos_inf, neg_pm_inf));
|
||||
ASSERT(!arb_contains(pos_inf, indet_exact));
|
||||
ASSERT(!arb_contains(pos_inf, indet_pos_rad));
|
||||
ASSERT(!arb_contains(pos_inf, indet_inf_rad));
|
||||
ASSERT(!arb_contains(neg_inf, zero));
|
||||
ASSERT(!arb_contains(neg_inf, pos));
|
||||
ASSERT(!arb_contains(neg_inf, neg));
|
||||
ASSERT(!arb_contains(neg_inf, pos_inf));
|
||||
ASSERT(arb_contains(neg_inf, neg_inf));
|
||||
ASSERT(!arb_contains(neg_inf, pos_inf_err));
|
||||
ASSERT(arb_contains(neg_inf, neg_inf_err));
|
||||
ASSERT(!arb_contains(neg_inf, zero_pm_inf));
|
||||
ASSERT(!arb_contains(neg_inf, pos_pm_inf));
|
||||
ASSERT(!arb_contains(neg_inf, neg_pm_inf));
|
||||
ASSERT(!arb_contains(neg_inf, indet_exact));
|
||||
ASSERT(!arb_contains(neg_inf, indet_pos_rad));
|
||||
ASSERT(!arb_contains(neg_inf, indet_inf_rad));
|
||||
ASSERT(!arb_contains(pos_inf_err, zero));
|
||||
ASSERT(!arb_contains(pos_inf_err, pos));
|
||||
ASSERT(!arb_contains(pos_inf_err, neg));
|
||||
ASSERT(arb_contains(pos_inf_err, pos_inf));
|
||||
ASSERT(!arb_contains(pos_inf_err, neg_inf));
|
||||
ASSERT(arb_contains(pos_inf_err, pos_inf_err));
|
||||
ASSERT(!arb_contains(pos_inf_err, neg_inf_err));
|
||||
ASSERT(!arb_contains(pos_inf_err, zero_pm_inf));
|
||||
ASSERT(!arb_contains(pos_inf_err, pos_pm_inf));
|
||||
ASSERT(!arb_contains(pos_inf_err, neg_pm_inf));
|
||||
ASSERT(!arb_contains(pos_inf_err, indet_exact));
|
||||
ASSERT(!arb_contains(pos_inf_err, indet_pos_rad));
|
||||
ASSERT(!arb_contains(pos_inf_err, indet_inf_rad));
|
||||
ASSERT(!arb_contains(neg_inf_err, zero));
|
||||
ASSERT(!arb_contains(neg_inf_err, pos));
|
||||
ASSERT(!arb_contains(neg_inf_err, neg));
|
||||
ASSERT(!arb_contains(neg_inf_err, pos_inf));
|
||||
ASSERT(arb_contains(neg_inf_err, neg_inf));
|
||||
ASSERT(!arb_contains(neg_inf_err, pos_inf_err));
|
||||
ASSERT(arb_contains(neg_inf_err, neg_inf_err));
|
||||
ASSERT(!arb_contains(neg_inf_err, zero_pm_inf));
|
||||
ASSERT(!arb_contains(neg_inf_err, pos_pm_inf));
|
||||
ASSERT(!arb_contains(neg_inf_err, neg_pm_inf));
|
||||
ASSERT(!arb_contains(neg_inf_err, indet_exact));
|
||||
ASSERT(!arb_contains(neg_inf_err, indet_pos_rad));
|
||||
ASSERT(!arb_contains(neg_inf_err, indet_inf_rad));
|
||||
ASSERT(arb_contains(zero_pm_inf, zero));
|
||||
ASSERT(arb_contains(zero_pm_inf, pos));
|
||||
ASSERT(arb_contains(zero_pm_inf, neg));
|
||||
ASSERT(arb_contains(zero_pm_inf, pos_inf));
|
||||
ASSERT(arb_contains(zero_pm_inf, neg_inf));
|
||||
ASSERT(arb_contains(zero_pm_inf, pos_inf_err));
|
||||
ASSERT(arb_contains(zero_pm_inf, neg_inf_err));
|
||||
ASSERT(arb_contains(zero_pm_inf, zero_pm_inf));
|
||||
ASSERT(arb_contains(zero_pm_inf, pos_pm_inf));
|
||||
ASSERT(arb_contains(zero_pm_inf, neg_pm_inf));
|
||||
ASSERT(!arb_contains(zero_pm_inf, indet_exact));
|
||||
ASSERT(!arb_contains(zero_pm_inf, indet_pos_rad));
|
||||
ASSERT(!arb_contains(zero_pm_inf, indet_inf_rad));
|
||||
ASSERT(arb_contains(pos_pm_inf, zero));
|
||||
ASSERT(arb_contains(pos_pm_inf, pos));
|
||||
ASSERT(arb_contains(pos_pm_inf, neg));
|
||||
ASSERT(arb_contains(pos_pm_inf, pos_inf));
|
||||
ASSERT(arb_contains(pos_pm_inf, neg_inf));
|
||||
ASSERT(arb_contains(pos_pm_inf, pos_inf_err));
|
||||
ASSERT(arb_contains(pos_pm_inf, neg_inf_err));
|
||||
ASSERT(arb_contains(pos_pm_inf, zero_pm_inf));
|
||||
ASSERT(arb_contains(pos_pm_inf, pos_pm_inf));
|
||||
ASSERT(arb_contains(pos_pm_inf, neg_pm_inf));
|
||||
ASSERT(!arb_contains(pos_pm_inf, indet_exact));
|
||||
ASSERT(!arb_contains(pos_pm_inf, indet_pos_rad));
|
||||
ASSERT(!arb_contains(pos_pm_inf, indet_inf_rad));
|
||||
ASSERT(arb_contains(neg_pm_inf, zero));
|
||||
ASSERT(arb_contains(neg_pm_inf, pos));
|
||||
ASSERT(arb_contains(neg_pm_inf, neg));
|
||||
ASSERT(arb_contains(neg_pm_inf, pos_inf));
|
||||
ASSERT(arb_contains(neg_pm_inf, neg_inf));
|
||||
ASSERT(arb_contains(neg_pm_inf, pos_inf_err));
|
||||
ASSERT(arb_contains(neg_pm_inf, neg_inf_err));
|
||||
ASSERT(arb_contains(neg_pm_inf, zero_pm_inf));
|
||||
ASSERT(arb_contains(neg_pm_inf, pos_pm_inf));
|
||||
ASSERT(arb_contains(neg_pm_inf, neg_pm_inf));
|
||||
ASSERT(!arb_contains(neg_pm_inf, indet_exact));
|
||||
ASSERT(!arb_contains(neg_pm_inf, indet_pos_rad));
|
||||
ASSERT(!arb_contains(neg_pm_inf, indet_inf_rad));
|
||||
ASSERT(arb_contains(indet_exact, zero));
|
||||
ASSERT(arb_contains(indet_exact, pos));
|
||||
ASSERT(arb_contains(indet_exact, neg));
|
||||
ASSERT(arb_contains(indet_exact, pos_inf));
|
||||
ASSERT(arb_contains(indet_exact, neg_inf));
|
||||
ASSERT(arb_contains(indet_exact, pos_inf_err));
|
||||
ASSERT(arb_contains(indet_exact, neg_inf_err));
|
||||
ASSERT(arb_contains(indet_exact, zero_pm_inf));
|
||||
ASSERT(arb_contains(indet_exact, pos_pm_inf));
|
||||
ASSERT(arb_contains(indet_exact, neg_pm_inf));
|
||||
ASSERT(arb_contains(indet_exact, indet_exact));
|
||||
ASSERT(arb_contains(indet_exact, indet_pos_rad));
|
||||
ASSERT(arb_contains(indet_exact, indet_inf_rad));
|
||||
ASSERT(arb_contains(indet_pos_rad, zero));
|
||||
ASSERT(arb_contains(indet_pos_rad, pos));
|
||||
ASSERT(arb_contains(indet_pos_rad, neg));
|
||||
ASSERT(arb_contains(indet_pos_rad, pos_inf));
|
||||
ASSERT(arb_contains(indet_pos_rad, neg_inf));
|
||||
ASSERT(arb_contains(indet_pos_rad, pos_inf_err));
|
||||
ASSERT(arb_contains(indet_pos_rad, neg_inf_err));
|
||||
ASSERT(arb_contains(indet_pos_rad, zero_pm_inf));
|
||||
ASSERT(arb_contains(indet_pos_rad, pos_pm_inf));
|
||||
ASSERT(arb_contains(indet_pos_rad, neg_pm_inf));
|
||||
ASSERT(arb_contains(indet_pos_rad, indet_exact));
|
||||
ASSERT(arb_contains(indet_pos_rad, indet_pos_rad));
|
||||
ASSERT(arb_contains(indet_pos_rad, indet_inf_rad));
|
||||
ASSERT(arb_contains(indet_inf_rad, zero));
|
||||
ASSERT(arb_contains(indet_inf_rad, pos));
|
||||
ASSERT(arb_contains(indet_inf_rad, neg));
|
||||
ASSERT(arb_contains(indet_inf_rad, pos_inf));
|
||||
ASSERT(arb_contains(indet_inf_rad, neg_inf));
|
||||
ASSERT(arb_contains(indet_inf_rad, pos_inf_err));
|
||||
ASSERT(arb_contains(indet_inf_rad, neg_inf_err));
|
||||
ASSERT(arb_contains(indet_inf_rad, zero_pm_inf));
|
||||
ASSERT(arb_contains(indet_inf_rad, pos_pm_inf));
|
||||
ASSERT(arb_contains(indet_inf_rad, neg_pm_inf));
|
||||
ASSERT(arb_contains(indet_inf_rad, indet_exact));
|
||||
ASSERT(arb_contains(indet_inf_rad, indet_pos_rad));
|
||||
ASSERT(arb_contains(indet_inf_rad, indet_inf_rad));
|
||||
|
||||
ASSERT(arb_overlaps(zero, zero));
|
||||
ASSERT(!arb_overlaps(zero, pos));
|
||||
ASSERT(!arb_overlaps(zero, neg));
|
||||
ASSERT(!arb_overlaps(zero, pos_inf));
|
||||
ASSERT(!arb_overlaps(zero, neg_inf));
|
||||
ASSERT(!arb_overlaps(zero, pos_inf_err));
|
||||
ASSERT(!arb_overlaps(zero, neg_inf_err));
|
||||
ASSERT(arb_overlaps(zero, zero_pm_inf));
|
||||
ASSERT(arb_overlaps(zero, pos_pm_inf));
|
||||
ASSERT(arb_overlaps(zero, neg_pm_inf));
|
||||
ASSERT(arb_overlaps(zero, indet_exact));
|
||||
ASSERT(arb_overlaps(zero, indet_pos_rad));
|
||||
ASSERT(arb_overlaps(zero, indet_inf_rad));
|
||||
ASSERT(!arb_overlaps(pos, zero));
|
||||
ASSERT(arb_overlaps(pos, pos));
|
||||
ASSERT(!arb_overlaps(pos, neg));
|
||||
ASSERT(!arb_overlaps(pos, pos_inf));
|
||||
ASSERT(!arb_overlaps(pos, neg_inf));
|
||||
ASSERT(!arb_overlaps(pos, pos_inf_err));
|
||||
ASSERT(!arb_overlaps(pos, neg_inf_err));
|
||||
ASSERT(arb_overlaps(pos, zero_pm_inf));
|
||||
ASSERT(arb_overlaps(pos, pos_pm_inf));
|
||||
ASSERT(arb_overlaps(pos, neg_pm_inf));
|
||||
ASSERT(arb_overlaps(pos, indet_exact));
|
||||
ASSERT(arb_overlaps(pos, indet_pos_rad));
|
||||
ASSERT(arb_overlaps(pos, indet_inf_rad));
|
||||
ASSERT(!arb_overlaps(neg, zero));
|
||||
ASSERT(!arb_overlaps(neg, pos));
|
||||
ASSERT(arb_overlaps(neg, neg));
|
||||
ASSERT(!arb_overlaps(neg, pos_inf));
|
||||
ASSERT(!arb_overlaps(neg, neg_inf));
|
||||
ASSERT(!arb_overlaps(neg, pos_inf_err));
|
||||
ASSERT(!arb_overlaps(neg, neg_inf_err));
|
||||
ASSERT(arb_overlaps(neg, zero_pm_inf));
|
||||
ASSERT(arb_overlaps(neg, pos_pm_inf));
|
||||
ASSERT(arb_overlaps(neg, neg_pm_inf));
|
||||
ASSERT(arb_overlaps(neg, indet_exact));
|
||||
ASSERT(arb_overlaps(neg, indet_pos_rad));
|
||||
ASSERT(arb_overlaps(neg, indet_inf_rad));
|
||||
ASSERT(!arb_overlaps(pos_inf, zero));
|
||||
ASSERT(!arb_overlaps(pos_inf, pos));
|
||||
ASSERT(!arb_overlaps(pos_inf, neg));
|
||||
ASSERT(arb_overlaps(pos_inf, pos_inf));
|
||||
ASSERT(!arb_overlaps(pos_inf, neg_inf));
|
||||
ASSERT(arb_overlaps(pos_inf, pos_inf_err));
|
||||
ASSERT(!arb_overlaps(pos_inf, neg_inf_err));
|
||||
ASSERT(arb_overlaps(pos_inf, zero_pm_inf));
|
||||
ASSERT(arb_overlaps(pos_inf, pos_pm_inf));
|
||||
ASSERT(arb_overlaps(pos_inf, neg_pm_inf));
|
||||
ASSERT(arb_overlaps(pos_inf, indet_exact));
|
||||
ASSERT(arb_overlaps(pos_inf, indet_pos_rad));
|
||||
ASSERT(arb_overlaps(pos_inf, indet_inf_rad));
|
||||
ASSERT(!arb_overlaps(neg_inf, zero));
|
||||
ASSERT(!arb_overlaps(neg_inf, pos));
|
||||
ASSERT(!arb_overlaps(neg_inf, neg));
|
||||
ASSERT(!arb_overlaps(neg_inf, pos_inf));
|
||||
ASSERT(arb_overlaps(neg_inf, neg_inf));
|
||||
ASSERT(!arb_overlaps(neg_inf, pos_inf_err));
|
||||
ASSERT(arb_overlaps(neg_inf, neg_inf_err));
|
||||
ASSERT(arb_overlaps(neg_inf, zero_pm_inf));
|
||||
ASSERT(arb_overlaps(neg_inf, pos_pm_inf));
|
||||
ASSERT(arb_overlaps(neg_inf, neg_pm_inf));
|
||||
ASSERT(arb_overlaps(neg_inf, indet_exact));
|
||||
ASSERT(arb_overlaps(neg_inf, indet_pos_rad));
|
||||
ASSERT(arb_overlaps(neg_inf, indet_inf_rad));
|
||||
ASSERT(!arb_overlaps(pos_inf_err, zero));
|
||||
ASSERT(!arb_overlaps(pos_inf_err, pos));
|
||||
ASSERT(!arb_overlaps(pos_inf_err, neg));
|
||||
ASSERT(arb_overlaps(pos_inf_err, pos_inf));
|
||||
ASSERT(!arb_overlaps(pos_inf_err, neg_inf));
|
||||
ASSERT(arb_overlaps(pos_inf_err, pos_inf_err));
|
||||
ASSERT(!arb_overlaps(pos_inf_err, neg_inf_err));
|
||||
ASSERT(arb_overlaps(pos_inf_err, zero_pm_inf));
|
||||
ASSERT(arb_overlaps(pos_inf_err, pos_pm_inf));
|
||||
ASSERT(arb_overlaps(pos_inf_err, neg_pm_inf));
|
||||
ASSERT(arb_overlaps(pos_inf_err, indet_exact));
|
||||
ASSERT(arb_overlaps(pos_inf_err, indet_pos_rad));
|
||||
ASSERT(arb_overlaps(pos_inf_err, indet_inf_rad));
|
||||
ASSERT(!arb_overlaps(neg_inf_err, zero));
|
||||
ASSERT(!arb_overlaps(neg_inf_err, pos));
|
||||
ASSERT(!arb_overlaps(neg_inf_err, neg));
|
||||
ASSERT(!arb_overlaps(neg_inf_err, pos_inf));
|
||||
ASSERT(arb_overlaps(neg_inf_err, neg_inf));
|
||||
ASSERT(!arb_overlaps(neg_inf_err, pos_inf_err));
|
||||
ASSERT(arb_overlaps(neg_inf_err, neg_inf_err));
|
||||
ASSERT(arb_overlaps(neg_inf_err, zero_pm_inf));
|
||||
ASSERT(arb_overlaps(neg_inf_err, pos_pm_inf));
|
||||
ASSERT(arb_overlaps(neg_inf_err, neg_pm_inf));
|
||||
ASSERT(arb_overlaps(neg_inf_err, indet_exact));
|
||||
ASSERT(arb_overlaps(neg_inf_err, indet_pos_rad));
|
||||
ASSERT(arb_overlaps(neg_inf_err, indet_inf_rad));
|
||||
ASSERT(arb_overlaps(zero_pm_inf, zero));
|
||||
ASSERT(arb_overlaps(zero_pm_inf, pos));
|
||||
ASSERT(arb_overlaps(zero_pm_inf, neg));
|
||||
ASSERT(arb_overlaps(zero_pm_inf, pos_inf));
|
||||
ASSERT(arb_overlaps(zero_pm_inf, neg_inf));
|
||||
ASSERT(arb_overlaps(zero_pm_inf, pos_inf_err));
|
||||
ASSERT(arb_overlaps(zero_pm_inf, neg_inf_err));
|
||||
ASSERT(arb_overlaps(zero_pm_inf, zero_pm_inf));
|
||||
ASSERT(arb_overlaps(zero_pm_inf, pos_pm_inf));
|
||||
ASSERT(arb_overlaps(zero_pm_inf, neg_pm_inf));
|
||||
ASSERT(arb_overlaps(zero_pm_inf, indet_exact));
|
||||
ASSERT(arb_overlaps(zero_pm_inf, indet_pos_rad));
|
||||
ASSERT(arb_overlaps(zero_pm_inf, indet_inf_rad));
|
||||
ASSERT(arb_overlaps(pos_pm_inf, zero));
|
||||
ASSERT(arb_overlaps(pos_pm_inf, pos));
|
||||
ASSERT(arb_overlaps(pos_pm_inf, neg));
|
||||
ASSERT(arb_overlaps(pos_pm_inf, pos_inf));
|
||||
ASSERT(arb_overlaps(pos_pm_inf, neg_inf));
|
||||
ASSERT(arb_overlaps(pos_pm_inf, pos_inf_err));
|
||||
ASSERT(arb_overlaps(pos_pm_inf, neg_inf_err));
|
||||
ASSERT(arb_overlaps(pos_pm_inf, zero_pm_inf));
|
||||
ASSERT(arb_overlaps(pos_pm_inf, pos_pm_inf));
|
||||
ASSERT(arb_overlaps(pos_pm_inf, neg_pm_inf));
|
||||
ASSERT(arb_overlaps(pos_pm_inf, indet_exact));
|
||||
ASSERT(arb_overlaps(pos_pm_inf, indet_pos_rad));
|
||||
ASSERT(arb_overlaps(pos_pm_inf, indet_inf_rad));
|
||||
ASSERT(arb_overlaps(neg_pm_inf, zero));
|
||||
ASSERT(arb_overlaps(neg_pm_inf, pos));
|
||||
ASSERT(arb_overlaps(neg_pm_inf, neg));
|
||||
ASSERT(arb_overlaps(neg_pm_inf, pos_inf));
|
||||
ASSERT(arb_overlaps(neg_pm_inf, neg_inf));
|
||||
ASSERT(arb_overlaps(neg_pm_inf, pos_inf_err));
|
||||
ASSERT(arb_overlaps(neg_pm_inf, neg_inf_err));
|
||||
ASSERT(arb_overlaps(neg_pm_inf, zero_pm_inf));
|
||||
ASSERT(arb_overlaps(neg_pm_inf, pos_pm_inf));
|
||||
ASSERT(arb_overlaps(neg_pm_inf, neg_pm_inf));
|
||||
ASSERT(arb_overlaps(neg_pm_inf, indet_exact));
|
||||
ASSERT(arb_overlaps(neg_pm_inf, indet_pos_rad));
|
||||
ASSERT(arb_overlaps(neg_pm_inf, indet_inf_rad));
|
||||
ASSERT(arb_overlaps(indet_exact, zero));
|
||||
ASSERT(arb_overlaps(indet_exact, pos));
|
||||
ASSERT(arb_overlaps(indet_exact, neg));
|
||||
ASSERT(arb_overlaps(indet_exact, pos_inf));
|
||||
ASSERT(arb_overlaps(indet_exact, neg_inf));
|
||||
ASSERT(arb_overlaps(indet_exact, pos_inf_err));
|
||||
ASSERT(arb_overlaps(indet_exact, neg_inf_err));
|
||||
ASSERT(arb_overlaps(indet_exact, zero_pm_inf));
|
||||
ASSERT(arb_overlaps(indet_exact, pos_pm_inf));
|
||||
ASSERT(arb_overlaps(indet_exact, neg_pm_inf));
|
||||
ASSERT(arb_overlaps(indet_exact, indet_exact));
|
||||
ASSERT(arb_overlaps(indet_exact, indet_pos_rad));
|
||||
ASSERT(arb_overlaps(indet_exact, indet_inf_rad));
|
||||
ASSERT(arb_overlaps(indet_pos_rad, zero));
|
||||
ASSERT(arb_overlaps(indet_pos_rad, pos));
|
||||
ASSERT(arb_overlaps(indet_pos_rad, neg));
|
||||
ASSERT(arb_overlaps(indet_pos_rad, pos_inf));
|
||||
ASSERT(arb_overlaps(indet_pos_rad, neg_inf));
|
||||
ASSERT(arb_overlaps(indet_pos_rad, pos_inf_err));
|
||||
ASSERT(arb_overlaps(indet_pos_rad, neg_inf_err));
|
||||
ASSERT(arb_overlaps(indet_pos_rad, zero_pm_inf));
|
||||
ASSERT(arb_overlaps(indet_pos_rad, pos_pm_inf));
|
||||
ASSERT(arb_overlaps(indet_pos_rad, neg_pm_inf));
|
||||
ASSERT(arb_overlaps(indet_pos_rad, indet_exact));
|
||||
ASSERT(arb_overlaps(indet_pos_rad, indet_pos_rad));
|
||||
ASSERT(arb_overlaps(indet_pos_rad, indet_inf_rad));
|
||||
ASSERT(arb_overlaps(indet_inf_rad, zero));
|
||||
ASSERT(arb_overlaps(indet_inf_rad, pos));
|
||||
ASSERT(arb_overlaps(indet_inf_rad, neg));
|
||||
ASSERT(arb_overlaps(indet_inf_rad, pos_inf));
|
||||
ASSERT(arb_overlaps(indet_inf_rad, neg_inf));
|
||||
ASSERT(arb_overlaps(indet_inf_rad, pos_inf_err));
|
||||
ASSERT(arb_overlaps(indet_inf_rad, neg_inf_err));
|
||||
ASSERT(arb_overlaps(indet_inf_rad, zero_pm_inf));
|
||||
ASSERT(arb_overlaps(indet_inf_rad, pos_pm_inf));
|
||||
ASSERT(arb_overlaps(indet_inf_rad, neg_pm_inf));
|
||||
ASSERT(arb_overlaps(indet_inf_rad, indet_exact));
|
||||
ASSERT(arb_overlaps(indet_inf_rad, indet_pos_rad));
|
||||
ASSERT(arb_overlaps(indet_inf_rad, indet_inf_rad));
|
||||
|
||||
{
|
||||
fmpz_t t;
|
||||
fmpz_init(t);
|
||||
|
||||
ASSERT(arb_get_unique_fmpz(t, zero));
|
||||
ASSERT(!arb_get_unique_fmpz(t, pos_inf));
|
||||
ASSERT(!arb_get_unique_fmpz(t, neg_inf));
|
||||
ASSERT(!arb_get_unique_fmpz(t, pos_inf_err));
|
||||
ASSERT(!arb_get_unique_fmpz(t, neg_inf_err));
|
||||
ASSERT(!arb_get_unique_fmpz(t, zero_pm_inf));
|
||||
ASSERT(!arb_get_unique_fmpz(t, pos_pm_inf));
|
||||
ASSERT(!arb_get_unique_fmpz(t, neg_pm_inf));
|
||||
ASSERT(!arb_get_unique_fmpz(t, indet_exact));
|
||||
ASSERT(!arb_get_unique_fmpz(t, indet_pos_rad));
|
||||
ASSERT(!arb_get_unique_fmpz(t, indet_inf_rad));
|
||||
|
||||
fmpz_clear(t);
|
||||
}
|
||||
|
||||
{
|
||||
arf_t b;
|
||||
long wp = 30;
|
||||
|
||||
arf_init(b);
|
||||
|
||||
arb_get_abs_ubound_arf(b, zero, wp); ASSERT(arf_is_zero(b));
|
||||
arb_get_abs_ubound_arf(b, pos, wp); ASSERT(arf_sgn(b) > 0);
|
||||
arb_get_abs_ubound_arf(b, neg, wp); ASSERT(arf_sgn(b) > 0);
|
||||
arb_get_abs_ubound_arf(b, pos_inf, wp); ASSERT(arf_is_pos_inf(b));
|
||||
arb_get_abs_ubound_arf(b, neg_inf, wp); ASSERT(arf_is_pos_inf(b));
|
||||
arb_get_abs_ubound_arf(b, pos_inf_err, wp); ASSERT(arf_is_pos_inf(b));
|
||||
arb_get_abs_ubound_arf(b, neg_inf_err, wp); ASSERT(arf_is_pos_inf(b));
|
||||
arb_get_abs_ubound_arf(b, zero_pm_inf, wp); ASSERT(arf_is_pos_inf(b));
|
||||
arb_get_abs_ubound_arf(b, indet_exact, wp); ASSERT(arf_is_nan(b));
|
||||
arb_get_abs_ubound_arf(b, indet_pos_rad, wp); ASSERT(arf_is_nan(b));
|
||||
arb_get_abs_ubound_arf(b, indet_inf_rad, wp); ASSERT(arf_is_nan(b));
|
||||
|
||||
arb_get_abs_lbound_arf(b, zero, wp); ASSERT(arf_is_zero(b));
|
||||
arb_get_abs_lbound_arf(b, pos, wp); ASSERT(arf_sgn(b) > 0);
|
||||
arb_get_abs_lbound_arf(b, neg, wp); ASSERT(arf_sgn(b) > 0);
|
||||
arb_get_abs_lbound_arf(b, pos_inf, wp); ASSERT(arf_is_pos_inf(b));
|
||||
arb_get_abs_lbound_arf(b, neg_inf, wp); ASSERT(arf_is_pos_inf(b));
|
||||
arb_get_abs_lbound_arf(b, pos_inf_err, wp); ASSERT(arf_is_pos_inf(b));
|
||||
arb_get_abs_lbound_arf(b, neg_inf_err, wp); ASSERT(arf_is_pos_inf(b));
|
||||
arb_get_abs_lbound_arf(b, zero_pm_inf, wp); ASSERT(arf_is_zero(b));
|
||||
arb_get_abs_lbound_arf(b, indet_exact, wp); ASSERT(arf_is_nan(b));
|
||||
arb_get_abs_lbound_arf(b, indet_pos_rad, wp); ASSERT(arf_is_nan(b));
|
||||
arb_get_abs_lbound_arf(b, indet_inf_rad, wp); ASSERT(arf_is_nan(b));
|
||||
|
||||
arf_clear(b);
|
||||
}
|
||||
|
||||
arb_clear(zero);
|
||||
arb_clear(pos);
|
||||
arb_clear(neg);
|
||||
arb_clear(pos_inf);
|
||||
arb_clear(neg_inf);
|
||||
arb_clear(pos_inf_err);
|
||||
arb_clear(neg_inf_err);
|
||||
arb_clear(zero_pm_inf);
|
||||
arb_clear(pos_pm_inf);
|
||||
arb_clear(neg_pm_inf);
|
||||
arb_clear(indet_exact);
|
||||
arb_clear(indet_pos_rad);
|
||||
arb_clear(indet_inf_rad);
|
||||
|
||||
#endif
|
||||
|
||||
flint_cleanup();
|
||||
printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
91
arb/test/t-trim.c
Normal file
91
arb/test/t-trim.c
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2013 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
long iter;
|
||||
flint_rand_t state;
|
||||
|
||||
printf("trim....");
|
||||
fflush(stdout);
|
||||
flint_randinit(state);
|
||||
|
||||
for (iter = 0; iter < 100000; iter++)
|
||||
{
|
||||
arb_t x, y;
|
||||
long acc1, acc2;
|
||||
int accuracy_ok;
|
||||
|
||||
arb_init(x);
|
||||
arb_init(y);
|
||||
|
||||
arb_randtest_special(x, state, 1000, 100);
|
||||
|
||||
arb_trim(y, x);
|
||||
|
||||
if (!arb_contains(y, x))
|
||||
{
|
||||
printf("FAIL (containment):\n\n");
|
||||
printf("x = "); arb_print(x); printf("\n\n");
|
||||
printf("y = "); arb_print(y); printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
acc1 = arb_rel_accuracy_bits(x);
|
||||
acc2 = arb_rel_accuracy_bits(y);
|
||||
|
||||
accuracy_ok = (acc1 < 0 && acc2 <= acc1) || (acc2 >= acc1 - 1);
|
||||
|
||||
if (!accuracy_ok)
|
||||
{
|
||||
printf("FAIL (accuracy):\n\n");
|
||||
printf("x: %ld, y = %ld\n\n", acc1, acc2);
|
||||
printf("x = "); arb_print(x); printf("\n\n");
|
||||
printf("y = "); arb_print(y); printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
arb_trim(x, x);
|
||||
|
||||
if (!arb_equal(y, x))
|
||||
{
|
||||
printf("FAIL (aliasing):\n\n");
|
||||
printf("x = "); arb_print(x); printf("\n\n");
|
||||
printf("y = "); arb_print(y); printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
arb_clear(x);
|
||||
arb_clear(y);
|
||||
}
|
||||
|
||||
flint_randclear(state);
|
||||
flint_cleanup();
|
||||
printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
94
arb/test/t-union.c
Normal file
94
arb/test/t-union.c
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
long iter;
|
||||
flint_rand_t state;
|
||||
|
||||
printf("union....");
|
||||
fflush(stdout);
|
||||
flint_randinit(state);
|
||||
|
||||
for (iter = 0; iter < 100000; iter++)
|
||||
{
|
||||
arb_t x, y, z;
|
||||
long prec;
|
||||
int alias;
|
||||
|
||||
arb_init(x);
|
||||
arb_init(y);
|
||||
arb_init(z);
|
||||
|
||||
arb_randtest_special(x, state, 200, 10);
|
||||
arb_randtest_special(y, state, 200, 10);
|
||||
arb_randtest_special(z, state, 200, 10);
|
||||
|
||||
prec = 2 + n_randint(state, 200);
|
||||
|
||||
arb_union(z, x, y, prec);
|
||||
|
||||
if (!arb_contains(z, x) || !arb_contains(z, y))
|
||||
{
|
||||
printf("FAIL:\n\n");
|
||||
printf("x = "); arb_print(x); printf("\n\n");
|
||||
printf("y = "); arb_print(y); printf("\n\n");
|
||||
printf("z = "); arb_print(z); printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (n_randint(state, 2))
|
||||
{
|
||||
arb_union(x, x, y, prec);
|
||||
alias = arb_equal(x, z);
|
||||
}
|
||||
else
|
||||
{
|
||||
arb_union(y, x, y, prec);
|
||||
alias = arb_equal(y, z);
|
||||
}
|
||||
|
||||
if (!alias)
|
||||
{
|
||||
printf("FAIL (aliasing):\n\n");
|
||||
printf("x = "); arb_print(x); printf("\n\n");
|
||||
printf("y = "); arb_print(y); printf("\n\n");
|
||||
printf("z = "); arb_print(z); printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
arb_clear(x);
|
||||
arb_clear(y);
|
||||
arb_clear(z);
|
||||
}
|
||||
|
||||
flint_randclear(state);
|
||||
flint_cleanup();
|
||||
printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
71
arb/trim.c
Normal file
71
arb/trim.c
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2013-2014 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
#define TRIM_PADDING 16
|
||||
|
||||
void
|
||||
arb_trim(arb_t y, const arb_t x)
|
||||
{
|
||||
if (mag_is_zero(arb_radref(x)) || arf_is_special(arb_midref(x)))
|
||||
{
|
||||
arb_set(y, x);
|
||||
}
|
||||
else if (mag_is_special(arb_radref(x)))
|
||||
{
|
||||
/* midpoint must be finite, so set to 0 +/- inf */
|
||||
arb_zero_pm_inf(y);
|
||||
}
|
||||
else
|
||||
{
|
||||
long bits, accuracy;
|
||||
|
||||
bits = arb_bits(x);
|
||||
accuracy = arb_rel_accuracy_bits(x);
|
||||
|
||||
if (accuracy < -TRIM_PADDING)
|
||||
{
|
||||
mag_t t;
|
||||
|
||||
/* set to 0 +/- r */
|
||||
mag_init(t);
|
||||
arf_get_mag(t, arb_midref(x));
|
||||
mag_add(arb_radref(y), t, arb_radref(x));
|
||||
mag_clear(t);
|
||||
|
||||
arf_zero(arb_midref(y));
|
||||
}
|
||||
else if (accuracy < bits - TRIM_PADDING)
|
||||
{
|
||||
arb_set_round(y, x, FLINT_MAX(0, accuracy) + TRIM_PADDING);
|
||||
}
|
||||
else
|
||||
{
|
||||
arb_set(y, x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
48
arb/union.c
Normal file
48
arb/union.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2013 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
void
|
||||
arb_union(arb_t z, const arb_t x, const arb_t y, long prec)
|
||||
{
|
||||
fmprb_t t, u, v;
|
||||
|
||||
fmprb_init(t);
|
||||
fmprb_init(u);
|
||||
fmprb_init(v);
|
||||
|
||||
arb_get_fmprb(t, x);
|
||||
arb_get_fmprb(u, y);
|
||||
|
||||
fmprb_union(v, t, u, prec);
|
||||
|
||||
arb_set_fmprb(z, v);
|
||||
|
||||
fmprb_clear(t);
|
||||
fmprb_clear(u);
|
||||
fmprb_clear(v);
|
||||
}
|
||||
|
77
arf.h
77
arf.h
|
@ -468,6 +468,40 @@ arf_set_si(arf_t x, long v)
|
|||
ARF_NEG(x);
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
arf_cmpabs_ui(const arf_t x, ulong y)
|
||||
{
|
||||
arf_t t;
|
||||
arf_init_set_ui(t, y); /* no need to free */
|
||||
return arf_cmpabs(x, t);
|
||||
}
|
||||
|
||||
/* TODO: document */
|
||||
static __inline__ void
|
||||
arf_init_set_mag_shallow(arf_t y, const mag_t x)
|
||||
{
|
||||
mp_limb_t t = MAG_MAN(x);
|
||||
ARF_XSIZE(y) = ARF_MAKE_XSIZE(t != 0, 0);
|
||||
ARF_EXP(y) = MAG_EXP(x);
|
||||
ARF_NOPTR_D(y)[0] = t << (FLINT_BITS - MAG_BITS);
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
arf_cmpabs_mag(const arf_t x, const mag_t y)
|
||||
{
|
||||
arf_t t;
|
||||
arf_init_set_mag_shallow(t, y); /* no need to free */
|
||||
return arf_cmpabs(x, t);
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
arf_mag_cmpabs(const mag_t x, const arf_t y)
|
||||
{
|
||||
arf_t t;
|
||||
arf_init_set_mag_shallow(t, x); /* no need to free */
|
||||
return arf_cmpabs(t, y);
|
||||
}
|
||||
|
||||
/* Assumes xn > 0, x[0] != 0. */
|
||||
/* TBD: 1, 2 limb versions */
|
||||
void arf_set_mpn(arf_t y, mp_srcptr x, mp_size_t xn, int sgnbit);
|
||||
|
@ -1133,6 +1167,49 @@ mag_fast_init_set_arf(mag_t y, const arf_t x)
|
|||
}
|
||||
}
|
||||
|
||||
/* TODO: document */
|
||||
static __inline__ void
|
||||
arf_mag_add_ulp(mag_t z, const mag_t x, const arf_t y, long prec)
|
||||
{
|
||||
if (ARF_IS_SPECIAL(y))
|
||||
{
|
||||
printf("error: ulp error not defined for special value!\n");
|
||||
abort();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* todo: speed up case r is special here */
|
||||
fmpz_t e;
|
||||
fmpz_init(e);
|
||||
_fmpz_add_fast(e, ARF_EXPREF(y), -prec);
|
||||
mag_add_2exp_fmpz(z, x, e);
|
||||
fmpz_clear(e);
|
||||
}
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
arf_mag_set_ulp(mag_t z, const arf_t y, long prec)
|
||||
{
|
||||
if (ARF_IS_SPECIAL(y))
|
||||
{
|
||||
printf("error: ulp error not defined for special value!\n");
|
||||
abort();
|
||||
}
|
||||
else
|
||||
{
|
||||
_fmpz_add_fast(MAG_EXPREF(z), ARF_EXPREF(y), 1 - prec);
|
||||
MAG_MAN(z) = MAG_ONE_HALF;
|
||||
}
|
||||
}
|
||||
|
||||
void arf_get_fmpq(fmpq_t y, const arf_t x);
|
||||
|
||||
static __inline__ int
|
||||
arf_set_fmpq(arf_t y, const fmpq_t x, long prec, arf_rnd_t rnd)
|
||||
{
|
||||
return arf_fmpz_div_fmpz(y, fmpq_numref(x), fmpq_denref(x), prec, rnd);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
67
arf/get_fmpq.c
Normal file
67
arf/get_fmpq.c
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arf.h"
|
||||
|
||||
void
|
||||
arf_get_fmpq(fmpq_t y, const arf_t x)
|
||||
{
|
||||
if (arf_is_zero(x))
|
||||
{
|
||||
fmpq_zero(y);
|
||||
}
|
||||
else if (arf_is_special(x) || !ARF_IS_LAGOM(x))
|
||||
{
|
||||
printf("exception: arf_get_fmpq: cannot convert to rational\n");
|
||||
abort();
|
||||
}
|
||||
else
|
||||
{
|
||||
fmpz_t man, exp;
|
||||
long e;
|
||||
|
||||
fmpz_init(man);
|
||||
fmpz_init(exp);
|
||||
|
||||
arf_get_fmpz_2exp(man, exp, x);
|
||||
|
||||
e = *exp;
|
||||
|
||||
fmpz_set_ui(fmpq_denref(y), 1UL);
|
||||
|
||||
if (e >= 0)
|
||||
{
|
||||
fmpz_mul_2exp(fmpq_numref(y), man, e);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmpz_set(fmpq_numref(y), man);
|
||||
fmpz_mul_2exp(fmpq_denref(y), fmpq_denref(y), -e);
|
||||
}
|
||||
|
||||
fmpz_clear(man);
|
||||
fmpz_clear(exp);
|
||||
}
|
||||
}
|
77
arf/test/t-set_fmpq.c
Normal file
77
arf/test/t-set_fmpq.c
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arf.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
long iter;
|
||||
flint_rand_t state;
|
||||
|
||||
printf("set_fmpq....");
|
||||
fflush(stdout);
|
||||
|
||||
flint_randinit(state);
|
||||
|
||||
/* test exact roundtrip R -> Q -> R */
|
||||
for (iter = 0; iter < 100000; iter++)
|
||||
{
|
||||
long bits, res;
|
||||
arf_t x, z;
|
||||
fmpq_t y;
|
||||
|
||||
bits = 2 + n_randint(state, 200);
|
||||
|
||||
arf_init(x);
|
||||
arf_init(z);
|
||||
fmpq_init(y);
|
||||
|
||||
arf_randtest(x, state, bits, 10);
|
||||
arf_randtest(z, state, bits, 10);
|
||||
|
||||
arf_get_fmpq(y, x);
|
||||
res = arf_set_fmpq(z, y, bits, ARF_RND_DOWN);
|
||||
|
||||
if (!arf_equal(x, z) || res != 0)
|
||||
{
|
||||
printf("FAIL\n\n");
|
||||
printf("bits: %ld\n", bits);
|
||||
printf("x = "); arf_print(x); printf("\n\n");
|
||||
printf("y = "); fmpq_print(y); printf("\n\n");
|
||||
printf("z = "); arf_print(z); printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
arf_clear(x);
|
||||
arf_clear(z);
|
||||
fmpq_clear(y);
|
||||
}
|
||||
|
||||
flint_randclear(state);
|
||||
flint_cleanup();
|
||||
printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
|
@ -216,6 +216,10 @@ Comparisons and bounds
|
|||
|
||||
.. function:: int arf_cmpabs(const arf_t x, const arf_t y)
|
||||
|
||||
.. function:: int arf_cmpabs_ui(const arf_t x, ulong y)
|
||||
|
||||
.. function:: int arf_cmpabs_mag(const arf_t x, const mag_t y)
|
||||
|
||||
Compares the absolute values of *x* and *y*.
|
||||
|
||||
.. function:: int arf_cmp_2exp_si(const arf_t x, long e)
|
||||
|
|
84
mag.h
84
mag.h
|
@ -262,6 +262,21 @@ mag_is_inf(const mag_t x)
|
|||
return (MAG_MAN(x) == 0) && (MAG_EXP(x) != 0);
|
||||
}
|
||||
|
||||
/* TODO: document */
|
||||
static __inline__ int
|
||||
mag_is_finite(const mag_t x)
|
||||
{
|
||||
return !mag_is_inf(x);
|
||||
}
|
||||
|
||||
/* TODO: document */
|
||||
static __inline__ int
|
||||
mag_equal(const mag_t x, const mag_t y)
|
||||
{
|
||||
return (MAG_MAN(x) == MAG_MAN(y))
|
||||
&& fmpz_equal(MAG_EXPREF(x), MAG_EXPREF(y));
|
||||
}
|
||||
|
||||
/* general versions */
|
||||
|
||||
void mag_mul(mag_t z, const mag_t x, const mag_t y);
|
||||
|
@ -270,8 +285,40 @@ void mag_addmul(mag_t z, const mag_t x, const mag_t y);
|
|||
|
||||
void mag_add_2exp_fmpz(mag_t z, const mag_t x, const fmpz_t e);
|
||||
|
||||
void mag_add(mag_t z, const mag_t x, const mag_t y);
|
||||
|
||||
void mag_div(mag_t z, const mag_t x, const mag_t y);
|
||||
|
||||
/* TODO: document */
|
||||
static __inline__ void
|
||||
mag_mul_2exp_si(mag_t z, const mag_t x, long y)
|
||||
{
|
||||
if (mag_is_special(x))
|
||||
{
|
||||
mag_set(z, x);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmpz_add_si_inline(MAG_EXPREF(z), MAG_EXPREF(x), y);
|
||||
MAG_MAN(z) = MAG_MAN(x);
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: document */
|
||||
static __inline__ void
|
||||
mag_mul_2exp_fmpz(mag_t z, const mag_t x, const fmpz_t y)
|
||||
{
|
||||
if (mag_is_special(x))
|
||||
{
|
||||
mag_set(z, x);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmpz_add_inline(MAG_EXPREF(z), MAG_EXPREF(x), y);
|
||||
MAG_MAN(z) = MAG_MAN(x);
|
||||
}
|
||||
}
|
||||
|
||||
/* Fast versions (no infs/nans, small exponents). Note that this
|
||||
applies to outputs too! */
|
||||
|
||||
|
@ -414,8 +461,9 @@ mag_get_fmpr(fmpr_t x, const mag_t r)
|
|||
}
|
||||
}
|
||||
|
||||
/* TODO: document */
|
||||
static __inline__ void
|
||||
mag_randtest(mag_t x, flint_rand_t state, long expbits)
|
||||
mag_randtest_special(mag_t x, flint_rand_t state, long expbits)
|
||||
{
|
||||
switch (n_randint(state, 32))
|
||||
{
|
||||
|
@ -440,18 +488,50 @@ mag_randtest(mag_t x, flint_rand_t state, long expbits)
|
|||
}
|
||||
}
|
||||
|
||||
/* TODO: update documentation */
|
||||
static __inline__ void
|
||||
mag_randtest(mag_t x, flint_rand_t state, long expbits)
|
||||
{
|
||||
mag_randtest_special(x, state, expbits);
|
||||
if (mag_is_inf(x))
|
||||
mag_zero(x);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
mag_print(const mag_t x)
|
||||
{
|
||||
printf("(");
|
||||
if (mag_is_zero(x))
|
||||
printf("0");
|
||||
else if (mag_is_inf(x))
|
||||
printf("inf");
|
||||
else
|
||||
{
|
||||
printf("%lu x ", MAG_MAN(x));
|
||||
printf("%lu * 2^", MAG_MAN(x));
|
||||
fmpz_print(MAG_EXPREF(x));
|
||||
}
|
||||
printf(")");
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
mag_printd(const mag_t x, long d)
|
||||
{
|
||||
fmpr_t t;
|
||||
fmpr_init(t);
|
||||
mag_get_fmpr(t, x);
|
||||
fmpr_printd(t, d);
|
||||
fmpr_clear(t);
|
||||
}
|
||||
|
||||
/* TODO: document */
|
||||
static __inline__ void
|
||||
mag_get_fmpq(fmpq_t y, const mag_t x)
|
||||
{
|
||||
fmpr_t t;
|
||||
fmpr_init(t);
|
||||
mag_get_fmpr(t, x);
|
||||
fmpr_get_fmpq(y, t);
|
||||
fmpr_clear(t);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
78
mag/add.c
Normal file
78
mag/add.c
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2014 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "mag.h"
|
||||
|
||||
void
|
||||
mag_add(mag_t z, const mag_t x, const mag_t y)
|
||||
{
|
||||
if (mag_is_zero(x))
|
||||
{
|
||||
mag_set(z, y);
|
||||
}
|
||||
else if (mag_is_zero(y))
|
||||
{
|
||||
mag_set(z, x);
|
||||
}
|
||||
else if (mag_is_inf(x) || mag_is_inf(y))
|
||||
{
|
||||
mag_inf(z);
|
||||
}
|
||||
else
|
||||
{
|
||||
long shift;
|
||||
shift = _fmpz_sub_small(MAG_EXPREF(x), MAG_EXPREF(y));
|
||||
|
||||
if (shift == 0)
|
||||
{
|
||||
_fmpz_set_fast(MAG_EXPREF(z), MAG_EXPREF(x));
|
||||
MAG_MAN(z) = MAG_MAN(x) + MAG_MAN(y);
|
||||
MAG_ADJUST_ONE_TOO_LARGE(z); /* may need two adjustments */
|
||||
}
|
||||
else if (shift > 0)
|
||||
{
|
||||
_fmpz_set_fast(MAG_EXPREF(z), MAG_EXPREF(x));
|
||||
|
||||
if (shift >= MAG_BITS)
|
||||
MAG_MAN(z) = MAG_MAN(x) + LIMB_ONE;
|
||||
else
|
||||
MAG_MAN(z) = MAG_MAN(x) + (MAG_MAN(y) >> shift) + LIMB_ONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
shift = -shift;
|
||||
_fmpz_set_fast(MAG_EXPREF(z), MAG_EXPREF(y));
|
||||
|
||||
if (shift >= MAG_BITS)
|
||||
MAG_MAN(z) = MAG_MAN(y) + LIMB_ONE;
|
||||
else
|
||||
MAG_MAN(z) = MAG_MAN(y) + (MAG_MAN(x) >> shift) + LIMB_ONE;
|
||||
}
|
||||
|
||||
/* TODO: combine */
|
||||
MAG_ADJUST_ONE_TOO_LARGE(z);
|
||||
}
|
||||
}
|
||||
|
80
mag/add_error.c
Normal file
80
mag/add_error.c
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2012-2014 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "arb.h"
|
||||
|
||||
/* TODO: improve these */
|
||||
|
||||
void
|
||||
arb_add_error_arf(arb_t x, const arf_t err)
|
||||
{
|
||||
mag_t t;
|
||||
mag_init(t);
|
||||
arf_get_mag(t, err);
|
||||
mag_add(arb_radref(x), arb_radref(x), t);
|
||||
mag_clear(t);
|
||||
}
|
||||
|
||||
void
|
||||
arb_add_error_2exp_si(arb_t x, long err)
|
||||
{
|
||||
fmpz_t t;
|
||||
fmpz_init(t);
|
||||
fmpz_set_si(t, err);
|
||||
mag_add_2exp_fmpz(arb_radref(x), arb_radref(x), t);
|
||||
fmpz_clear(t);
|
||||
}
|
||||
|
||||
void
|
||||
arb_add_error_2exp_fmpz(arb_t x, const fmpz_t err)
|
||||
{
|
||||
mag_add_2exp_fmpz(arb_radref(x), arb_radref(x), err);
|
||||
}
|
||||
|
||||
void
|
||||
arb_add_error(arb_t x, const arb_t error)
|
||||
{
|
||||
arf_t t;
|
||||
mag_t u;
|
||||
|
||||
arf_init(t);
|
||||
mag_init(u);
|
||||
|
||||
arf_set_mag(t, arb_radref(error));
|
||||
arf_add(t, arb_midref(error), t, MAG_BITS, ARF_RND_UP);
|
||||
|
||||
if (arf_sgn(t) < 0)
|
||||
{
|
||||
printf("arb_add_error: error must be nonnegative!\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
arf_get_mag(u, t);
|
||||
mag_add(arb_radref(x), arb_radref(x), u);
|
||||
|
||||
arf_clear(t);
|
||||
mag_clear(u);
|
||||
}
|
||||
|
99
mag/test/t-add.c
Normal file
99
mag/test/t-add.c
Normal file
|
@ -0,0 +1,99 @@
|
|||
/*=============================================================================
|
||||
|
||||
This file is part of ARB.
|
||||
|
||||
ARB is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ARB is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ARB; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2014 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "mag.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
long iter;
|
||||
flint_rand_t state;
|
||||
|
||||
printf("add....");
|
||||
fflush(stdout);
|
||||
|
||||
flint_randinit(state);
|
||||
|
||||
for (iter = 0; iter < 100000; iter++)
|
||||
{
|
||||
fmpr_t x, y, z, z2, w;
|
||||
mag_t xb, yb, zb;
|
||||
|
||||
fmpr_init(x);
|
||||
fmpr_init(y);
|
||||
fmpr_init(z);
|
||||
fmpr_init(z2);
|
||||
fmpr_init(w);
|
||||
|
||||
mag_init(xb);
|
||||
mag_init(yb);
|
||||
mag_init(zb);
|
||||
|
||||
mag_randtest_special(xb, state, 100);
|
||||
mag_randtest_special(yb, state, 100);
|
||||
|
||||
mag_get_fmpr(x, xb);
|
||||
mag_get_fmpr(y, yb);
|
||||
|
||||
fmpr_add(z, x, y, MAG_BITS + 10, FMPR_RND_DOWN);
|
||||
if (fmpr_is_nan(z))
|
||||
fmpr_pos_inf(z);
|
||||
|
||||
fmpr_mul_ui(z2, z, 1025, MAG_BITS, FMPR_RND_UP);
|
||||
fmpr_mul_2exp_si(z2, z2, -10);
|
||||
|
||||
mag_add(zb, xb, yb);
|
||||
mag_get_fmpr(w, zb);
|
||||
|
||||
MAG_CHECK_BITS(xb)
|
||||
MAG_CHECK_BITS(yb)
|
||||
MAG_CHECK_BITS(zb)
|
||||
|
||||
if (!(fmpr_cmpabs(z, w) <= 0 && fmpr_cmpabs(w, z2) <= 0))
|
||||
{
|
||||
printf("FAIL\n\n");
|
||||
printf("x = "); fmpr_print(x); printf("\n\n");
|
||||
printf("y = "); fmpr_print(y); printf("\n\n");
|
||||
printf("z = "); fmpr_print(z); printf("\n\n");
|
||||
printf("w = "); fmpr_print(w); printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpr_clear(x);
|
||||
fmpr_clear(y);
|
||||
fmpr_clear(z);
|
||||
fmpr_clear(z2);
|
||||
fmpr_clear(w);
|
||||
|
||||
mag_clear(xb);
|
||||
mag_clear(yb);
|
||||
mag_clear(zb);
|
||||
}
|
||||
|
||||
flint_randclear(state);
|
||||
flint_cleanup();
|
||||
printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -50,9 +50,9 @@ int main()
|
|||
mag_init(yb);
|
||||
mag_init(zb);
|
||||
|
||||
mag_randtest(xb, state, 100);
|
||||
mag_randtest(yb, state, 100);
|
||||
mag_randtest(zb, state, 100);
|
||||
mag_randtest_special(xb, state, 100);
|
||||
mag_randtest_special(yb, state, 100);
|
||||
mag_randtest_special(zb, state, 100);
|
||||
|
||||
mag_get_fmpr(x, xb);
|
||||
mag_get_fmpr(y, yb);
|
||||
|
|
|
@ -50,8 +50,8 @@ int main()
|
|||
mag_init(yb);
|
||||
mag_init(zb);
|
||||
|
||||
mag_randtest(xb, state, 10);
|
||||
mag_randtest(yb, state, 10);
|
||||
mag_randtest_special(xb, state, 10);
|
||||
mag_randtest_special(yb, state, 10);
|
||||
|
||||
mag_get_fmpr(x, xb);
|
||||
mag_get_fmpr(y, yb);
|
||||
|
|
|
@ -54,11 +54,6 @@ int main()
|
|||
mag_randtest(yb, state, 15);
|
||||
mag_randtest(zb, state, 15);
|
||||
|
||||
/* not supported */
|
||||
if (mag_is_inf(xb)) mag_zero(xb);
|
||||
if (mag_is_inf(yb)) mag_zero(yb);
|
||||
if (mag_is_inf(zb)) mag_zero(zb);
|
||||
|
||||
mag_get_fmpr(x, xb);
|
||||
mag_get_fmpr(y, yb);
|
||||
mag_get_fmpr(z, zb);
|
||||
|
|
|
@ -53,10 +53,6 @@ int main()
|
|||
mag_randtest(xb, state, 15);
|
||||
mag_randtest(yb, state, 15);
|
||||
|
||||
/* not supported */
|
||||
if (mag_is_inf(xb)) mag_zero(xb);
|
||||
if (mag_is_inf(yb)) mag_zero(yb);
|
||||
|
||||
mag_get_fmpr(x, xb);
|
||||
mag_get_fmpr(y, yb);
|
||||
|
||||
|
|
|
@ -50,8 +50,8 @@ int main()
|
|||
mag_init(yb);
|
||||
mag_init(zb);
|
||||
|
||||
mag_randtest(xb, state, 100);
|
||||
mag_randtest(yb, state, 100);
|
||||
mag_randtest_special(xb, state, 100);
|
||||
mag_randtest_special(yb, state, 100);
|
||||
|
||||
mag_get_fmpr(x, xb);
|
||||
mag_get_fmpr(y, yb);
|
||||
|
|
Loading…
Add table
Reference in a new issue