blob: 1ab69b0ef30f70102ecb3d9d8571f4ceb9f72429 [file] [log] [blame]
Austin Schuh405fa6c2015-09-06 18:13:55 -07001/* cddmp.h (cddlib arithmetic operations using gmp)
2 written by Komei Fukuda, fukuda@math.ethz.ch
3 Version 0.94h, April 30, 2015
4*/
5
6/* This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#ifndef __CDDMP_H
22#define __CDDMP_H
23#endif /* __CDDMP_H */
24
25/**********************************/
26/* MACROS */
27/* dependent on mp implementation */
28/**********************************/
29
30#if defined GMPRATIONAL
31 #include "gmp.h"
32 #define dd_ARITHMETIC "GMP rational"
33 #define dd_init(a) mpq_init(a)
34 #define dd_clear(a) mpq_clear(a)
35 #define dd_set(a, b) mpq_set(a,b)
36 #define dd_set_si(a, b) ddd_mpq_set_si(a,b) /* defined in cddgmp.c */
37 #define dd_set_si2(a, b, c) mpq_set_si(a,b,c) /* gmp 3.1 or higher */
38 #define dd_add(a, b, c) mpq_add(a,b,c)
39 #define dd_sub(a, b, c) mpq_sub(a,b,c)
40 #define dd_mul(a, b, c) mpq_mul(a,b,c)
41 #define dd_div(a, b, c) mpq_div(a,b,c)
42 #define dd_neg(a, b) mpq_neg(a,b)
43 #define dd_inv(a, b) mpq_inv(a,b)
44 #define dd_cmp(a, b) mpq_cmp(a,b)
45 /* returns pos if a>b, 0 if a=b, negative if a<b */
46 #define dd_sgn(a) mpq_sgn(a)
47 /* returns nonzero if equal. much faster than mpq_cmp. */
48 #define dd_get_d(a) mpq_get_d(a)
49#elif defined GMPFLOAT
50 #include "gmp.h"
51 #define dd_ARITHMETIC "GMP float"
52 #define dd_init(a) mpf_init(a)
53 #define dd_clear(a) mpf_clear(a)
54 #define dd_set(a, b) mpf_set(a,b)
55 #define dd_set_d(a, b) mpf_set_d(a,b)
56 #define dd_set_si(a, b) mpf_set_si(a,b)
57 #define dd_set_si2(a, b, c) mpf_set_si(a,b,c) /* gmp 3.1 or higher */
58 #define dd_add(a, b, c) mpf_add(a,b,c)
59 #define dd_sub(a, b, c) mpf_sub(a,b,c)
60 #define dd_mul(a, b, c) mpf_mul(a,b,c)
61 #define dd_div(a, b, c) mpf_div(a,b,c)
62 #define dd_neg(a, b) mpf_neg(a,b)
63 #define dd_inv(a, b) mpf_inv(a,b)
64 #define dd_cmp(a, b) mpf_cmp(a,b)
65 /* returns pos if a>b, 0 if a=b, negative if a<b */
66 #define dd_sgn(a) mpf_sgn(a)
67 #define dd_get_d(a) mpf_get_d(a)
68#else /* built-in C double */
69 #define dd_ARITHMETIC "C double"
70 #define dd_CDOUBLE
71 #define dd_init(a) ddd_init(a)
72 #define dd_clear(a) ddd_clear(a)
73 #define dd_set(a, b) ddd_set(a,b)
74 #define dd_set_si(a, b) ddd_set_si(a,b)
75 #define dd_set_si2(a, b, c) ddd_set_si2(a,b,c)
76 #define dd_set_d(a, b) ddd_set_d(a,b)
77 #define dd_add(a, b, c) ddd_add(a,b,c)
78 #define dd_sub(a, b, c) ddd_sub(a,b,c)
79 #define dd_mul(a, b, c) ddd_mul(a,b,c)
80 #define dd_div(a, b, c) ddd_div(a,b,c)
81 #define dd_neg(a, b) ddd_neg(a,b)
82 #define dd_inv(a, b) ddd_inv(a,b)
83 #define dd_cmp(a, b) ddd_cmp(a,b)
84 /* returns pos if a>b, 0 if a=b, negative if a<b */
85 #define dd_sgn(a) ddd_sgn(a)
86 #define dd_get_d(a) ddd_get_d(a)
87#endif
88
89
90#if defined GMPRATIONAL
91 typedef mpq_t mytype;
92#elif defined GMPFLOAT
93 typedef mpf_t mytype;
94#else /* built-in C double */
95 typedef double mytype[1];
96#endif
97
98#if defined(__cplusplus)
99extern "C" {
100#endif
101
102void ddd_mpq_set_si(mytype,signed long);
103void ddd_init(mytype);
104void ddd_clear(mytype);
105void ddd_set(mytype,mytype);
106void ddd_set_d(mytype,double);
107void ddd_set_si(mytype,signed long);
108void ddd_set_si2(mytype,signed long, unsigned long);
109void ddd_add(mytype,mytype,mytype);
110void ddd_sub(mytype,mytype,mytype);
111void ddd_mul(mytype,mytype,mytype);
112void ddd_div(mytype,mytype,mytype);
113void ddd_neg(mytype,mytype);
114void ddd_inv(mytype,mytype);
115int ddd_cmp(mytype,mytype);
116int ddd_sgn(mytype);
117double ddd_get_d(mytype);
118void ddd_mpq_set_si(mytype,signed long);
119
120void dd_set_global_constants(void);
121void dd_free_global_constants(void); /* 094d */
122
123#if defined(__cplusplus)
124}
125#endif
126
127/* end of cddmp.h */