Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:15:06

0001 /*
0002     Copyright (C) 2022 Fredrik Johansson
0003 
0004     This file is part of FLINT.
0005 
0006     FLINT is free software: you can redistribute it and/or modify it under
0007     the terms of the GNU Lesser General Public License (LGPL) as published
0008     by the Free Software Foundation; either version 3 of the License, or
0009     (at your option) any later version.  See <https://www.gnu.org/licenses/>.
0010 */
0011 
0012 #ifndef ACF_H
0013 #define ACF_H
0014 
0015 #ifdef ACF_INLINES_C
0016 #define ACF_INLINE
0017 #else
0018 #define ACF_INLINE static inline
0019 #endif
0020 
0021 #include "arf.h"
0022 #include "acf_types.h"
0023 
0024 #ifdef __cplusplus
0025 extern "C" {
0026 #endif
0027 
0028 #define acf_realref(x) (&(x)->real)
0029 #define acf_imagref(x) (&(x)->imag)
0030 
0031 ACF_INLINE void
0032 acf_init(acf_t x)
0033 {
0034     arf_init(acf_realref(x));
0035     arf_init(acf_imagref(x));
0036 }
0037 
0038 ACF_INLINE void
0039 acf_clear(acf_t x)
0040 {
0041     arf_clear(acf_realref(x));
0042     arf_clear(acf_imagref(x));
0043 }
0044 
0045 ACF_INLINE acf_ptr _acf_vec_init(slong n) { return (acf_ptr) _arf_vec_init(2 * n); }
0046 ACF_INLINE void _acf_vec_clear(acf_ptr v, slong n) { _arf_vec_clear((arf_ptr) v, 2 * n); }
0047 
0048 ACF_INLINE arf_ptr acf_real_ptr(acf_t z) { return acf_realref(z); }
0049 ACF_INLINE arf_ptr acf_imag_ptr(acf_t z) { return acf_imagref(z); }
0050 
0051 ACF_INLINE void
0052 acf_set(acf_t z, const acf_t x)
0053 {
0054     arf_set(acf_realref(z), acf_realref(x));
0055     arf_set(acf_imagref(z), acf_imagref(x));
0056 }
0057 
0058 ACF_INLINE void
0059 acf_swap(acf_t z, acf_t x)
0060 {
0061     FLINT_SWAP(acf_struct, *z, *x);
0062 }
0063 
0064 ACF_INLINE int
0065 acf_equal(const acf_t x, const acf_t y)
0066 {
0067     return arf_equal(acf_realref(x), acf_realref(y)) &&
0068            arf_equal(acf_imagref(x), acf_imagref(y));
0069 }
0070 
0071 /* todo: document */
0072 ACF_INLINE void
0073 acf_printd(const acf_t x, slong n)
0074 {
0075     arf_printd(acf_realref(x), n);
0076     flint_printf(" + ");
0077     arf_printd(acf_imagref(x), n);
0078     flint_printf("*I");
0079 }
0080 
0081 /* todo: document */
0082 ACF_INLINE slong
0083 acf_bits(const acf_t x)
0084 {
0085     slong b1, b2;
0086     b1 = arf_bits(acf_realref(x));
0087     b2 = arf_bits(acf_imagref(x));
0088     return FLINT_MAX(b1, b2);
0089 }
0090 
0091 ACF_INLINE slong
0092 acf_allocated_bytes(const acf_t x)
0093 {
0094     return arf_allocated_bytes(acf_realref(x)) + arf_allocated_bytes(acf_imagref(x));
0095 }
0096 
0097 /* todo: document */
0098 ACF_INLINE void acf_randtest(acf_t x, flint_rand_t state, slong bits, slong mag_bits)
0099 {
0100     arf_randtest(acf_realref(x), state, bits, mag_bits);
0101     arf_randtest(acf_imagref(x), state, bits, mag_bits);
0102 }
0103 
0104 /* todo: document */
0105 ACF_INLINE void
0106 acf_get_mag(mag_t res, const acf_t x)
0107 {
0108     mag_t t, u;
0109     mag_init(t);
0110     mag_init(u);
0111     arf_get_mag(t, acf_realref(x));
0112     arf_get_mag(u, acf_imagref(x));
0113     mag_hypot(res, t, u);
0114     mag_clear(t);
0115     mag_clear(u);
0116 }
0117 
0118 /* todo: document */
0119 ACF_INLINE void
0120 acf_neg(acf_t z, const acf_t x)
0121 {
0122     arf_neg(acf_realref(z), acf_realref(x));
0123     arf_neg(acf_imagref(z), acf_imagref(x));
0124 }
0125 
0126 /* todo: document */
0127 ACF_INLINE int
0128 acf_set_round(acf_t res, const acf_t x, slong prec, arf_rnd_t rnd)
0129 {
0130     return arf_set_round(acf_realref(res), acf_realref(x), prec, rnd) |
0131            (arf_set_round(acf_imagref(res), acf_imagref(x), prec, rnd) << 1);
0132 }
0133 
0134 /* todo: document */
0135 ACF_INLINE int
0136 acf_neg_round(acf_t res, const acf_t x, slong prec, arf_rnd_t rnd)
0137 {
0138     return arf_neg_round(acf_realref(res), acf_realref(x), prec, rnd) |
0139            (arf_neg_round(acf_imagref(res), acf_imagref(x), prec, rnd) << 1);
0140 }
0141 
0142 ACF_INLINE int
0143 acf_add(acf_t res, const acf_t x, const acf_t y, slong prec, arf_rnd_t rnd)
0144 {
0145     return arf_add(acf_realref(res), acf_realref(x), acf_realref(y), prec, rnd) |
0146            (arf_add(acf_imagref(res), acf_imagref(x), acf_imagref(y), prec, rnd) << 1);
0147 }
0148 
0149 ACF_INLINE int
0150 acf_sub(acf_t res, const acf_t x, const acf_t y, slong prec, arf_rnd_t rnd)
0151 {
0152     return arf_sub(acf_realref(res), acf_realref(x), acf_realref(y), prec, rnd) |
0153            (arf_sub(acf_imagref(res), acf_imagref(x), acf_imagref(y), prec, rnd) << 1);
0154 }
0155 
0156 ACF_INLINE int
0157 acf_mul(acf_t res, const acf_t x, const acf_t y, slong prec, arf_rnd_t rnd)
0158 {
0159     if (x == y)
0160         return arf_complex_sqr(acf_realref(res), acf_imagref(res),
0161             acf_realref(x), acf_imagref(x),
0162             prec, rnd);
0163     else
0164         return arf_complex_mul(acf_realref(res), acf_imagref(res),
0165             acf_realref(x), acf_imagref(x),
0166             acf_realref(y), acf_imagref(y),
0167             prec, rnd);
0168 }
0169 
0170 void acf_approx_inv(acf_t res, const acf_t x, slong prec, arf_rnd_t rnd);
0171 void acf_approx_div(acf_t res, const acf_t x, const acf_t y, slong prec, arf_rnd_t rnd);
0172 void acf_approx_sqrt(acf_t res, const acf_t x, slong prec, arf_rnd_t rnd);
0173 
0174 void acf_approx_dot(acf_t res, const acf_t initial, int subtract, acf_srcptr x, slong xstep, acf_srcptr y, slong ystep, slong len, slong prec, arf_rnd_t rnd);
0175 
0176 #ifdef __cplusplus
0177 }
0178 #endif
0179 
0180 #endif