1 /*
2     Copyright (C) 2012 Fredrik Johansson
3 
4     This file is part of Arb.
5 
6     Arb is free software: you can redistribute it and/or modify it under
7     the terms of the GNU Lesser General Public License (LGPL) as published
8     by the Free Software Foundation; either version 2.1 of the License, or
9     (at your option) any later version.  See <http://www.gnu.org/licenses/>.
10 */
11 
12 #include "acb.h"
13 
14 #ifndef __compar_fn_t
15 #if defined(_MSC_VER)
16 typedef int(*__compar_fn_t) (const void *, const void *);
17 #else
18 typedef int(*__compar_fn_t) (__const void *, __const void *);
19 #endif
20 #endif
21 
acb_cmp_pretty(const acb_t a,const acb_t b)22 int acb_cmp_pretty(const acb_t a, const acb_t b)
23 {
24     arb_t t, u, v;
25     int res;
26     arb_init(t);
27     arb_init(u);
28     arb_init(v);
29     arb_abs(u, acb_imagref(a));
30     arb_abs(v, acb_imagref(b));
31     arb_sub(t, u, v, MAG_BITS);
32     res = 0;
33     if (arb_contains_zero(t))
34     {
35         arb_sub(t, acb_realref(a), acb_realref(b), MAG_BITS);
36         res = arb_is_positive(t) ? 1 : -1;
37     }
38     else
39     {
40         res = arb_is_positive(t) ? 1 : -1;
41     }
42     arb_clear(t);
43     arb_clear(u);
44     arb_clear(v);
45     return res;
46 }
47 
_acb_vec_sort_pretty(acb_ptr vec,slong len)48 void _acb_vec_sort_pretty(acb_ptr vec, slong len)
49 {
50     qsort(vec, len, sizeof(acb_struct), (__compar_fn_t) acb_cmp_pretty);
51 }
52 
53