Austin Schuh | dace2a6 | 2020-08-18 10:56:48 -0700 | [diff] [blame] | 1 | /* mini-mpq, a minimalistic implementation of a GNU GMP subset. |
| 2 | |
| 3 | Copyright 2018, 2019 Free Software Foundation, Inc. |
| 4 | |
| 5 | This file is part of the GNU MP Library. |
| 6 | |
| 7 | The GNU MP Library is free software; you can redistribute it and/or modify |
| 8 | it 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 | |
| 14 | or |
| 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 | |
| 20 | or both in parallel, as here. |
| 21 | |
| 22 | The GNU MP Library is distributed in the hope that it will be useful, but |
| 23 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 24 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 25 | for more details. |
| 26 | |
| 27 | You should have received copies of the GNU General Public License and the |
| 28 | GNU Lesser General Public License along with the GNU MP Library. If not, |
| 29 | see 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) |
| 39 | extern "C" { |
| 40 | #endif |
| 41 | |
| 42 | typedef struct |
| 43 | { |
| 44 | __mpz_struct _mp_num; |
| 45 | __mpz_struct _mp_den; |
| 46 | } __mpq_struct; |
| 47 | |
| 48 | typedef __mpq_struct mpq_t[1]; |
| 49 | |
| 50 | typedef const __mpq_struct *mpq_srcptr; |
| 51 | typedef __mpq_struct *mpq_ptr; |
| 52 | |
| 53 | #define mpq_numref(Q) (&((Q)->_mp_num)) |
| 54 | #define mpq_denref(Q) (&((Q)->_mp_den)) |
| 55 | |
| 56 | void mpq_abs (mpq_t, const mpq_t); |
| 57 | void mpq_add (mpq_t, const mpq_t, const mpq_t); |
| 58 | void mpq_canonicalize (mpq_t); |
| 59 | void mpq_clear (mpq_t); |
| 60 | int mpq_cmp (const mpq_t, const mpq_t); |
| 61 | int mpq_cmp_si (const mpq_t, signed long, unsigned long); |
| 62 | int mpq_cmp_ui (const mpq_t, unsigned long, unsigned long); |
| 63 | int mpq_cmp_z (const mpq_t, const mpz_t); |
| 64 | void mpq_div (mpq_t, const mpq_t, const mpq_t); |
| 65 | void mpq_div_2exp (mpq_t, const mpq_t, mp_bitcnt_t); |
| 66 | int mpq_equal (const mpq_t, const mpq_t); |
| 67 | double mpq_get_d (const mpq_t); |
| 68 | void mpq_get_den (mpz_t, const mpq_t); |
| 69 | void mpq_get_num (mpz_t, const mpq_t); |
| 70 | char * mpq_get_str (char *, int, const mpq_t q); |
| 71 | void mpq_init (mpq_t); |
| 72 | void mpq_inv (mpq_t, const mpq_t); |
| 73 | void mpq_mul (mpq_t, const mpq_t, const mpq_t); |
| 74 | void mpq_mul_2exp (mpq_t, const mpq_t, mp_bitcnt_t); |
| 75 | void mpq_neg (mpq_t, const mpq_t); |
| 76 | void mpq_set (mpq_t, const mpq_t); |
| 77 | void mpq_set_d (mpq_t, double); |
| 78 | void mpq_set_den (mpq_t, const mpz_t); |
| 79 | void mpq_set_num (mpq_t, const mpz_t); |
| 80 | void mpq_set_si (mpq_t, signed long, unsigned long); |
| 81 | int mpq_set_str (mpq_t, const char *, int); |
| 82 | void mpq_set_ui (mpq_t, unsigned long, unsigned long); |
| 83 | void mpq_set_z (mpq_t, const mpz_t); |
| 84 | int mpq_sgn (const mpq_t); |
| 85 | void mpq_sub (mpq_t, const mpq_t, const mpq_t); |
| 86 | void 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 */ |
| 106 | size_t mpq_out_str (FILE *, int, const mpq_t); |
| 107 | #endif |
| 108 | |
| 109 | void mpz_set_q (mpz_t, const mpq_t); |
| 110 | |
| 111 | #if defined (__cplusplus) |
| 112 | } |
| 113 | #endif |
| 114 | #endif /* __MINI_MPQ_H__ */ |