-
Notifications
You must be signed in to change notification settings - Fork 1
/
FACT_mpc.h
99 lines (82 loc) · 2.46 KB
/
FACT_mpc.h
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
/* This file is part of FACT.
*
* FACT 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 3 of the License, or
* (at your option) any later version.
*
* FACT 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 FACT. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FACT_MPC_H_
#define FACT_MPC_H_
/* Because mpc is designed as a small extension upon GMP (one that will
* never be developed as its own independent project), we use the
* GMP/MPC calling conventions.
*/
#include "FACT.h"
#include <gmp.h>
typedef struct {
struct {
unsigned char fp : 1; /* Floating point. */
unsigned char pad : 7;
};
union {
mpz_t intv; /* Integer value. */
mpf_t fltv; /* Float value. */
};
} __mpc_struct;
typedef __mpc_struct mpc_t[1];
void mpc_init (mpc_t);
void mpc_clear (mpc_t);
void mpc_set (mpc_t, mpc_t);
void mpc_set_ui (mpc_t, unsigned long);
void mpc_set_si (mpc_t, signed long);
void mpc_set_str (mpc_t, char *, int);
/* Arithmetic functions. */
void mpc_add (mpc_t, mpc_t, mpc_t);
void mpc_sub (mpc_t, mpc_t, mpc_t);
void mpc_mul (mpc_t, mpc_t, mpc_t);
void mpc_div (mpc_t, mpc_t, mpc_t);
void mpc_mod (mpc_t, mpc_t, mpc_t);
/* Bitwise functions. */
void mpc_and (mpc_t, mpc_t, mpc_t);
void mpc_ior (mpc_t, mpc_t, mpc_t);
void mpc_xor (mpc_t, mpc_t, mpc_t);
void mpc_neg (mpc_t, mpc_t);
int mpc_cmp (mpc_t, mpc_t);
int mpc_cmp_ui (mpc_t, unsigned long int);
int mpc_cmp_si (mpc_t, signed long int);
unsigned long int mpc_get_ui (mpc_t);
signed long int mpc_get_si (mpc_t);
char *mpc_get_str (mpc_t);
static inline void mpc_add_ui (mpc_t rop, mpc_t op1, unsigned long int op2)
{
mpc_set (rop, op1);
if (rop->fp)
mpf_add_ui (rop->fltv, rop->fltv, op2);
else
mpz_add_ui (rop->intv, rop->intv, op2);
}
static inline void mpc_sub_ui (mpc_t rop, mpc_t op1, unsigned long int op2)
{
mpc_set (rop, op1);
if (rop->fp)
mpf_sub_ui (rop->fltv, rop->fltv, op2);
else
mpz_sub_ui (rop->intv, rop->intv, op2);
}
static inline bool mpc_is_float (mpc_t n)
{
return n->fp;
}
static inline bool mpc_is_int (mpc_t n)
{
return !n->fp;
}
#endif /* FACT_MPC_H_ */