aboutsummaryrefslogtreecommitdiffstats
path: root/moon-abe/pbc-0.5.14/ecc/mpc.h
blob: 3588586b08349c77bc04e39fab4010439d554dfa (plain)
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
// Complex floats.
// Called mpc_t, these complex numbers are built on GMP's mpf_t type.

// Requires:
// * stdio.h
// * gmp.h

#ifndef __PBC_MPC_H__
#define __PBC_MPC_H__

#pragma GCC visibility push(hidden)

struct mpc_s {
  mpf_t a;
  mpf_t b;
};
typedef struct mpc_s mpc_t[1];
typedef struct mpc_s *mpc_ptr;

static inline void mpc_init(mpc_ptr c) {
  mpf_init(c->a);
  mpf_init(c->b);
}

static inline void mpc_clear(mpc_ptr c) {
  mpf_clear(c->a);
  mpf_clear(c->b);
}

static inline mpf_ptr mpc_re(mpc_ptr c) {
  return c->a;
}

static inline mpf_ptr mpc_im(mpc_ptr c) {
  return c->b;
}

static inline void mpc_add(mpc_ptr res, mpc_ptr z0, mpc_ptr z1) {
  mpf_add(res->a, z0->a, z1->a);
  mpf_add(res->b, z0->b, z1->b);
}

static inline void mpc_sub(mpc_ptr res, mpc_ptr z0, mpc_ptr z1) {
  mpf_sub(res->a, z0->a, z1->a);
  mpf_sub(res->b, z0->b, z1->b);
}

static inline void mpc_neg(mpc_ptr res, mpc_ptr z) {
  mpf_neg(res->a, z->a);
  mpf_neg(res->b, z->b);
}

static inline void mpc_conj(mpc_ptr res, mpc_ptr z) {
  mpf_set(res->a, z->a);
  mpf_neg(res->b, z->b);
}

static inline void mpc_set(mpc_t res, mpc_t z) {
  mpf_set(res->a, z->a);
  mpf_set(res->b, z->b);
}

static inline void mpc_set_ui(mpc_t res, unsigned long int n) {
  mpf_set_ui(res->a, n);
  mpf_set_ui(res->b, 0);
}

static inline void mpc_add_ui(mpc_t res, mpc_t z, unsigned long int n) {
  mpf_add_ui(res->a, z->a, n);
}

static inline void mpc_mul_ui(mpc_t res, mpc_t z, unsigned long int n) {
  mpf_mul_ui(res->a, z->a, n);
  mpf_mul_ui(res->b, z->b, n);
}

static inline void mpc_mul_mpf(mpc_t res, mpc_t z, mpf_t f) {
  mpf_mul(res->a, z->a, f);
  mpf_mul(res->b, z->b, f);
}

void mpc_mul(mpc_t res, mpc_t z0, mpc_t z1);
void mpc_mul_2exp(mpc_t res, mpc_t z, unsigned long int);
void mpc_div(mpc_t res, mpc_t z0, mpc_t z1);
void mpc_muli(mpc_t res, mpc_t z);
void mpc_sqr(mpc_t res, mpc_t z);
void mpc_inv(mpc_t res, mpc_t z);
size_t mpc_out_str(FILE *stream, int base, size_t n_digits, mpc_t op);
void mpc_pow_ui(mpc_t res, mpc_t z, unsigned int n);

#pragma GCC visibility pop

#endif //__PBC_MPC_H__