blob: 8eabcec87c02db796b5d364b16844d2366ba63ab [file] [log] [blame]
Austin Schuhdace2a62020-08-18 10:56:48 -07001/* mini-mpq, a minimalistic implementation of a GNU GMP subset.
2
3Copyright 2018, 2019 Free Software Foundation, Inc.
4
5This file is part of the GNU MP Library.
6
7The GNU MP Library is free software; you can redistribute it and/or modify
8it under the terms of either:
9
10 * the GNU Lesser General Public License as published by the Free
11 Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
13
14or
15
16 * the GNU General Public License as published by the Free Software
17 Foundation; either version 2 of the License, or (at your option) any
18 later version.
19
20or both in parallel, as here.
21
22The GNU MP Library is distributed in the hope that it will be useful, but
23WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25for more details.
26
27You should have received copies of the GNU General Public License and the
28GNU Lesser General Public License along with the GNU MP Library. If not,
29see https://www.gnu.org/licenses/. */
30
31/* Header */
32
33#ifndef __MINI_MPQ_H__
34#define __MINI_MPQ_H__
35
36#include "mini-gmp.h"
37
38#if defined (__cplusplus)
39extern "C" {
40#endif
41
42typedef struct
43{
44 __mpz_struct _mp_num;
45 __mpz_struct _mp_den;
46} __mpq_struct;
47
48typedef __mpq_struct mpq_t[1];
49
50typedef const __mpq_struct *mpq_srcptr;
51typedef __mpq_struct *mpq_ptr;
52
53#define mpq_numref(Q) (&((Q)->_mp_num))
54#define mpq_denref(Q) (&((Q)->_mp_den))
55
56void mpq_abs (mpq_t, const mpq_t);
57void mpq_add (mpq_t, const mpq_t, const mpq_t);
58void mpq_canonicalize (mpq_t);
59void mpq_clear (mpq_t);
60int mpq_cmp (const mpq_t, const mpq_t);
61int mpq_cmp_si (const mpq_t, signed long, unsigned long);
62int mpq_cmp_ui (const mpq_t, unsigned long, unsigned long);
63int mpq_cmp_z (const mpq_t, const mpz_t);
64void mpq_div (mpq_t, const mpq_t, const mpq_t);
65void mpq_div_2exp (mpq_t, const mpq_t, mp_bitcnt_t);
66int mpq_equal (const mpq_t, const mpq_t);
67double mpq_get_d (const mpq_t);
68void mpq_get_den (mpz_t, const mpq_t);
69void mpq_get_num (mpz_t, const mpq_t);
70char * mpq_get_str (char *, int, const mpq_t q);
71void mpq_init (mpq_t);
72void mpq_inv (mpq_t, const mpq_t);
73void mpq_mul (mpq_t, const mpq_t, const mpq_t);
74void mpq_mul_2exp (mpq_t, const mpq_t, mp_bitcnt_t);
75void mpq_neg (mpq_t, const mpq_t);
76void mpq_set (mpq_t, const mpq_t);
77void mpq_set_d (mpq_t, double);
78void mpq_set_den (mpq_t, const mpz_t);
79void mpq_set_num (mpq_t, const mpz_t);
80void mpq_set_si (mpq_t, signed long, unsigned long);
81int mpq_set_str (mpq_t, const char *, int);
82void mpq_set_ui (mpq_t, unsigned long, unsigned long);
83void mpq_set_z (mpq_t, const mpz_t);
84int mpq_sgn (const mpq_t);
85void mpq_sub (mpq_t, const mpq_t, const mpq_t);
86void mpq_swap (mpq_t, mpq_t);
87
88/* This long list taken from gmp.h. */
89/* For reference, "defined(EOF)" cannot be used here. In g++ 2.95.4,
90 <iostream> defines EOF but not FILE. */
91#if defined (FILE) \
92 || defined (H_STDIO) \
93 || defined (_H_STDIO) /* AIX */ \
94 || defined (_STDIO_H) /* glibc, Sun, SCO */ \
95 || defined (_STDIO_H_) /* BSD, OSF */ \
96 || defined (__STDIO_H) /* Borland */ \
97 || defined (__STDIO_H__) /* IRIX */ \
98 || defined (_STDIO_INCLUDED) /* HPUX */ \
99 || defined (__dj_include_stdio_h_) /* DJGPP */ \
100 || defined (_FILE_DEFINED) /* Microsoft */ \
101 || defined (__STDIO__) /* Apple MPW MrC */ \
102 || defined (_MSL_STDIO_H) /* Metrowerks */ \
103 || defined (_STDIO_H_INCLUDED) /* QNX4 */ \
104 || defined (_ISO_STDIO_ISO_H) /* Sun C++ */ \
105 || defined (__STDIO_LOADED) /* VMS */
106size_t mpq_out_str (FILE *, int, const mpq_t);
107#endif
108
109void mpz_set_q (mpz_t, const mpq_t);
110
111#if defined (__cplusplus)
112}
113#endif
114#endif /* __MINI_MPQ_H__ */