This file is indexed.

/usr/include/fmprb.h is in libflint-arb-dev 2.8.1-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
/*=============================================================================

    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

******************************************************************************/

#ifndef FMPRB_H
#define FMPRB_H

#include "fmpr.h"
#include "flint/fmpz_poly.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct
{
    fmpr_struct mid;
    fmpr_struct rad;
}
fmprb_struct;

typedef fmprb_struct fmprb_t[1];
typedef fmprb_struct * fmprb_ptr;
typedef const fmprb_struct * fmprb_srcptr;

#define fmprb_midref(x) (&(x)->mid)
#define fmprb_radref(x) (&(x)->rad)


#define FMPRB_RAD_PREC 30
#define FMPRB_MIN_ADJUSTED_PREC 

static __inline__ void
fmprb_init(fmprb_t x)
{
    fmpr_init(fmprb_midref(x));
    fmpr_init(fmprb_radref(x));
}

#define FMPRB_DEBUG 0

static __inline__ void
fmprb_clear(fmprb_t x)
{
#if FMPRB_DEBUG
    if (fmpr_is_nan(fmprb_radref(x)) || fmpr_sgn(fmprb_radref(x)) < 0)
    {
        flint_printf("ABORT: nan or negative radius!\n");
        abort();
    }
#endif

    fmpr_clear(fmprb_midref(x));
    fmpr_clear(fmprb_radref(x));
}

static __inline__ fmprb_ptr
_fmprb_vec_init(slong n)
{
    slong i;
    fmprb_ptr v = (fmprb_ptr) flint_malloc(sizeof(fmprb_struct) * n);

    for (i = 0; i < n; i++)
        fmprb_init(v + i);

    return v;
}

static __inline__ void
_fmprb_vec_clear(fmprb_ptr v, slong n)
{
    slong i;
    for (i = 0; i < n; i++)
        fmprb_clear(v + i);
    flint_free(v);
}

static __inline__ int
fmprb_is_exact(const fmprb_t x)
{
    return fmpr_is_zero(fmprb_radref(x));
}

static __inline__ int
fmprb_equal(const fmprb_t x, const fmprb_t y)
{
    return fmpr_equal(fmprb_midref(x), fmprb_midref(y)) &&
            fmpr_equal(fmprb_radref(x), fmprb_radref(y));
}

static __inline__ void
fmprb_zero(fmprb_t x)
{
    fmpr_zero(fmprb_midref(x));
    fmpr_zero(fmprb_radref(x));
}

static __inline__ int
fmprb_is_zero(const fmprb_t x)
{
    return fmpr_is_zero(fmprb_midref(x)) && fmpr_is_zero(fmprb_radref(x));
}

static __inline__ void
fmprb_pos_inf(fmprb_t x)
{
    fmpr_pos_inf(fmprb_midref(x));
    fmpr_zero(fmprb_radref(x));
}

static __inline__ void
fmprb_neg_inf(fmprb_t x)
{
    fmpr_neg_inf(fmprb_midref(x));
    fmpr_zero(fmprb_radref(x));
}

static __inline__ void
fmprb_zero_pm_inf(fmprb_t x)
{
    fmpr_zero(fmprb_midref(x));
    fmpr_pos_inf(fmprb_radref(x));
}

static __inline__ void
fmprb_indeterminate(fmprb_t x)
{
    fmpr_nan(fmprb_midref(x));
    fmpr_pos_inf(fmprb_radref(x));
}

static __inline__ int
fmprb_is_finite(const fmprb_t x)
{
    return fmpr_is_finite(fmprb_midref(x)) && fmpr_is_finite(fmprb_radref(x));
}

static __inline__ void
fmprb_set(fmprb_t x, const fmprb_t y)
{
    fmpr_set(fmprb_midref(x), fmprb_midref(y));
    fmpr_set(fmprb_radref(x), fmprb_radref(y));
}

void fmprb_set_round(fmprb_t z, const fmprb_t x, slong prec);

void fmprb_trim(fmprb_t y, const fmprb_t x);

static __inline__ void
fmprb_swap(fmprb_t x, fmprb_t y)
{
    fmprb_struct t = *x;
    *x = *y;
    *y = t;
}

static __inline__ void
fmprb_neg(fmprb_t x, const fmprb_t y)
{
    fmpr_neg(fmprb_midref(x), fmprb_midref(y));
    fmpr_set(fmprb_radref(x), fmprb_radref(y));
}

static __inline__ void
fmprb_neg_round(fmprb_t x, const fmprb_t y, slong prec)
{
    fmprb_set_round(x, y, prec);
    fmprb_neg(x, x);
}

static __inline__ void
fmprb_abs(fmprb_t x, const fmprb_t y)
{
    fmpr_abs(fmprb_midref(x), fmprb_midref(y));
    fmpr_set(fmprb_radref(x), fmprb_radref(y));
}

static __inline__ void
fmprb_set_fmpr(fmprb_t x, const fmpr_t y)
{
    fmpr_set(fmprb_midref(x), y);
    fmpr_zero(fmprb_radref(x));
}

static __inline__ void
fmprb_set_si(fmprb_t x, slong y)
{
    fmpr_set_si(fmprb_midref(x), y);
    fmpr_zero(fmprb_radref(x));
}

static __inline__ void
fmprb_set_ui(fmprb_t x, ulong y)
{
    fmpr_set_ui(fmprb_midref(x), y);
    fmpr_zero(fmprb_radref(x));
}

static __inline__ void
fmprb_set_fmpz(fmprb_t x, const fmpz_t y)
{
    fmpr_set_fmpz(fmprb_midref(x), y);
    fmpr_zero(fmprb_radref(x));
}

static __inline__ void
fmprb_set_fmpz_2exp(fmprb_t x, const fmpz_t y, const fmpz_t exp)
{
    fmpr_set_fmpz_2exp(fmprb_midref(x), y, exp);
    fmpr_zero(fmprb_radref(x));
}


static __inline__ void
fmprb_set_round_fmpz_2exp(fmprb_t y, const fmpz_t x, const fmpz_t exp, slong prec)
{
    slong r = fmpr_set_round_fmpz_2exp(fmprb_midref(y), x, exp, prec, FMPR_RND_DOWN);
    fmpr_set_error_result(fmprb_radref(y), fmprb_midref(y), r);
}

static __inline__ void
fmprb_set_round_fmpz(fmprb_t y, const fmpz_t x, slong prec)
{
    slong r = fmpr_set_round_fmpz(fmprb_midref(y), x, prec, FMPR_RND_DOWN);
    fmpr_set_error_result(fmprb_radref(y), fmprb_midref(y), r);
}

static __inline__ int
fmprb_is_one(const fmprb_t f)
{
    return fmpr_is_one(fmprb_midref(f)) && fmpr_is_zero(fmprb_radref(f));
}

static __inline__ void
fmprb_one(fmprb_t f)
{
    fmprb_set_ui(f, UWORD(1));
}

static __inline__ void
fmprb_adjust(fmprb_t x)
{
    if (!fmprb_is_exact(x))
    {
        /* reduce precision here */
    }
}

void fmprb_add(fmprb_t z, const fmprb_t x, const fmprb_t y, slong prec);
void fmprb_add_ui(fmprb_t z, const fmprb_t x, ulong y, slong prec);
void fmprb_add_si(fmprb_t z, const fmprb_t x, slong y, slong prec);
void fmprb_add_fmpz(fmprb_t z, const fmprb_t x, const fmpz_t y, slong prec);
void fmprb_add_fmpr(fmprb_t z, const fmprb_t x, const fmpr_t y, slong prec);

void fmprb_addmul(fmprb_t z, const fmprb_t x, const fmprb_t y, slong prec);
void fmprb_addmul_ui(fmprb_t z, const fmprb_t x, ulong y, slong prec);
void fmprb_addmul_si(fmprb_t z, const fmprb_t x, slong y, slong prec);
void fmprb_addmul_fmpz(fmprb_t z, const fmprb_t x, const fmpz_t y, slong prec);

void fmprb_div(fmprb_t z, const fmprb_t x, const fmprb_t y, slong prec);
void fmprb_div_ui(fmprb_t z, const fmprb_t x, ulong y, slong prec);
void fmprb_div_si(fmprb_t z, const fmprb_t x, slong y, slong prec);
void fmprb_div_fmpz(fmprb_t z, const fmprb_t x, const fmpz_t y, slong prec);
void fmprb_div_fmpr(fmprb_t z, const fmprb_t x, const fmpr_t y, slong prec);
void fmprb_fmpz_div_fmpz(fmprb_t y, const fmpz_t num, const fmpz_t den, slong prec);
void fmprb_ui_div(fmprb_t z, ulong x, const fmprb_t y, slong prec);

static __inline__ void
fmprb_inv(fmprb_t y, const fmprb_t x, slong prec)
{
    fmprb_ui_div(y, 1, x, prec);
}

void fmprb_mul_fmpr_naive(fmprb_t z, const fmprb_t x, const fmpr_t y, slong prec);
void fmprb_mul_main_naive(fmprb_t z, const fmprb_t x, const fmprb_t y, slong prec);
void fmprb_mul_naive(fmprb_t z, const fmprb_t x, const fmprb_t y, slong prec);

void fmprb_mul(fmprb_t z, const fmprb_t x, const fmprb_t y, slong prec);
void fmprb_mul_ui(fmprb_t z, const fmprb_t x, ulong y, slong prec);
void fmprb_mul_si(fmprb_t z, const fmprb_t x, slong y, slong prec);
void fmprb_mul_fmpz(fmprb_t z, const fmprb_t x, const fmpz_t y, slong prec);
void fmprb_mul_fmpr(fmprb_t z, const fmprb_t x, const fmpr_t y, slong prec);

void fmprb_sqrt(fmprb_t z, const fmprb_t x, slong prec);
void fmprb_sqrt_ui(fmprb_t z, ulong x, slong prec);
void fmprb_sqrt_fmpz(fmprb_t z, const fmpz_t x, slong prec);

void fmprb_rsqrt(fmprb_t z, const fmprb_t x, slong prec);
void fmprb_rsqrt_ui(fmprb_t z, ulong x, slong prec);

void fmprb_sqrtpos(fmprb_t z, const fmprb_t x, slong prec);

void fmprb_hypot(fmprb_t z, const fmprb_t x, const fmprb_t y, slong prec);


void fmprb_sub(fmprb_t z, const fmprb_t x, const fmprb_t y, slong prec);
void fmprb_sub_ui(fmprb_t z, const fmprb_t x, ulong y, slong prec);
void fmprb_sub_si(fmprb_t z, const fmprb_t x, slong y, slong prec);
void fmprb_sub_fmpz(fmprb_t z, const fmprb_t x, const fmpz_t y, slong prec);

void fmprb_submul(fmprb_t z, const fmprb_t x, const fmprb_t y, slong prec);
void fmprb_submul_ui(fmprb_t z, const fmprb_t x, ulong y, slong prec);
void fmprb_submul_si(fmprb_t z, const fmprb_t x, slong y, slong prec);
void fmprb_submul_fmpz(fmprb_t z, const fmprb_t x, const fmpz_t y, slong prec);

void fmprb_root(fmprb_t z, const fmprb_t x, ulong k, slong prec);

void fmprb_agm(fmprb_t z, const fmprb_t x, const fmprb_t y, slong prec);

static __inline__ void
fmprb_print(const fmprb_t x)
{
    fmpr_print(fmprb_midref(x));
    flint_printf(" +/- ");
    fmpr_print(fmprb_radref(x));
}

static __inline__ void
fmprb_printd(const fmprb_t x, slong digits)
{
    fmpr_printd(fmprb_midref(x), FLINT_ABS(digits));
    if (digits > 0)
    {
        flint_printf(" +/- ");
        fmpr_printd(fmprb_radref(x), 5);
    }
}

static __inline__ void
fmprb_mul_2exp_si(fmprb_t y, const fmprb_t x, slong e)
{
    fmpr_mul_2exp_si(fmprb_midref(y), fmprb_midref(x), e);
    fmpr_mul_2exp_si(fmprb_radref(y), fmprb_radref(x), e);
}

static __inline__ void
fmprb_mul_2exp_fmpz(fmprb_t y, const fmprb_t x, const fmpz_t e)
{
    fmpr_mul_2exp_fmpz(fmprb_midref(y), fmprb_midref(x), e);
    fmpr_mul_2exp_fmpz(fmprb_radref(y), fmprb_radref(x), e);
}

static __inline__ void
fmprb_set_fmpq(fmprb_t y, const fmpq_t x, slong prec)
{
    fmprb_fmpz_div_fmpz(y, fmpq_numref(x), fmpq_denref(x), prec);
}

int fmprb_contains_fmpr(const fmprb_t x, const fmpr_t y);
int fmprb_contains_fmpq(const fmprb_t x, const fmpq_t y);
int fmprb_contains_fmpz(const fmprb_t x, const fmpz_t y);
int fmprb_contains_si(const fmprb_t x, slong y);
int fmprb_contains_mpfr(const fmprb_t x, const mpfr_t y);
int fmprb_contains_zero(const fmprb_t x);

int fmprb_overlaps(const fmprb_t x, const fmprb_t y);

int fmprb_contains(const fmprb_t x, const fmprb_t y);

static __inline__ int
fmprb_is_int(const fmprb_t x)
{
    return fmpr_is_zero(fmprb_radref(x)) &&
           fmpr_is_int(fmprb_midref(x));
}

static __inline__ int
fmprb_is_nonzero(const fmprb_t x)
{
    return !fmprb_contains_zero(x);
}

static __inline__ int
fmprb_is_positive(const fmprb_t x)
{
    return (fmpr_sgn(fmprb_midref(x)) > 0) &&
        (fmpr_cmpabs(fmprb_radref(x), fmprb_midref(x)) < 0) &&
         !fmpr_is_nan(fmprb_midref(x));
}

static __inline__ int
fmprb_is_nonnegative(const fmprb_t x)
{
    return (fmpr_sgn(fmprb_midref(x)) >= 0) &&
        (fmpr_cmpabs(fmprb_radref(x), fmprb_midref(x)) <= 0) &&
         !fmpr_is_nan(fmprb_midref(x));
}

static __inline__ int
fmprb_is_negative(const fmprb_t x)
{
    return (fmpr_sgn(fmprb_midref(x)) < 0) &&
        (fmpr_cmpabs(fmprb_radref(x), fmprb_midref(x)) < 0) &&
         !fmpr_is_nan(fmprb_midref(x));
}

static __inline__ int
fmprb_is_nonpositive(const fmprb_t x)
{
    return (fmpr_sgn(fmprb_midref(x)) <= 0) &&
        (fmpr_cmpabs(fmprb_radref(x), fmprb_midref(x)) <= 0) &&
         !fmpr_is_nan(fmprb_midref(x));
}

static __inline__ int
fmprb_contains_negative(const fmprb_t x)
{
    return (fmpr_sgn(fmprb_midref(x)) < 0) ||
        (fmpr_cmpabs(fmprb_radref(x), fmprb_midref(x)) > 0)
        || fmpr_is_nan(fmprb_midref(x));
}

static __inline__ int
fmprb_contains_nonpositive(const fmprb_t x)
{
    return (fmpr_sgn(fmprb_midref(x)) <= 0) ||
        (fmpr_cmpabs(fmprb_radref(x), fmprb_midref(x)) >= 0)
        || fmpr_is_nan(fmprb_midref(x));
}

static __inline__ int
fmprb_contains_positive(const fmprb_t x)
{
    return (fmpr_sgn(fmprb_midref(x)) > 0) ||
        (fmpr_cmpabs(fmprb_radref(x), fmprb_midref(x)) > 0)
        || fmpr_is_nan(fmprb_midref(x));
}

static __inline__ int
fmprb_contains_nonnegative(const fmprb_t x)
{
    return (fmpr_sgn(fmprb_midref(x)) >= 0) ||
        (fmpr_cmpabs(fmprb_radref(x), fmprb_midref(x)) >= 0)
        || fmpr_is_nan(fmprb_midref(x));
}

static __inline__ void
fmprb_get_abs_ubound_fmpr(fmpr_t u, const fmprb_t x, slong prec)
{
    if (fmpr_sgn(fmprb_midref(x)) < 0)
        fmpr_sub(u, fmprb_midref(x), fmprb_radref(x), prec, FMPR_RND_UP);
    else
        fmpr_add(u, fmprb_midref(x), fmprb_radref(x), prec, FMPR_RND_UP);

    fmpr_abs(u, u);
}

static __inline__ void
fmprb_get_abs_lbound_fmpr(fmpr_t u, const fmprb_t x, slong prec)
{
    if (fmpr_sgn(fmprb_midref(x)) > 0)
    {
        fmpr_sub(u, fmprb_midref(x), fmprb_radref(x), prec, FMPR_RND_DOWN);
    }
    else
    {
        fmpr_add(u, fmprb_midref(x), fmprb_radref(x), prec, FMPR_RND_DOWN);
        fmpr_neg(u, u);
    }

    if (fmpr_sgn(u) < 0)
        fmpr_zero(u);
}

void fmprb_get_interval_fmpz_2exp(fmpz_t a, fmpz_t b, fmpz_t exp, const fmprb_t x);

int fmprb_get_unique_fmpz(fmpz_t z, const fmprb_t x);

void fmprb_set_interval_fmpr(fmprb_t x, const fmpr_t a, const fmpr_t b, slong prec);

void fmprb_union(fmprb_t z, const fmprb_t x, const fmprb_t y, slong prec);

static __inline__ slong
fmprb_rel_error_bits(const fmprb_t x)
{
    fmpz_t midmag, radmag;
    slong result;

    if (fmpr_is_zero(fmprb_radref(x)))
        return -FMPR_PREC_EXACT;
    if (fmpr_is_special(fmprb_midref(x)) || fmpr_is_special(fmprb_radref(x)))
        return FMPR_PREC_EXACT;

    fmpz_init(midmag);
    fmpz_init(radmag);

    fmpr_abs_bound_lt_2exp_fmpz(midmag, fmprb_midref(x));
    fmpr_abs_bound_lt_2exp_fmpz(radmag, fmprb_radref(x));
    fmpz_add_ui(radmag, radmag, 1);

    result = _fmpz_sub_small(radmag, midmag);

    fmpz_clear(midmag);
    fmpz_clear(radmag);

    return result;
}

static __inline__ slong
fmprb_rel_accuracy_bits(const fmprb_t x)
{
    return -fmprb_rel_error_bits(x);
}

static __inline__ slong
fmprb_bits(const fmprb_t x)
{
    return fmpr_bits(fmprb_midref(x));
}

void fmprb_add_error_fmpr(fmprb_t x, const fmpr_t err);
void fmprb_add_error_2exp_si(fmprb_t x, slong err);
void fmprb_add_error_2exp_fmpz(fmprb_t x, const fmpz_t err);
void fmprb_add_error(fmprb_t x, const fmprb_t error);

void fmprb_randtest(fmprb_t x, flint_rand_t state, slong prec, slong mag_bits);
void fmprb_randtest_exact(fmprb_t x, flint_rand_t state, slong prec, slong mag_bits);
void fmprb_randtest_wide(fmprb_t x, flint_rand_t state, slong prec, slong mag_bits);
void fmprb_randtest_precise(fmprb_t x, flint_rand_t state, slong prec, slong mag_bits);
void fmprb_randtest_special(fmprb_t x, flint_rand_t state, slong prec, slong mag_bits);

void fmprb_get_rand_fmpq(fmpq_t q, flint_rand_t state, const fmprb_t x, slong bits);

#define DEF_CACHED_CONSTANT(name, comp_func) \
    TLS_PREFIX slong name ## _cached_prec = 0; \
    TLS_PREFIX fmprb_t name ## _cached_value; \
    void name ## _cleanup(void) \
    { \
        fmprb_clear(name ## _cached_value); \
        name ## _cached_prec = 0; \
    } \
    void name(fmprb_t x, slong prec) \
    { \
        if (name ## _cached_prec < prec) \
        { \
            if (name ## _cached_prec == 0) \
            { \
                fmprb_init(name ## _cached_value); \
                flint_register_cleanup_function(name ## _cleanup); \
            } \
            comp_func(name ## _cached_value, prec); \
            name ## _cached_prec = prec; \
        } \
        fmprb_set_round(x, name ## _cached_value, prec); \
    }

/* vector functions */

static __inline__ void
_fmprb_vec_zero(fmprb_ptr A, slong n)
{
    slong i;
    for (i = 0; i < n; i++)
        fmprb_zero(A + i);
}

static __inline__ int
_fmprb_vec_is_zero(fmprb_srcptr vec, slong len)
{
    slong i;
    for (i = 0; i < len; i++)
        if (!fmprb_is_zero(vec + i))
            return 0;
    return 1;
}

static __inline__ void
_fmprb_vec_set(fmprb_ptr res, fmprb_srcptr vec, slong len)
{
    slong i;
    for (i = 0; i < len; i++)
        fmprb_set(res + i, vec + i);
}

static __inline__ void
_fmprb_vec_set_round(fmprb_ptr res, fmprb_srcptr vec, slong len, slong prec)
{
    slong i;
    for (i = 0; i < len; i++)
        fmprb_set_round(res + i, vec + i, prec);
}

static __inline__ void
_fmprb_vec_swap(fmprb_ptr res, fmprb_ptr vec, slong len)
{
    slong i;
    for (i = 0; i < len; i++)
        fmprb_swap(res + i, vec + i);
}

static __inline__ void
_fmprb_vec_neg(fmprb_ptr B, fmprb_srcptr A, slong n)
{
    slong i;
    for (i = 0; i < n; i++)
        fmprb_neg(B + i, A + i);
}

static __inline__ void
_fmprb_vec_sub(fmprb_ptr C, fmprb_srcptr A,
    fmprb_srcptr B, slong n, slong prec)
{
    slong i;
    for (i = 0; i < n; i++)
        fmprb_sub(C + i, A + i, B + i, prec);
}

static __inline__ void
_fmprb_vec_add(fmprb_ptr C, fmprb_srcptr A,
    fmprb_srcptr B, slong n, slong prec)
{
    slong i;
    for (i = 0; i < n; i++)
        fmprb_add(C + i, A + i, B + i, prec);
}

static __inline__ void
_fmprb_vec_scalar_mul(fmprb_ptr res, fmprb_srcptr vec,
    slong len, const fmprb_t c, slong prec)
{
    slong i;
    for (i = 0; i < len; i++)
        fmprb_mul(res + i, vec + i, c, prec);
}

static __inline__ void
_fmprb_vec_scalar_div(fmprb_ptr res, fmprb_srcptr vec,
    slong len, const fmprb_t c, slong prec)
{
    slong i;
    for (i = 0; i < len; i++)
        fmprb_div(res + i, vec + i, c, prec);
}

static __inline__ void
_fmprb_vec_scalar_mul_fmpz(fmprb_ptr res, fmprb_srcptr vec,
    slong len, const fmpz_t c, slong prec)
{
    slong i;
    fmpr_t t;
    fmpr_init(t);
    fmpr_set_fmpz(t, c);
    for (i = 0; i < len; i++)
        fmprb_mul_fmpr(res + i, vec + i, t, prec);
    fmpr_clear(t);
}

static __inline__ void
_fmprb_vec_scalar_mul_2exp_si(fmprb_ptr res, fmprb_srcptr src, slong len, slong c)
{
    slong i;
    for (i = 0; i < len; i++)
        fmprb_mul_2exp_si(res + i, src + i, c);
}

static __inline__ void
_fmprb_vec_scalar_addmul(fmprb_ptr res, fmprb_srcptr vec,
    slong len, const fmprb_t c, slong prec)
{
    slong i;
    for (i = 0; i < len; i++)
        fmprb_addmul(res + i, vec + i, c, prec);
}

static __inline__ void
_fmprb_vec_get_abs_ubound_fmpr(fmpr_t bound, fmprb_srcptr vec,
        slong len, slong prec)
{
    fmpr_t t;
    slong i;

    if (len < 1)
    {
        fmpr_zero(bound);
    }
    else
    {
        fmprb_get_abs_ubound_fmpr(bound, vec, prec);
        fmpr_init(t);
        for (i = 1; i < len; i++)
        {
            fmprb_get_abs_ubound_fmpr(t, vec + i, prec);
            if (fmpr_cmp(t, bound) > 0)
                fmpr_set(bound, t);
        }
        fmpr_clear(t);
    }
}

static __inline__ slong
_fmprb_vec_bits(fmprb_srcptr x, slong len)
{
    slong i, b, c;

    b = 0;
    for (i = 0; i < len; i++)
    {
        c = fmprb_bits(x + i);
        b = FLINT_MAX(b, c);
    }

    return b;
}

static __inline__ void
_fmprb_vec_set_powers(fmprb_ptr xs, const fmprb_t x, slong len, slong prec)
{
    slong i;

    for (i = 0; i < len; i++)
    {
        if (i == 0)
            fmprb_one(xs + i);
        else if (i == 1)
            fmprb_set_round(xs + i, x, prec);
        else if (i % 2 == 0)
            fmprb_mul(xs + i, xs + i / 2, xs + i / 2, prec);
        else
            fmprb_mul(xs + i, xs + i - 1, x, prec);
    }
}

static __inline__ void
_fmprb_vec_add_error_fmpr_vec(fmprb_ptr res, fmpr_srcptr err, slong len)
{
    slong i;
    for (i = 0; i < len; i++)
        fmprb_add_error_fmpr(res + i, err + i);
}

static __inline__ void
_fmprb_vec_indeterminate(fmprb_ptr vec, slong len)
{
    slong i;
    for (i = 0; i < len; i++)
    {
        fmpr_nan(fmprb_midref(vec + i));
        fmpr_pos_inf(fmprb_radref(vec + i));
    }
}

static __inline__ void
_fmprb_vec_trim(fmprb_ptr res, fmprb_srcptr vec, slong len)
{
    slong i;
    for (i = 0; i < len; i++)
        fmprb_trim(res + i, vec + i);
}

#ifdef __cplusplus
}
#endif

#endif