From 08a85134625b96ebe38d8bc3b9ad9dbbb6309541 Mon Sep 17 00:00:00 2001 From: Fredrik Johansson Date: Wed, 14 May 2014 12:04:08 +0200 Subject: [PATCH] fix --- arb_poly/newton_step.c | 2 +- mag.h | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/arb_poly/newton_step.c b/arb_poly/newton_step.c index b8ef2782..a7d3a529 100644 --- a/arb_poly/newton_step.c +++ b/arb_poly/newton_step.c @@ -55,7 +55,7 @@ _arb_poly_newton_step(arb_t xnew, arb_srcptr poly, long len, arb_add_error_arf(u, err); if (arb_contains(convergence_interval, u) && - (arf_cmpabs_mag(arb_radref(u), arb_radref(x)) < 0)) + (mag_cmp(arb_radref(u), arb_radref(x)) < 0)) { arb_swap(xnew, u); result = 1; diff --git a/mag.h b/mag.h index 89dcbdfd..3b75bb8b 100644 --- a/mag.h +++ b/mag.h @@ -548,6 +548,31 @@ mag_get_fmpq(fmpq_t y, const mag_t x) fmpr_clear(t); } +/* TODO: document/test */ +static __inline__ int +mag_cmp(const mag_t x, const mag_t y) +{ + int c; + + if (mag_equal(x, y)) + return 0; + + if (mag_is_special(x) || mag_is_special(y)) + { + if (mag_is_zero(x)) return -1; + if (mag_is_zero(y)) return 1; + if (mag_is_inf(x)) return 1; + if (mag_is_inf(y)) return -1; + } + + c = fmpz_cmp(MAG_EXPREF(x), MAG_EXPREF(y)); + + if (c == 0) + return (MAG_MAN(x) < MAG_MAN(y)) ? -1 : 1; + + return (c < 0) ? -1 : 1; +} + #ifdef __cplusplus } #endif