gmp_mpfr_sys/mpfr.rs
1// Copyright © 2017–2025 Trevor Spiteri
2
3// This program is free software: you can redistribute it and/or
4// modify it under the terms of the GNU Lesser General Public License
5// as published by the Free Software Foundation, either version 3 of
6// the License, or (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful, but
9// WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11// General Public License for more details.
12//
13// You should have received a copy of the GNU Lesser General Public
14// License and a copy of the GNU General Public License along with
15// this program. If not, see <https://www.gnu.org/licenses/>.
16
17/*!
18Function and type bindings for the [MPFR] library.
19
20# Examples
21
22```rust
23use core::mem::MaybeUninit;
24use gmp_mpfr_sys::mpfr;
25let one_third = 1.0_f64 / 3.0;
26unsafe {
27 let mut f = {
28 let mut f = MaybeUninit::uninit();
29 mpfr::init2(f.as_mut_ptr(), 53);
30 f.assume_init()
31 };
32 let dir = mpfr::set_d(&mut f, one_third, mpfr::rnd_t::RNDN);
33 assert_eq!(dir, 0);
34 let d = mpfr::get_d(&f, mpfr::rnd_t::RNDN);
35 assert_eq!(d, one_third);
36 mpfr::clear(&mut f);
37}
38```
39
40The following example is a translation of the [MPFR sample] found on
41the [MPFR] website. The program computes a lower bound on
421 + 1/1! + 1/2! + … + 1/100!
43using 200-bit precision. The program outputs:
44
45`Sum is 2.7182818284590452353602874713526624977572470936999595749669131e0`
46
47```rust
48use core::ffi::c_int;
49use core::mem::MaybeUninit;
50use gmp_mpfr_sys::mpfr;
51use gmp_mpfr_sys::mpfr::rnd_t;
52use libc::STDOUT_FILENO;
53
54fn main() {
55 unsafe {
56 let mut t = {
57 let mut t = MaybeUninit::uninit();
58 mpfr::init2(t.as_mut_ptr(), 200);
59 t.assume_init()
60 };
61 mpfr::set_d(&mut t, 1.0, rnd_t::RNDD);
62
63 let mut s = {
64 let mut s = MaybeUninit::uninit();
65 mpfr::init2(s.as_mut_ptr(), 200);
66 s.assume_init()
67 };
68 mpfr::set_d(&mut s, 1.0, rnd_t::RNDD);
69
70 let mut u = {
71 let mut u = MaybeUninit::uninit();
72 mpfr::init2(u.as_mut_ptr(), 200);
73 u.assume_init()
74 };
75
76 for i in 1..=100 {
77 mpfr::mul_ui(&mut t, &t, i, rnd_t::RNDU);
78 mpfr::set_d(&mut u, 1.0, rnd_t::RNDD);
79 mpfr::div(&mut u, &u, &t, rnd_t::RNDD);
80 mpfr::add(&mut s, &s, &u, rnd_t::RNDD);
81 }
82
83 let stdout = libc::fdopen(STDOUT_FILENO, b"w\0".as_ptr().cast());
84# let real_stdout = stdout;
85# let tmp_file = libc::tmpfile();
86# let stdout = if tmp_file.is_null() { real_stdout } else { tmp_file };
87 libc::fputs(b"Sum is \0".as_ptr().cast(), stdout);
88 mpfr::out_str(stdout, 10, 0, &s, rnd_t::RNDD);
89 libc::fputc(b'\n' as c_int, stdout);
90# libc::rewind(stdout);
91# let mut buf = [0u8; 73];
92# libc::fread(buf.as_mut_ptr().cast(), 1, 73, stdout);
93# let stdout = real_stdout;
94 libc::fclose(stdout);
95# if !tmp_file.is_null() {
96# libc::fclose(tmp_file);
97# assert_eq!(
98# &buf[..],
99# &b"Sum is 2.7182818284590452353602874713526624977572470936999595749669131e0\n"[..]
100# );
101# }
102
103 mpfr::clear(&mut s);
104 mpfr::clear(&mut t);
105 mpfr::clear(&mut u);
106 mpfr::free_cache();
107 }
108}
109```
110
111[MPFR sample]: https://www.mpfr.org/sample.html
112[MPFR]: https://www.mpfr.org/
113*/
114#![allow(non_camel_case_types, non_snake_case)]
115#![allow(clippy::needless_doctest_main)]
116
117use crate::gmp::{limb_t, mpf_t, mpq_t, mpz_t, randstate_t, NUMB_BITS};
118use core::ffi::{c_char, c_int, c_long, c_uint, c_ulong, c_void};
119use core::mem;
120use core::ptr::NonNull;
121use libc::{intmax_t, uintmax_t, FILE};
122
123include!(concat!(env!("OUT_DIR"), "/mpfr_h.rs"));
124
125/// See: [`mpfr_prec_t`](../C/MPFR/constant.MPFR_Basics.html#index-mpfr_005fprec_005ft)
126pub type prec_t = c_long;
127
128/// See: [`mpfr_rnd_t`](../C/MPFR/constant.MPFR_Basics.html#index-mpfr_005frnd_005ft)
129///
130/// # Planned change
131///
132/// In the next major version of the crate (version 2), this enum will
133/// be replaced by a type alias to [`c_int`]. The variants will be
134/// replaced by constants, for example `rnd_t::RNDN` will be replaced
135/// by a constant `RNDN` of type [`c_int`].
136#[repr(C)]
137#[derive(Clone, Copy, Debug)]
138#[allow(deprecated)]
139pub enum rnd_t {
140 /// See: [Rounding](../C/MPFR/constant.MPFR_Basics.html#Rounding)
141 ///
142 /// # Planned change
143 ///
144 /// In the next major version of the crate (version 2), the enum
145 /// will be removed. This variant will be replaced by a constant
146 /// `RNDN` of type [`c_int`].
147 RNDN = 0,
148 /// See: [Rounding Modes](../C/MPFR/constant.MPFR_Basics.html#Rounding)
149 ///
150 /// # Planned change
151 ///
152 /// In the next major version of the crate (version 2), the enum
153 /// will be removed. This variant will be replaced by a constant
154 /// `RNDZ` of type [`c_int`].
155 RNDZ = 1,
156 /// See: [Rounding Modes](../C/MPFR/constant.MPFR_Basics.html#Rounding)
157 ///
158 /// # Planned change
159 ///
160 /// In the next major version of the crate (version 2), the enum
161 /// will be removed. This variant will be replaced by a constant
162 /// `RNDU` of type [`c_int`].
163 RNDU = 2,
164 /// See: [Rounding Modes](../C/MPFR/constant.MPFR_Basics.html#Rounding)
165 ///
166 /// # Planned change
167 ///
168 /// In the next major version of the crate (version 2), the enum
169 /// will be removed. This variant will be replaced by a constant
170 /// `RNDD` of type [`c_int`].
171 RNDD = 3,
172 /// See: [Rounding Modes](../C/MPFR/constant.MPFR_Basics.html#Rounding)
173 ///
174 /// # Planned change
175 ///
176 /// In the next major version of the crate (version 2), the enum
177 /// will be removed. This variant will be replaced by a constant
178 /// `RNDA` of type [`c_int`].
179 RNDA = 4,
180 /// See: [Rounding Modes](../C/MPFR/constant.MPFR_Basics.html#Rounding)
181 ///
182 /// # Planned change
183 ///
184 /// In the next major version of the crate (version 2), the enum
185 /// will be removed. This variant will be replaced by a constant
186 /// `RNDF` of type [`c_int`].
187 RNDF = 5,
188 #[doc(hidden)]
189 #[deprecated(since = "1.1.0", note = "do not use!")]
190 RNDNA = -1,
191}
192
193/// See: [`mpfr_flags_t`](../C/MPFR/constant.MPFR_Basics.html#index-mpfr_005fflags_005ft)
194pub type flags_t = c_uint;
195
196/// See: [Exception Related Functions](../C/MPFR/constant.MPFR_Interface.html#Exception-Related-Functions)
197pub type exp_t = c_long;
198
199/// See: [Nomenclature and Types](../C/MPFR/constant.MPFR_Basics.html#Nomenclature-and-Types)
200pub const PREC_MIN: prec_t = 1;
201/// See: [Nomenclature and Types](../C/MPFR/constant.MPFR_Basics.html#Nomenclature-and-Types)
202pub const PREC_MAX: prec_t = prec_t::MAX - 256;
203
204/// See: [`mpfr_t`](../C/MPFR/constant.MPFR_Basics.html#index-mpfr_005ft)
205/// and [Internals](../C/MPFR/constant.MPFR_Interface.html#Internals)
206///
207#[doc = include_str!("internal_fields.md")]
208#[repr(C)]
209#[derive(Clone, Copy, Debug)]
210pub struct mpfr_t {
211 /// See: [Internals](../C/MPFR/constant.MPFR_Interface.html#Internals)
212 pub prec: prec_t,
213 /// See: [Internals](../C/MPFR/constant.MPFR_Interface.html#Internals)
214 pub sign: c_int,
215 /// See: [Internals](../C/MPFR/constant.MPFR_Interface.html#Internals)
216 pub exp: exp_t,
217 /// See: [Internals](../C/MPFR/constant.MPFR_Interface.html#Internals)
218 pub d: NonNull<limb_t>,
219}
220
221/// See: [`mpfr_custom_init_set`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcustom_005finit_005fset)
222pub const NAN_KIND: c_int = 0;
223/// See: [`mpfr_custom_init_set`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcustom_005finit_005fset)
224pub const INF_KIND: c_int = 1;
225/// See: [`mpfr_custom_init_set`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcustom_005finit_005fset)
226pub const ZERO_KIND: c_int = 2;
227/// See: [`mpfr_custom_init_set`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcustom_005finit_005fset)
228pub const REGULAR_KIND: c_int = 3;
229
230/// See: [`mpfr_free_cache2`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffree_005fcache2)
231pub const FREE_LOCAL_CACHE: c_int = 1;
232/// See: [`mpfr_free_cache2`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffree_005fcache2)
233pub const FREE_GLOBAL_CACHE: c_int = 2;
234
235// Types for function declarations in this file.
236
237type mpz_srcptr = *const mpz_t;
238type mpz_ptr = *mut mpz_t;
239type mpq_srcptr = *const mpq_t;
240type mpq_ptr = *mut mpq_t;
241type mpf_srcptr = *const mpf_t;
242type mpf_ptr = *mut mpf_t;
243type randstate_ptr = *mut randstate_t;
244type mpfr_ptr = *mut mpfr_t;
245type mpfr_srcptr = *const mpfr_t;
246
247// Private constants.
248
249const EXP_MAX: exp_t = exp_t::MAX;
250const EXP_NAN: exp_t = 1 - EXP_MAX;
251const EXP_ZERO: exp_t = 0 - EXP_MAX;
252const EXP_INF: exp_t = 2 - EXP_MAX;
253
254// Initialization Functions
255
256extern "C" {
257 /// See: [`mpfr_init2`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005finit2)
258 #[link_name = "mpfr_init2"]
259 pub fn init2(x: mpfr_ptr, prec: prec_t);
260 /// See: [`mpfr_inits2`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005finits2)
261 #[link_name = "mpfr_inits2"]
262 pub fn inits2(prec: prec_t, x: mpfr_ptr, ...);
263 /// See: [`mpfr_clear`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fclear)
264 #[link_name = "mpfr_clear"]
265 pub fn clear(x: mpfr_ptr);
266 /// See: [`mpfr_clears`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fclears)
267 #[link_name = "mpfr_clears"]
268 pub fn clears(x: mpfr_ptr, ...);
269 /// See: [`mpfr_init`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005finit)
270 #[link_name = "mpfr_init"]
271 pub fn init(x: mpfr_ptr);
272 /// See: [`mpfr_inits`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005finits)
273 #[link_name = "mpfr_inits"]
274 pub fn inits(x: mpfr_ptr, ...);
275}
276// macro will be exported at top level, so link to C/MPFR... not to ../C/MPFR...
277/// See: [`MPFR_DECL_INIT`](C/MPFR/constant.MPFR_Interface.html#index-MPFR_005fDECL_005fINIT)
278#[macro_export]
279macro_rules! MPFR_DECL_INIT {
280 ($name:ident, $prec:expr) => {
281 // limbs is visible only in one macro instance thanks to macro hygiene
282 let mut limbs: [core::mem::MaybeUninit<$crate::gmp::limb_t>;
283 ($prec as usize - 1) / $crate::gmp::NUMB_BITS as usize + 1] =
284 unsafe { core::mem::MaybeUninit::uninit().assume_init() };
285 let mut $name = $crate::mpfr::mpfr_t {
286 prec: $prec as $crate::mpfr::prec_t,
287 sign: 1,
288 exp: 1 - $crate::mpfr::exp_t::MAX,
289 d: unsafe { core::ptr::NonNull::new_unchecked(limbs[..].as_mut_ptr()).cast() },
290 };
291 };
292}
293extern "C" {
294 /// See: [`mpfr_set_default_prec`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fdefault_005fprec)
295 #[link_name = "mpfr_set_default_prec"]
296 pub fn set_default_prec(prec: prec_t);
297 /// See: [`mpfr_get_default_prec`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005fdefault_005fprec)
298 #[link_name = "mpfr_get_default_prec"]
299 pub fn get_default_prec() -> prec_t;
300 /// See: [`mpfr_set_prec`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fprec)
301 #[link_name = "mpfr_set_prec"]
302 pub fn set_prec(x: mpfr_ptr, prec: prec_t);
303}
304/// See: [`mpfr_get_prec`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005fprec)
305#[inline]
306pub const unsafe extern "C" fn get_prec(x: mpfr_srcptr) -> prec_t {
307 unsafe { (*x).prec }
308}
309
310// Assignment Functions
311
312extern "C" {
313 #[link_name = "mpfr_set4"]
314 fn set4(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t, i: c_int) -> c_int;
315}
316/// See: [`mpfr_set`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset)
317#[inline]
318pub unsafe extern "C" fn set(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int {
319 unsafe { set4(rop, op, rnd, (*op).sign) }
320}
321extern "C" {
322 /// See: [`mpfr_set_ui`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fui)
323 #[link_name = "mpfr_set_ui"]
324 pub fn set_ui(rop: mpfr_ptr, op: c_ulong, rnd: rnd_t) -> c_int;
325 /// See: [`mpfr_set_si`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fsi)
326 #[link_name = "mpfr_set_si"]
327 pub fn set_si(rop: mpfr_ptr, op: c_long, rnd: rnd_t) -> c_int;
328 /// See: [`mpfr_set_uj`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fuj)
329 #[link_name = "__gmpfr_set_uj"]
330 pub fn set_uj(rop: mpfr_ptr, op: uintmax_t, rnd: rnd_t) -> c_int;
331 /// See: [`mpfr_set_sj`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fsj)
332 #[link_name = "__gmpfr_set_sj"]
333 pub fn set_sj(rop: mpfr_ptr, op: intmax_t, rnd: rnd_t) -> c_int;
334 /// See: [`mpfr_set_flt`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fflt)
335 #[link_name = "mpfr_set_flt"]
336 pub fn set_flt(rop: mpfr_ptr, op: f32, rnd: rnd_t) -> c_int;
337 /// See: [`mpfr_set_d`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fd)
338 #[link_name = "mpfr_set_d"]
339 pub fn set_d(rop: mpfr_ptr, op: f64, rnd: rnd_t) -> c_int;
340 /// See: [`mpfr_set_z`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fz)
341 #[link_name = "mpfr_set_z"]
342 pub fn set_z(rop: mpfr_ptr, op: mpz_srcptr, rnd: rnd_t) -> c_int;
343 /// See: [`mpfr_set_q`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fq)
344 #[link_name = "mpfr_set_q"]
345 pub fn set_q(rop: mpfr_ptr, op: mpq_srcptr, rnd: rnd_t) -> c_int;
346 /// See: [`mpfr_set_f`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005ff)
347 #[link_name = "mpfr_set_f"]
348 pub fn set_f(rop: mpfr_ptr, op: mpf_srcptr, rnd: rnd_t) -> c_int;
349 /// See: [`mpfr_set_ui_2exp`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fui_005f2exp)
350 #[link_name = "mpfr_set_ui_2exp"]
351 pub fn set_ui_2exp(rop: mpfr_ptr, op: c_ulong, e: exp_t, rnd: rnd_t) -> c_int;
352 /// See: [`mpfr_set_si_2exp`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fsi_005f2exp)
353 #[link_name = "mpfr_set_si_2exp"]
354 pub fn set_si_2exp(rop: mpfr_ptr, op: c_long, e: exp_t, rnd: rnd_t) -> c_int;
355 /// See: [`mpfr_set_uj_2exp`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fuj_005f2exp)
356 #[link_name = "__gmpfr_set_uj_2exp"]
357 pub fn set_uj_2exp(rop: mpfr_ptr, op: uintmax_t, e: intmax_t, rnd: rnd_t) -> c_int;
358 /// See: [`mpfr_set_sj_2exp`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fsj_005f2exp)
359 #[link_name = "__gmpfr_set_sj_2exp"]
360 pub fn set_sj_2exp(rop: mpfr_ptr, op: intmax_t, e: intmax_t, rnd: rnd_t) -> c_int;
361 /// See: [`mpfr_set_z_2exp`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fz_005f2exp)
362 #[link_name = "mpfr_set_z_2exp"]
363 pub fn set_z_2exp(rop: mpfr_ptr, op: mpz_srcptr, e: exp_t, rnd: rnd_t) -> c_int;
364 /// See: [`mpfr_set_str`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fstr)
365 #[link_name = "mpfr_set_str"]
366 pub fn set_str(rop: mpfr_ptr, s: *const c_char, base: c_int, rnd: rnd_t) -> c_int;
367 /// See: [`mpfr_strtofr`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fstrtofr)
368 #[link_name = "mpfr_strtofr"]
369 pub fn strtofr(
370 rop: mpfr_ptr,
371 nptr: *const c_char,
372 endptr: *mut *mut c_char,
373 base: c_int,
374 rnd: rnd_t,
375 ) -> c_int;
376 /// See: [`mpfr_set_nan`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fnan)
377 #[link_name = "mpfr_set_nan"]
378 pub fn set_nan(x: mpfr_ptr);
379 /// See: [`mpfr_set_inf`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005finf)
380 #[link_name = "mpfr_set_inf"]
381 pub fn set_inf(x: mpfr_ptr, sign: c_int);
382 /// See: [`mpfr_set_zero`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fzero)
383 #[link_name = "mpfr_set_zero"]
384 pub fn set_zero(x: mpfr_ptr, sign: c_int);
385 /// See: [`mpfr_swap`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fswap)
386 #[link_name = "mpfr_swap"]
387 pub fn swap(x: mpfr_ptr, y: mpfr_ptr);
388}
389
390// Combined Initialization and Assignment Functions
391
392/// See: [`mpfr_init_set`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005finit_005fset)
393#[inline]
394pub unsafe extern "C" fn init_set(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int {
395 unsafe {
396 init(rop);
397 set(rop, op, rnd)
398 }
399}
400/// See: [`mpfr_init_set_ui`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005finit_005fset_005fui)
401#[inline]
402pub unsafe extern "C" fn init_set_ui(rop: mpfr_ptr, op: c_ulong, rnd: rnd_t) -> c_int {
403 unsafe {
404 init(rop);
405 set_ui(rop, op, rnd)
406 }
407}
408/// See: [`mpfr_init_set_si`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005finit_005fset_005fsi)
409#[inline]
410pub unsafe extern "C" fn init_set_si(rop: mpfr_ptr, op: c_long, rnd: rnd_t) -> c_int {
411 unsafe {
412 init(rop);
413 set_si(rop, op, rnd)
414 }
415}
416/// See: [`mpfr_init_set_d`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005finit_005fset_005fd)
417#[inline]
418pub unsafe extern "C" fn init_set_d(rop: mpfr_ptr, op: f64, rnd: rnd_t) -> c_int {
419 unsafe {
420 init(rop);
421 set_d(rop, op, rnd)
422 }
423}
424/// See: [`mpfr_init_set_z`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005finit_005fset_005fz)
425#[inline]
426pub unsafe extern "C" fn init_set_z(rop: mpfr_ptr, op: mpz_srcptr, rnd: rnd_t) -> c_int {
427 unsafe {
428 init(rop);
429 set_z(rop, op, rnd)
430 }
431}
432/// See: [`mpfr_init_set_q`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005finit_005fset_005fq)
433#[inline]
434pub unsafe extern "C" fn init_set_q(rop: mpfr_ptr, op: mpq_srcptr, rnd: rnd_t) -> c_int {
435 unsafe {
436 init(rop);
437 set_q(rop, op, rnd)
438 }
439}
440/// See: [`mpfr_init_set_f`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005finit_005fset_005ff)
441#[inline]
442pub unsafe extern "C" fn init_set_f(rop: mpfr_ptr, op: mpf_srcptr, rnd: rnd_t) -> c_int {
443 unsafe {
444 init(rop);
445 set_f(rop, op, rnd)
446 }
447}
448extern "C" {
449 /// See: [`mpfr_init_set_str`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005finit_005fset_005fstr)
450 #[link_name = "mpfr_init_set_str"]
451 pub fn init_set_str(x: mpfr_ptr, s: *const c_char, base: c_int, rnd: rnd_t) -> c_int;
452
453 // Conversion Functions
454
455 /// See: [`mpfr_get_flt`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005fflt)
456 #[link_name = "mpfr_get_flt"]
457 pub fn get_flt(op: mpfr_srcptr, rnd: rnd_t) -> f32;
458 /// See: [`mpfr_get_d`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005fd)
459 #[link_name = "mpfr_get_d"]
460 pub fn get_d(op: mpfr_srcptr, rnd: rnd_t) -> f64;
461 /// See: [`mpfr_get_si`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005fsi)
462 #[link_name = "mpfr_get_si"]
463 pub fn get_si(op: mpfr_srcptr, rnd: rnd_t) -> c_long;
464 /// See: [`mpfr_get_ui`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005fui)
465 #[link_name = "mpfr_get_ui"]
466 pub fn get_ui(op: mpfr_srcptr, rnd: rnd_t) -> c_ulong;
467 /// See: [`mpfr_get_sj`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005fsj)
468 #[link_name = "__gmpfr_mpfr_get_sj"]
469 pub fn get_sj(op: mpfr_srcptr, rnd: rnd_t) -> intmax_t;
470 /// See: [`mpfr_get_uj`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005fuj)
471 #[link_name = "__gmpfr_mpfr_get_uj"]
472 pub fn get_uj(op: mpfr_srcptr, rnd: rnd_t) -> uintmax_t;
473 /// See: [`mpfr_get_d_2exp`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005fd_005f2exp)
474 #[link_name = "mpfr_get_d_2exp"]
475 pub fn get_d_2exp(exp: *mut c_long, op: mpfr_srcptr, rnd: rnd_t) -> f64;
476 /// See: [`mpfr_frexp`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffrexp)
477 #[link_name = "mpfr_frexp"]
478 pub fn frexp(exp: *mut exp_t, y: mpfr_ptr, x: mpfr_srcptr, rnd: rnd_t) -> c_int;
479 /// See: [`mpfr_get_z_2exp`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005fz_005f2exp)
480 #[link_name = "mpfr_get_z_2exp"]
481 pub fn get_z_2exp(rop: mpz_ptr, op: mpfr_srcptr) -> exp_t;
482 /// See: [`mpfr_get_z`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005fz)
483 #[link_name = "mpfr_get_z"]
484 pub fn get_z(z: mpz_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
485 /// See: [`mpfr_get_q`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005fq)
486 #[link_name = "mpfr_get_q"]
487 pub fn get_q(rop: mpq_ptr, op: mpfr_srcptr);
488 /// See: [`mpfr_get_f`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005ff)
489 #[link_name = "mpfr_get_f"]
490 pub fn get_f(rop: mpf_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
491 /// See: [`mpfr_get_str_ndigits`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005fstr_005fndigits)
492 #[link_name = "mpfr_get_str_ndigits"]
493 pub fn get_str_ndigits(b: c_int, p: prec_t) -> usize;
494 /// See: [`mpfr_get_str`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005fstr)
495 #[link_name = "mpfr_get_str"]
496 pub fn get_str(
497 str: *mut c_char,
498 expptr: *mut exp_t,
499 base: c_int,
500 n: usize,
501 op: mpfr_srcptr,
502 rnd: rnd_t,
503 ) -> *mut c_char;
504 /// See: [`mpfr_free_str`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffree_005fstr)
505 #[link_name = "mpfr_free_str"]
506 pub fn free_str(str: *mut c_char);
507 /// See: [`mpfr_fits_ulong_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffits_005fulong_005fp)
508 #[link_name = "mpfr_fits_ulong_p"]
509 pub fn fits_ulong_p(op: mpfr_srcptr, rnd: rnd_t) -> c_int;
510 /// See: [`mpfr_fits_slong_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffits_005fslong_005fp)
511 #[link_name = "mpfr_fits_slong_p"]
512 pub fn fits_slong_p(op: mpfr_srcptr, rnd: rnd_t) -> c_int;
513 /// See: [`mpfr_fits_uint_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffits_005fuint_005fp)
514 #[link_name = "mpfr_fits_uint_p"]
515 pub fn fits_uint_p(op: mpfr_srcptr, rnd: rnd_t) -> c_int;
516 /// See: [`mpfr_fits_sint_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffits_005fsint_005fp)
517 #[link_name = "mpfr_fits_sint_p"]
518 pub fn fits_sint_p(op: mpfr_srcptr, rnd: rnd_t) -> c_int;
519 /// See: [`mpfr_fits_ushort_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffits_005fushort_005fp)
520 #[link_name = "mpfr_fits_ushort_p"]
521 pub fn fits_ushort_p(op: mpfr_srcptr, rnd: rnd_t) -> c_int;
522 /// See: [`mpfr_fits_sshort_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffits_005fsshort_005fp)
523 #[link_name = "mpfr_fits_sshort_p"]
524 pub fn fits_sshort_p(op: mpfr_srcptr, rnd: rnd_t) -> c_int;
525 /// See: [`mpfr_fits_uintmax_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffits_005fuintmax_005fp)
526 #[link_name = "mpfr_fits_uintmax_p"]
527 pub fn fits_uintmax_p(op: mpfr_srcptr, rnd: rnd_t) -> c_int;
528 /// See: [`mpfr_fits_intmax_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffits_005fintmax_005fp)
529 #[link_name = "mpfr_fits_intmax_p"]
530 pub fn fits_intmax_p(op: mpfr_srcptr, rnd: rnd_t) -> c_int;
531
532 // Arithmetic Functions
533
534 /// See: [`mpfr_add`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fadd)
535 #[link_name = "mpfr_add"]
536 pub fn add(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpfr_srcptr, rnd: rnd_t) -> c_int;
537 /// See: [`mpfr_add_ui`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fadd_005fui)
538 #[link_name = "mpfr_add_ui"]
539 pub fn add_ui(rop: mpfr_ptr, op1: mpfr_srcptr, op2: c_ulong, rnd: rnd_t) -> c_int;
540 /// See: [`mpfr_add_si`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fadd_005fsi)
541 #[link_name = "mpfr_add_si"]
542 pub fn add_si(rop: mpfr_ptr, op1: mpfr_srcptr, op2: c_long, rnd: rnd_t) -> c_int;
543 /// See: [`mpfr_add_d`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fadd_005fd)
544 #[link_name = "mpfr_add_d"]
545 pub fn add_d(rop: mpfr_ptr, op1: mpfr_srcptr, op2: f64, rnd: rnd_t) -> c_int;
546 /// See: [`mpfr_add_z`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fadd_005fz)
547 #[link_name = "mpfr_add_z"]
548 pub fn add_z(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpz_srcptr, rnd: rnd_t) -> c_int;
549 /// See: [`mpfr_add_q`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fadd_005fq)
550 #[link_name = "mpfr_add_q"]
551 pub fn add_q(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpq_srcptr, rnd: rnd_t) -> c_int;
552 /// See: [`mpfr_sub`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsub)
553 #[link_name = "mpfr_sub"]
554 pub fn sub(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpfr_srcptr, rnd: rnd_t) -> c_int;
555 /// See: [`mpfr_ui_sub`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fui_005fsub)
556 #[link_name = "mpfr_ui_sub"]
557 pub fn ui_sub(rop: mpfr_ptr, op1: c_ulong, op2: mpfr_srcptr, rnd: rnd_t) -> c_int;
558 /// See: [`mpfr_sub_ui`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsub_005fui)
559 #[link_name = "mpfr_sub_ui"]
560 pub fn sub_ui(rop: mpfr_ptr, op1: mpfr_srcptr, op2: c_ulong, rnd: rnd_t) -> c_int;
561 /// See: [`mpfr_si_sub`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsi_005fsub)
562 #[link_name = "mpfr_si_sub"]
563 pub fn si_sub(rop: mpfr_ptr, op1: c_long, op2: mpfr_srcptr, rnd: rnd_t) -> c_int;
564 /// See: [`mpfr_sub_si`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsub_005fsi)
565 #[link_name = "mpfr_sub_si"]
566 pub fn sub_si(rop: mpfr_ptr, op1: mpfr_srcptr, op2: c_long, rnd: rnd_t) -> c_int;
567 /// See: [`mpfr_d_sub`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fd_005fsub)
568 #[link_name = "mpfr_d_sub"]
569 pub fn d_sub(rop: mpfr_ptr, op1: f64, op2: mpfr_srcptr, rnd: rnd_t) -> c_int;
570 /// See: [`mpfr_sub_d`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsub_005fd)
571 #[link_name = "mpfr_sub_d"]
572 pub fn sub_d(rop: mpfr_ptr, op1: mpfr_srcptr, op2: f64, rnd: rnd_t) -> c_int;
573 /// See: [`mpfr_z_sub`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fz_005fsub)
574 #[link_name = "mpfr_z_sub"]
575 pub fn z_sub(rop: mpfr_ptr, op1: mpz_srcptr, op2: mpfr_srcptr, rnd: rnd_t) -> c_int;
576 /// See: [`mpfr_sub_z`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsub_005fz)
577 #[link_name = "mpfr_sub_z"]
578 pub fn sub_z(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpz_srcptr, rnd: rnd_t) -> c_int;
579 /// See: [`mpfr_sub_q`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsub_005fq)
580 #[link_name = "mpfr_sub_q"]
581 pub fn sub_q(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpq_srcptr, rnd: rnd_t) -> c_int;
582 /// See: [`mpfr_mul`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fmul)
583 #[link_name = "mpfr_mul"]
584 pub fn mul(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpfr_srcptr, rnd: rnd_t) -> c_int;
585 /// See: [`mpfr_mul_ui`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fmul_005fui)
586 #[link_name = "mpfr_mul_ui"]
587 pub fn mul_ui(rop: mpfr_ptr, op1: mpfr_srcptr, op2: c_ulong, rnd: rnd_t) -> c_int;
588 /// See: [`mpfr_mul_si`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fmul_005fsi)
589 #[link_name = "mpfr_mul_si"]
590 pub fn mul_si(rop: mpfr_ptr, op1: mpfr_srcptr, op2: c_long, rnd: rnd_t) -> c_int;
591 /// See: [`mpfr_mul_d`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fmul_005fd)
592 #[link_name = "mpfr_mul_d"]
593 pub fn mul_d(rop: mpfr_ptr, op1: mpfr_srcptr, op2: f64, rnd: rnd_t) -> c_int;
594 /// See: [`mpfr_mul_z`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fmul_005fz)
595 #[link_name = "mpfr_mul_z"]
596 pub fn mul_z(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpz_srcptr, rnd: rnd_t) -> c_int;
597 /// See: [`mpfr_mul_q`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fmul_005fq)
598 #[link_name = "mpfr_mul_q"]
599 pub fn mul_q(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpq_srcptr, rnd: rnd_t) -> c_int;
600 /// See: [`mpfr_sqr`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsqr)
601 #[link_name = "mpfr_sqr"]
602 pub fn sqr(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
603 /// See: [`mpfr_div`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fdiv)
604 #[link_name = "mpfr_div"]
605 pub fn div(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpfr_srcptr, rnd: rnd_t) -> c_int;
606 /// See: [`mpfr_ui_div`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fui_005fdiv)
607 #[link_name = "mpfr_ui_div"]
608 pub fn ui_div(rop: mpfr_ptr, op1: c_ulong, op2: mpfr_srcptr, rnd: rnd_t) -> c_int;
609 /// See: [`mpfr_div_ui`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fdiv_005fui)
610 #[link_name = "mpfr_div_ui"]
611 pub fn div_ui(rop: mpfr_ptr, op1: mpfr_srcptr, op2: c_ulong, rnd: rnd_t) -> c_int;
612 /// See: [`mpfr_si_div`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsi_005fdiv)
613 #[link_name = "mpfr_si_div"]
614 pub fn si_div(rop: mpfr_ptr, op1: c_long, op2: mpfr_srcptr, rnd: rnd_t) -> c_int;
615 /// See: [`mpfr_div_si`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fdiv_005fsi)
616 #[link_name = "mpfr_div_si"]
617 pub fn div_si(rop: mpfr_ptr, op1: mpfr_srcptr, op2: c_long, rnd: rnd_t) -> c_int;
618 /// See: [`mpfr_d_div`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fd_005fdiv)
619 #[link_name = "mpfr_d_div"]
620 pub fn d_div(rop: mpfr_ptr, op1: f64, op2: mpfr_srcptr, rnd: rnd_t) -> c_int;
621 /// See: [`mpfr_div_d`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fdiv_005fd)
622 #[link_name = "mpfr_div_d"]
623 pub fn div_d(rop: mpfr_ptr, op1: mpfr_srcptr, op2: f64, rnd: rnd_t) -> c_int;
624 /// See: [`mpfr_div_z`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fdiv_005fz)
625 #[link_name = "mpfr_div_z"]
626 pub fn div_z(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpz_srcptr, rnd: rnd_t) -> c_int;
627 /// See: [`mpfr_div_q`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fdiv_005fq)
628 #[link_name = "mpfr_div_q"]
629 pub fn div_q(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpq_srcptr, rnd: rnd_t) -> c_int;
630 /// See: [`mpfr_sqrt`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsqrt)
631 #[link_name = "mpfr_sqrt"]
632 pub fn sqrt(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
633 /// See: [`mpfr_sqrt_ui`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsqrt_005fui)
634 #[link_name = "mpfr_sqrt_ui"]
635 pub fn sqrt_ui(rop: mpfr_ptr, op: c_ulong, rnd: rnd_t) -> c_int;
636 /// See: [`mpfr_rec_sqrt`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005frec_005fsqrt)
637 #[link_name = "mpfr_rec_sqrt"]
638 pub fn rec_sqrt(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
639 /// See: [`mpfr_cbrt`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcbrt)
640 #[link_name = "mpfr_cbrt"]
641 pub fn cbrt(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
642 /// See: [`mpfr_rootn_ui`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005frootn_005fui)
643 #[link_name = "mpfr_rootn_ui"]
644 pub fn rootn_ui(rop: mpfr_ptr, op: mpfr_srcptr, n: c_ulong, rnd: rnd_t) -> c_int;
645 /// See: [`mpfr_rootn_si`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005frootn_005fsi)
646 #[link_name = "mpfr_rootn_si"]
647 pub fn rootn_si(rop: mpfr_ptr, op: mpfr_srcptr, n: c_long, rnd: rnd_t) -> c_int;
648 /// See: [`mpfr_root`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005froot)
649 #[link_name = "mpfr_root"]
650 #[deprecated(
651 since = "1.1.0",
652 note = "replaced by the slightly different `rootn_ui`"
653 )]
654 pub fn root(rop: mpfr_ptr, op: mpfr_srcptr, n: c_ulong, rnd: rnd_t) -> c_int;
655 /// See: [`mpfr_neg`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fneg)
656 #[link_name = "mpfr_neg"]
657 pub fn neg(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
658}
659/// See: [`mpfr_abs`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fabs)
660#[inline]
661pub unsafe extern "C" fn abs(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int {
662 unsafe { set4(rop, op, rnd, 1) }
663}
664extern "C" {
665 /// See: [`mpfr_dim`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fdim)
666 #[link_name = "mpfr_dim"]
667 pub fn dim(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpfr_srcptr, rnd: rnd_t) -> c_int;
668 /// See: [`mpfr_mul_2ui`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fmul_005f2ui)
669 #[link_name = "mpfr_mul_2ui"]
670 pub fn mul_2ui(rop: mpfr_ptr, op1: mpfr_srcptr, op2: c_ulong, rnd: rnd_t) -> c_int;
671 /// See: [`mpfr_mul_2si`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fmul_005f2si)
672 #[link_name = "mpfr_mul_2si"]
673 pub fn mul_2si(rop: mpfr_ptr, op1: mpfr_srcptr, op2: c_long, rnd: rnd_t) -> c_int;
674 /// See: [`mpfr_div_2ui`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fdiv_005f2ui)
675 #[link_name = "mpfr_div_2ui"]
676 pub fn div_2ui(rop: mpfr_ptr, op1: mpfr_srcptr, op2: c_ulong, rnd: rnd_t) -> c_int;
677 /// See: [`mpfr_div_2si`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fdiv_005f2si)
678 #[link_name = "mpfr_div_2si"]
679 pub fn div_2si(rop: mpfr_ptr, op1: mpfr_srcptr, op2: c_long, rnd: rnd_t) -> c_int;
680 /// See: [`mpfr_fac_ui`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffac_005fui)
681 #[link_name = "mpfr_fac_ui"]
682 pub fn fac_ui(rop: mpfr_ptr, op: c_ulong, rnd: rnd_t) -> c_int;
683 /// See: [`mpfr_fma`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffma)
684 #[link_name = "mpfr_fma"]
685 pub fn fma(
686 rop: mpfr_ptr,
687 op1: mpfr_srcptr,
688 op2: mpfr_srcptr,
689 op3: mpfr_srcptr,
690 rnd: rnd_t,
691 ) -> c_int;
692 /// See: [`mpfr_fms`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffms)
693 #[link_name = "mpfr_fms"]
694 pub fn fms(
695 rop: mpfr_ptr,
696 op1: mpfr_srcptr,
697 op2: mpfr_srcptr,
698 op3: mpfr_srcptr,
699 rnd: rnd_t,
700 ) -> c_int;
701 /// See: [`mpfr_fmma`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffmma)
702 #[link_name = "mpfr_fmma"]
703 pub fn fmma(
704 rop: mpfr_ptr,
705 op1: mpfr_srcptr,
706 op2: mpfr_srcptr,
707 op3: mpfr_srcptr,
708 op4: mpfr_srcptr,
709 rnd: rnd_t,
710 ) -> c_int;
711 /// See: [`mpfr_fmms`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffmms)
712 #[link_name = "mpfr_fmms"]
713 pub fn fmms(
714 rop: mpfr_ptr,
715 op1: mpfr_srcptr,
716 op2: mpfr_srcptr,
717 op3: mpfr_srcptr,
718 op4: mpfr_srcptr,
719 rnd: rnd_t,
720 ) -> c_int;
721 /// See: [`mpfr_hypot`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fhypot)
722 #[link_name = "mpfr_hypot"]
723 pub fn hypot(rop: mpfr_ptr, x: mpfr_srcptr, y: mpfr_srcptr, rnd: rnd_t) -> c_int;
724 /// See: [`mpfr_sum`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsum)
725 #[link_name = "mpfr_sum"]
726 pub fn sum(rop: mpfr_ptr, tab: *const mpfr_ptr, n: c_ulong, rnd: rnd_t) -> c_int;
727 /// See: [`mpfr_dot`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fdot)
728 #[link_name = "mpfr_dot"]
729 pub fn dot(
730 rop: mpfr_ptr,
731 a: *const mpfr_ptr,
732 b: *const mpfr_ptr,
733 n: c_ulong,
734 rnd: rnd_t,
735 ) -> c_int;
736}
737
738// Comparison Functions
739
740extern "C" {
741 #[link_name = "mpfr_cmp3"]
742 fn cmp3(op1: mpfr_srcptr, op2: mpfr_srcptr, i: c_int) -> c_int;
743}
744/// See: [`mpfr_cmp`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcmp)
745#[inline]
746pub unsafe extern "C" fn cmp(op1: mpfr_srcptr, op2: mpfr_srcptr) -> c_int {
747 unsafe { cmp3(op1, op2, 1) }
748}
749/// See: [`mpfr_cmp_ui`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcmp_005fui)
750#[inline]
751pub unsafe extern "C" fn cmp_ui(op1: mpfr_srcptr, op2: c_ulong) -> c_int {
752 unsafe { cmp_ui_2exp(op1, op2, 0) }
753}
754/// See: [`mpfr_cmp_si`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcmp_005fsi)
755#[inline]
756pub unsafe extern "C" fn cmp_si(op1: mpfr_srcptr, op2: c_long) -> c_int {
757 unsafe { cmp_si_2exp(op1, op2, 0) }
758}
759extern "C" {
760 /// See: [`mpfr_cmp_d`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcmp_005fd)
761 #[link_name = "mpfr_cmp_d"]
762 pub fn cmp_d(op1: mpfr_srcptr, op2: f64) -> c_int;
763 /// See: [`mpfr_cmp_z`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcmp_005fz)
764 #[link_name = "mpfr_cmp_z"]
765 pub fn cmp_z(op1: mpfr_srcptr, op2: mpz_srcptr) -> c_int;
766 /// See: [`mpfr_cmp_q`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcmp_005fq)
767 #[link_name = "mpfr_cmp_q"]
768 pub fn cmp_q(op1: mpfr_srcptr, op2: mpq_srcptr) -> c_int;
769 /// See: [`mpfr_cmp_f`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcmp_005ff)
770 #[link_name = "mpfr_cmp_f"]
771 pub fn cmp_f(op1: mpfr_srcptr, op2: mpf_srcptr) -> c_int;
772 /// See: [`mpfr_cmp_ui_2exp`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcmp_005fui_005f2exp)
773 #[link_name = "mpfr_cmp_ui_2exp"]
774 pub fn cmp_ui_2exp(op1: mpfr_srcptr, op2: c_ulong, e: exp_t) -> c_int;
775 /// See: [`mpfr_cmp_si_2exp`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcmp_005fsi_005f2exp)
776 #[link_name = "mpfr_cmp_si_2exp"]
777 pub fn cmp_si_2exp(op1: mpfr_srcptr, op2: c_long, e: exp_t) -> c_int;
778 /// See: [`mpfr_cmpabs`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcmpabs)
779 #[link_name = "mpfr_cmpabs"]
780 pub fn cmpabs(op1: mpfr_srcptr, op2: mpfr_srcptr) -> c_int;
781 /// See: [`mpfr_cmpabs_ui`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcmpabs_005fui)
782 #[link_name = "mpfr_cmpabs_ui"]
783 pub fn cmpabs_ui(op1: mpfr_srcptr, op2: c_ulong) -> c_int;
784}
785/// See: [`mpfr_nan_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fnan_005fp)
786#[inline]
787pub const unsafe extern "C" fn nan_p(op: mpfr_srcptr) -> c_int {
788 (unsafe { (*op).exp } == EXP_NAN) as c_int
789}
790/// See: [`mpfr_inf_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005finf_005fp)
791#[inline]
792pub const unsafe extern "C" fn inf_p(op: mpfr_srcptr) -> c_int {
793 (unsafe { (*op).exp } == EXP_INF) as c_int
794}
795/// See: [`mpfr_number_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fnumber_005fp)
796#[inline]
797pub const unsafe extern "C" fn number_p(op: mpfr_srcptr) -> c_int {
798 // Note: mpfr_number_p is not a macro in mpfr.h, but in isnum.c it simply returns
799 // MPFR_IS_FP(x), which is a macro defined in mpfr-impl.h as not nan and not inf
800 let exp = unsafe { (*op).exp };
801 (exp != EXP_NAN && exp != EXP_INF) as c_int
802}
803/// See: [`mpfr_zero_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fzero_005fp)
804#[inline]
805pub const unsafe extern "C" fn zero_p(op: mpfr_srcptr) -> c_int {
806 (unsafe { (*op).exp } == EXP_ZERO) as c_int
807}
808/// See: [`mpfr_regular_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fregular_005fp)
809#[inline]
810pub const unsafe extern "C" fn regular_p(op: mpfr_srcptr) -> c_int {
811 (unsafe { (*op).exp } > EXP_INF) as c_int
812}
813/// See: [`mpfr_sgn`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsgn)
814#[inline]
815pub unsafe extern "C" fn sgn(op: mpfr_srcptr) -> c_int {
816 if unsafe { (*op).exp } < EXP_INF {
817 unsafe {
818 if nan_p(op) != 0 {
819 set_erangeflag();
820 }
821 }
822 0
823 } else {
824 unsafe { (*op).sign }
825 }
826}
827extern "C" {
828 /// See: [`mpfr_greater_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fgreater_005fp)
829 #[link_name = "mpfr_greater_p"]
830 pub fn greater_p(op1: mpfr_srcptr, op2: mpfr_srcptr) -> c_int;
831 /// See: [`mpfr_greaterequal_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fgreaterequal_005fp)
832 #[link_name = "mpfr_greaterequal_p"]
833 pub fn greaterequal_p(op1: mpfr_srcptr, op2: mpfr_srcptr) -> c_int;
834 /// See: [`mpfr_less_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fless_005fp)
835 #[link_name = "mpfr_less_p"]
836 pub fn less_p(op1: mpfr_srcptr, op2: mpfr_srcptr) -> c_int;
837 /// See: [`mpfr_lessequal_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005flessequal_005fp)
838 #[link_name = "mpfr_lessequal_p"]
839 pub fn lessequal_p(op1: mpfr_srcptr, op2: mpfr_srcptr) -> c_int;
840 /// See: [`mpfr_equal_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fequal_005fp)
841 #[link_name = "mpfr_equal_p"]
842 pub fn equal_p(op1: mpfr_srcptr, op2: mpfr_srcptr) -> c_int;
843 /// See: [`mpfr_lessgreater_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005flessgreater_005fp)
844 #[link_name = "mpfr_lessgreater_p"]
845 pub fn lessgreater_p(op1: mpfr_srcptr, op2: mpfr_srcptr) -> c_int;
846 /// See: [`mpfr_unordered_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005funordered_005fp)
847 #[link_name = "mpfr_unordered_p"]
848 pub fn unordered_p(op1: mpfr_srcptr, op2: mpfr_srcptr) -> c_int;
849 /// See: [`mpfr_total_order_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ftotal_005forder_005fp)
850 #[link_name = "mpfr_total_order_p"]
851 pub fn total_order_p(x: mpfr_srcptr, y: mpfr_srcptr) -> c_int;
852
853 // Transcendental Functions
854
855 /// See: [`mpfr_log`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005flog)
856 #[link_name = "mpfr_log"]
857 pub fn log(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
858 /// See: [`mpfr_log_ui`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005flog_005fui)
859 #[link_name = "mpfr_log_ui"]
860 pub fn log_ui(rop: mpfr_ptr, op: c_ulong, rnd: rnd_t) -> c_int;
861 /// See: [`mpfr_log2`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005flog2)
862 #[link_name = "mpfr_log2"]
863 pub fn log2(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
864 /// See: [`mpfr_log10`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005flog10)
865 #[link_name = "mpfr_log10"]
866 pub fn log10(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
867 /// See: [`mpfr_log1p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005flog1p)
868 #[link_name = "mpfr_log1p"]
869 pub fn log1p(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
870 /// See: [`mpfr_log2p1`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005flog2p1)
871 #[link_name = "mpfr_log2p1"]
872 pub fn log2p1(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
873 /// See: [`mpfr_log10p1`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005flog10p1)
874 #[link_name = "mpfr_log10p1"]
875 pub fn log10p1(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
876 /// See: [`mpfr_exp`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fexp)
877 #[link_name = "mpfr_exp"]
878 pub fn exp(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
879 /// See: [`mpfr_exp2`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fexp2)
880 #[link_name = "mpfr_exp2"]
881 pub fn exp2(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
882 /// See: [`mpfr_exp10`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fexp10)
883 #[link_name = "mpfr_exp10"]
884 pub fn exp10(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
885 /// See: [`mpfr_expm1`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fexpm1)
886 #[link_name = "mpfr_expm1"]
887 pub fn expm1(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
888 /// See: [`mpfr_exp2m1`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fexp2m1)
889 #[link_name = "mpfr_exp2m1"]
890 pub fn exp2m1(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
891 /// See: [`mpfr_exp10m1`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fexp10m1)
892 #[link_name = "mpfr_exp10m1"]
893 pub fn exp10m1(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
894 /// See: [`mpfr_pow`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fpow)
895 #[link_name = "mpfr_pow"]
896 pub fn pow(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpfr_srcptr, rnd: rnd_t) -> c_int;
897 /// See: [`mpfr_powr`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fpowr)
898 #[link_name = "mpfr_powr"]
899 pub fn powr(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpfr_srcptr, rnd: rnd_t) -> c_int;
900 /// See: [`mpfr_pow_ui`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fpow_005fui)
901 #[link_name = "mpfr_pow_ui"]
902 pub fn pow_ui(rop: mpfr_ptr, op1: mpfr_srcptr, op2: c_ulong, rnd: rnd_t) -> c_int;
903 /// See: [`mpfr_pow_si`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fpow_005fsi)
904 #[link_name = "mpfr_pow_si"]
905 pub fn pow_si(rop: mpfr_ptr, op1: mpfr_srcptr, op2: c_long, rnd: rnd_t) -> c_int;
906 /// See: [`mpfr_pow_uj`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fpow_005fuj)
907 #[link_name = "__gmpfr_mpfr_pow_uj"]
908 pub fn pow_uj(rop: mpfr_ptr, op1: mpfr_srcptr, op2: uintmax_t, rnd: rnd_t) -> c_int;
909 /// See: [`mpfr_pow_sj`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fpow_005fsj)
910 #[link_name = "__gmpfr_mpfr_pow_sj"]
911 pub fn pow_sj(rop: mpfr_ptr, op1: mpfr_srcptr, op2: intmax_t, rnd: rnd_t) -> c_int;
912}
913/// See: [`mpfr_pown`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fpown)
914#[inline]
915pub unsafe extern "C" fn pown(rop: mpfr_ptr, op1: mpfr_srcptr, op2: intmax_t, rnd: rnd_t) -> c_int {
916 unsafe { pow_sj(rop, op1, op2, rnd) }
917}
918extern "C" {
919 /// See: [`mpfr_pow_z`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fpow_005fz)
920 #[link_name = "mpfr_pow_z"]
921 pub fn pow_z(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpz_srcptr, rnd: rnd_t) -> c_int;
922 /// See: [`mpfr_ui_pow_ui`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fui_005fpow_005fui)
923 #[link_name = "mpfr_ui_pow_ui"]
924 pub fn ui_pow_ui(rop: mpfr_ptr, op1: c_ulong, op2: c_ulong, rnd: rnd_t) -> c_int;
925 /// See: [`mpfr_ui_pow`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fui_005fpow)
926 #[link_name = "mpfr_ui_pow"]
927 pub fn ui_pow(rop: mpfr_ptr, op1: c_ulong, op2: mpfr_srcptr, rnd: rnd_t) -> c_int;
928 //int mpfr_compound_si (mpfr_t rop, mpfr_t op, long int n, mpfr_rnd_t rnd)
929 /// See: [`mpfr_compound_si`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcompound_005fsi)
930 #[link_name = "mpfr_compound_si"]
931 pub fn compound_si(rop: mpfr_ptr, op: mpfr_srcptr, n: c_long, rnd: rnd_t) -> c_int;
932 /// See: [`mpfr_cos`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcos)
933 #[link_name = "mpfr_cos"]
934 pub fn cos(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
935 /// See: [`mpfr_sin`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsin)
936 #[link_name = "mpfr_sin"]
937 pub fn sin(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
938 /// See: [`mpfr_tan`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ftan)
939 #[link_name = "mpfr_tan"]
940 pub fn tan(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
941 /// See: [`mpfr_cosu`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcosu)
942 #[link_name = "mpfr_cosu"]
943 pub fn cosu(rop: mpfr_ptr, op: mpfr_srcptr, u: c_ulong, rnd: rnd_t) -> c_int;
944 /// See: [`mpfr_sinu`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsinu)
945 #[link_name = "mpfr_sinu"]
946 pub fn sinu(rop: mpfr_ptr, op: mpfr_srcptr, u: c_ulong, rnd: rnd_t) -> c_int;
947 /// See: [`mpfr_tanu`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ftanu)
948 #[link_name = "mpfr_tanu"]
949 pub fn tanu(rop: mpfr_ptr, op: mpfr_srcptr, u: c_ulong, rnd: rnd_t) -> c_int;
950 /// See: [`mpfr_cospi`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcospi)
951 #[link_name = "mpfr_cospi"]
952 pub fn cospi(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
953 /// See: [`mpfr_sinpi`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsinpi)
954 #[link_name = "mpfr_sinpi"]
955 pub fn sinpi(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
956 /// See: [`mpfr_tanpi`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ftanpi)
957 #[link_name = "mpfr_tanpi"]
958 pub fn tanpi(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
959 /// See: [`mpfr_sin_cos`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsin_005fcos)
960 #[link_name = "mpfr_sin_cos"]
961 pub fn sin_cos(sop: mpfr_ptr, cop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
962 /// See: [`mpfr_sec`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsec)
963 #[link_name = "mpfr_sec"]
964 pub fn sec(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
965 /// See: [`mpfr_csc`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcsc)
966 #[link_name = "mpfr_csc"]
967 pub fn csc(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
968 /// See: [`mpfr_cot`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcot)
969 #[link_name = "mpfr_cot"]
970 pub fn cot(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
971 /// See: [`mpfr_acos`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005facos)
972 #[link_name = "mpfr_acos"]
973 pub fn acos(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
974 /// See: [`mpfr_asin`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fasin)
975 #[link_name = "mpfr_asin"]
976 pub fn asin(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
977 /// See: [`mpfr_atan`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fatan)
978 #[link_name = "mpfr_atan"]
979 pub fn atan(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
980 /// See: [`mpfr_acosu`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005facosu)
981 #[link_name = "mpfr_acosu"]
982 pub fn acosu(rop: mpfr_ptr, op: mpfr_srcptr, u: c_ulong, rnd: rnd_t) -> c_int;
983 /// See: [`mpfr_asinu`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fasinu)
984 #[link_name = "mpfr_asinu"]
985 pub fn asinu(rop: mpfr_ptr, op: mpfr_srcptr, u: c_ulong, rnd: rnd_t) -> c_int;
986 /// See: [`mpfr_atanu`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fatanu)
987 #[link_name = "mpfr_atanu"]
988 pub fn atanu(rop: mpfr_ptr, op: mpfr_srcptr, u: c_ulong, rnd: rnd_t) -> c_int;
989 /// See: [`mpfr_acospi`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005facospi)
990 #[link_name = "mpfr_acospi"]
991 pub fn acospi(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
992 /// See: [`mpfr_asinpi`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fasinpi)
993 #[link_name = "mpfr_asinpi"]
994 pub fn asinpi(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
995 /// See: [`mpfr_atanpi`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fatanpi)
996 #[link_name = "mpfr_atanpi"]
997 pub fn atanpi(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
998 /// See: [`mpfr_atan2`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fatan2)
999 #[link_name = "mpfr_atan2"]
1000 pub fn atan2(rop: mpfr_ptr, y: mpfr_srcptr, x: mpfr_srcptr, rnd: rnd_t) -> c_int;
1001 /// See: [`mpfr_atan2u`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fatan2u)
1002 #[link_name = "mpfr_atan2u"]
1003 pub fn atan2u(rop: mpfr_ptr, y: mpfr_srcptr, x: mpfr_srcptr, u: c_ulong, rnd: rnd_t) -> c_int;
1004 /// See: [`mpfr_atan2pi`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fatan2pi)
1005 #[link_name = "mpfr_atan2pi"]
1006 pub fn atan2pi(rop: mpfr_ptr, y: mpfr_srcptr, x: mpfr_srcptr, rnd: rnd_t) -> c_int;
1007 /// See: [`mpfr_cosh`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcosh)
1008 #[link_name = "mpfr_cosh"]
1009 pub fn cosh(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1010 /// See: [`mpfr_sinh`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsinh)
1011 #[link_name = "mpfr_sinh"]
1012 pub fn sinh(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1013 /// See: [`mpfr_tanh`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ftanh)
1014 #[link_name = "mpfr_tanh"]
1015 pub fn tanh(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1016 /// See: [`mpfr_sinh_cosh`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsinh_005fcosh)
1017 #[link_name = "mpfr_sinh_cosh"]
1018 pub fn sinh_cosh(sop: mpfr_ptr, cop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1019 /// See: [`mpfr_sech`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsech)
1020 #[link_name = "mpfr_sech"]
1021 pub fn sech(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1022 /// See: [`mpfr_csch`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcsch)
1023 #[link_name = "mpfr_csch"]
1024 pub fn csch(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1025 /// See: [`mpfr_coth`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcoth)
1026 #[link_name = "mpfr_coth"]
1027 pub fn coth(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1028 /// See: [`mpfr_acosh`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005facosh)
1029 #[link_name = "mpfr_acosh"]
1030 pub fn acosh(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1031 /// See: [`mpfr_asinh`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fasinh)
1032 #[link_name = "mpfr_asinh"]
1033 pub fn asinh(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1034 /// See: [`mpfr_atanh`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fatanh)
1035 #[link_name = "mpfr_atanh"]
1036 pub fn atanh(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1037 /// See: [`mpfr_eint`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005feint)
1038 #[link_name = "mpfr_eint"]
1039 pub fn eint(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1040 /// See: [`mpfr_li2`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fli2)
1041 #[link_name = "mpfr_li2"]
1042 pub fn li2(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1043 /// See: [`mpfr_gamma`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fgamma)
1044 #[link_name = "mpfr_gamma"]
1045 pub fn gamma(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1046 /// See: [`mpfr_gamma_inc`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fgamma_005finc)
1047 #[link_name = "mpfr_gamma_inc"]
1048 pub fn gamma_inc(rop: mpfr_ptr, op: mpfr_srcptr, op2: mpfr_srcptr, rnd: rnd_t) -> c_int;
1049 /// See: [`mpfr_lngamma`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005flngamma)
1050 #[link_name = "mpfr_lngamma"]
1051 pub fn lngamma(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1052 /// See: [`mpfr_lgamma`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005flgamma)
1053 #[link_name = "mpfr_lgamma"]
1054 pub fn lgamma(rop: mpfr_ptr, signp: *mut c_int, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1055 /// See: [`mpfr_digamma`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fdigamma)
1056 #[link_name = "mpfr_digamma"]
1057 pub fn digamma(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1058 /// See: [`mpfr_beta`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fbeta)
1059 #[link_name = "mpfr_beta"]
1060 pub fn beta(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpfr_srcptr, rnd: rnd_t) -> c_int;
1061 /// See: [`mpfr_zeta`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fzeta)
1062 #[link_name = "mpfr_zeta"]
1063 pub fn zeta(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1064 /// See: [`mpfr_zeta_ui`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fzeta_005fui)
1065 #[link_name = "mpfr_zeta_ui"]
1066 pub fn zeta_ui(rop: mpfr_ptr, op: c_ulong, rnd: rnd_t) -> c_int;
1067 /// See: [`mpfr_erf`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ferf)
1068 #[link_name = "mpfr_erf"]
1069 pub fn erf(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1070 /// See: [`mpfr_erfc`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ferfc)
1071 #[link_name = "mpfr_erfc"]
1072 pub fn erfc(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1073 /// See: [`mpfr_j0`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fj0)
1074 #[link_name = "mpfr_j0"]
1075 pub fn j0(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1076 /// See: [`mpfr_j1`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fj1)
1077 #[link_name = "mpfr_j1"]
1078 pub fn j1(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1079 /// See: [`mpfr_jn`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fjn)
1080 #[link_name = "mpfr_jn"]
1081 pub fn jn(rop: mpfr_ptr, n: c_long, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1082 /// See: [`mpfr_y0`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fy0)
1083 #[link_name = "mpfr_y0"]
1084 pub fn y0(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1085 /// See: [`mpfr_y1`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fy1)
1086 #[link_name = "mpfr_y1"]
1087 pub fn y1(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1088 /// See: [`mpfr_yn`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fyn)
1089 #[link_name = "mpfr_yn"]
1090 pub fn yn(rop: mpfr_ptr, n: c_long, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1091 /// See: [`mpfr_agm`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fagm)
1092 #[link_name = "mpfr_agm"]
1093 pub fn agm(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpfr_srcptr, rnd: rnd_t) -> c_int;
1094 /// See: [`mpfr_ai`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fai)
1095 #[link_name = "mpfr_ai"]
1096 pub fn ai(rop: mpfr_ptr, x: mpfr_srcptr, rnd: rnd_t) -> c_int;
1097 /// See: [`mpfr_const_log2`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fconst_005flog2)
1098 #[link_name = "mpfr_const_log2"]
1099 pub fn const_log2(rop: mpfr_ptr, rnd: rnd_t) -> c_int;
1100 /// See: [`mpfr_const_pi`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fconst_005fpi)
1101 #[link_name = "mpfr_const_pi"]
1102 pub fn const_pi(rop: mpfr_ptr, rnd: rnd_t) -> c_int;
1103 /// See: [`mpfr_const_euler`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fconst_005feuler)
1104 #[link_name = "mpfr_const_euler"]
1105 pub fn const_euler(rop: mpfr_ptr, rnd: rnd_t) -> c_int;
1106 /// See: [`mpfr_const_catalan`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fconst_005fcatalan)
1107 #[link_name = "mpfr_const_catalan"]
1108 pub fn const_catalan(rop: mpfr_ptr, rnd: rnd_t) -> c_int;
1109
1110 // Input and Output Functions
1111
1112 /// See: [`mpfr_out_str`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fout_005fstr)
1113 #[link_name = "__gmpfr_out_str"]
1114 pub fn out_str(stream: *mut FILE, base: c_int, n: usize, op: mpfr_srcptr, rnd: rnd_t) -> usize;
1115 /// See: [`mpfr_inp_str`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005finp_005fstr)
1116 #[link_name = "__gmpfr_inp_str"]
1117 pub fn inp_str(rop: mpfr_ptr, stream: *mut FILE, base: c_int, rnd: rnd_t) -> usize;
1118 /// See: [`mpfr_fpif_export`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffpip_005fexport)
1119 #[link_name = "__gmpfr_fpif_export"]
1120 pub fn fpif_export(stream: *mut FILE, op: mpfr_ptr) -> c_int;
1121 /// See: [`mpfr_fpif_import`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffpip_005fimport)
1122 #[link_name = "__gmpfr_fpif_import"]
1123 pub fn fpif_import(op: mpfr_ptr, stream: *mut FILE) -> c_int;
1124 /// See: [`mpfr_dump`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fdump)
1125 #[link_name = "mpfr_dump"]
1126 pub fn dump(op: mpfr_srcptr);
1127
1128 // Formatted Output Functions
1129
1130 /// See: [`mpfr_fprintf`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffprintf)
1131 #[link_name = "__gmpfr_fprintf"]
1132 pub fn fprintf(stream: *mut FILE, template: *const c_char, ...) -> c_int;
1133 /// See: [`mpfr_printf`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fprintf)
1134 #[link_name = "mpfr_printf"]
1135 pub fn printf(template: *const c_char, ...) -> c_int;
1136 /// See: [`mpfr_sprintf`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsprintf)
1137 #[link_name = "mpfr_sprintf"]
1138 pub fn sprintf(buf: *mut c_char, template: *const c_char, ...) -> c_int;
1139 /// See: [`mpfr_snprintf`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsnprintf)
1140 #[link_name = "mpfr_snprintf"]
1141 pub fn snprintf(buf: *mut c_char, n: usize, template: *const c_char, ...) -> c_int;
1142 /// See: [`mpfr_asprintf`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fasprintf)
1143 #[link_name = "mpfr_asprintf"]
1144 pub fn asprintf(str: *mut *mut c_char, template: *const c_char, ...) -> c_int;
1145
1146 // Integer and Remainder Related Functions
1147
1148 /// See: [`mpfr_rint`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005frint)
1149 #[link_name = "mpfr_rint"]
1150 pub fn rint(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1151}
1152/// See: [`mpfr_ceil`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fceil)
1153#[inline]
1154pub unsafe extern "C" fn ceil(rop: mpfr_ptr, op: mpfr_srcptr) -> c_int {
1155 unsafe { rint(rop, op, rnd_t::RNDU) }
1156}
1157/// See: [`mpfr_floor`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffloor)
1158#[inline]
1159pub unsafe extern "C" fn floor(rop: mpfr_ptr, op: mpfr_srcptr) -> c_int {
1160 unsafe { rint(rop, op, rnd_t::RNDD) }
1161}
1162/// See: [`mpfr_round`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fround)
1163#[inline]
1164pub unsafe extern "C" fn round(rop: mpfr_ptr, op: mpfr_srcptr) -> c_int {
1165 #[allow(deprecated)]
1166 unsafe {
1167 rint(rop, op, rnd_t::RNDNA)
1168 }
1169}
1170extern "C" {
1171 /// See: [`mpfr_roundeven`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005froundeven)
1172 #[link_name = "mpfr_roundeven"]
1173 pub fn roundeven(rop: mpfr_ptr, op: mpfr_srcptr) -> c_int;
1174}
1175/// See: [`mpfr_trunc`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ftrunc)
1176#[inline]
1177pub unsafe extern "C" fn trunc(rop: mpfr_ptr, op: mpfr_srcptr) -> c_int {
1178 unsafe { rint(rop, op, rnd_t::RNDZ) }
1179}
1180extern "C" {
1181 /// See: [`mpfr_rint_ceil`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005frint_005fceil)
1182 #[link_name = "mpfr_rint_ceil"]
1183 pub fn rint_ceil(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1184 /// See: [`mpfr_rint_floor`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005frint_005ffloor)
1185 #[link_name = "mpfr_rint_floor"]
1186 pub fn rint_floor(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1187 /// See: [`mpfr_rint_round`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005frint_005fround)
1188 #[link_name = "mpfr_rint_round"]
1189 pub fn rint_round(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1190 /// See: [`mpfr_rint_roundeven`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005frint_005froundeven)
1191 #[link_name = "mpfr_rint_roundeven"]
1192 pub fn rint_roundeven(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1193 /// See: [`mpfr_rint_trunc`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005frint_005ftrunc)
1194 #[link_name = "mpfr_rint_trunc"]
1195 pub fn rint_trunc(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1196 /// See: [`mpfr_frac`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffrac)
1197 #[link_name = "mpfr_frac"]
1198 pub fn frac(rop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1199 /// See: [`mpfr_modf`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fmodf)
1200 #[link_name = "mpfr_modf"]
1201 pub fn modf(iop: mpfr_ptr, fop: mpfr_ptr, op: mpfr_srcptr, rnd: rnd_t) -> c_int;
1202 /// See: [`mpfr_fmod`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffmod)
1203 #[link_name = "mpfr_fmod"]
1204 pub fn fmod(r: mpfr_ptr, x: mpfr_srcptr, y: mpfr_srcptr, rnd: rnd_t) -> c_int;
1205 /// See: [`mpfr_fmod_ui`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffmod_005fui)
1206 #[link_name = "mpfr_fmod_ui"]
1207 pub fn fmod_ui(r: mpfr_ptr, x: mpfr_srcptr, y: c_ulong, rnd: rnd_t) -> c_int;
1208 /// See: [`mpfr_fmodquo`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffmodquo)
1209 #[link_name = "mpfr_fmodquo"]
1210 pub fn fmodquo(
1211 r: mpfr_ptr,
1212 q: *mut c_long,
1213 x: mpfr_srcptr,
1214 y: mpfr_srcptr,
1215 rnd: rnd_t,
1216 ) -> c_int;
1217 /// See: [`mpfr_remainder`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fremainder)
1218 #[link_name = "mpfr_remainder"]
1219 pub fn remainder(r: mpfr_ptr, x: mpfr_srcptr, y: mpfr_srcptr, rnd: rnd_t) -> c_int;
1220 /// See: [`mpfr_remquo`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fremquo)
1221 #[link_name = "mpfr_remquo"]
1222 pub fn remquo(r: mpfr_ptr, q: *mut c_long, x: mpfr_srcptr, y: mpfr_srcptr, rnd: rnd_t)
1223 -> c_int;
1224 /// See: [`mpfr_integer_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005finteger_005fp)
1225 #[link_name = "mpfr_integer_p"]
1226 pub fn integer_p(op: mpfr_srcptr) -> c_int;
1227
1228 // Rounding Related Functions
1229
1230 /// See: [`mpfr_set_default_rounding_mode`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fdefault_005frounding_005fmode)
1231 #[link_name = "mpfr_set_default_rounding_mode"]
1232 pub fn set_default_rounding_mode(rnd: rnd_t);
1233 /// See: [`mpfr_get_default_rounding_mode`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005fdefault_005frounding_005fmode)
1234 #[link_name = "mpfr_get_default_rounding_mode"]
1235 pub fn get_default_rounding_mode() -> rnd_t;
1236 /// See: [`mpfr_prec_round`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fprec_005fround)
1237 #[link_name = "mpfr_prec_round"]
1238 pub fn prec_round(x: mpfr_ptr, prec: prec_t, rnd: rnd_t) -> c_int;
1239 /// See: [`mpfr_can_round`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcan_005fround)
1240 #[link_name = "mpfr_can_round"]
1241 pub fn can_round(b: mpfr_srcptr, err: exp_t, rnd1: rnd_t, rnd2: rnd_t, prec: prec_t) -> c_int;
1242 /// See: [`mpfr_min_prec`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fmin_005fprec)
1243 #[link_name = "mpfr_min_prec"]
1244 pub fn min_prec(x: mpfr_srcptr) -> prec_t;
1245 /// See: [`mpfr_print_rnd_mode`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fprint_005frnd_005fmode)
1246 #[link_name = "mpfr_print_rnd_mode"]
1247 pub fn print_rnd_mode(rnd: rnd_t) -> *const c_char;
1248}
1249// macro will be exported at top level, so link to C/MPFR... not to ../C/MPFR...
1250/// See: [`mpfr_round_nearest_away`](C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fround_005fnearest_005faway)
1251#[macro_export]
1252macro_rules! mpfr_round_nearest_away {
1253 ($foo:expr, $rop:expr $(, $op:expr)*) => {{
1254 use core::ffi::c_int;
1255 type mpfr_ptr = *mut $crate::mpfr::mpfr_t;
1256 let rop: mpfr_ptr = $rop;
1257 extern "C" {
1258 fn mpfr_round_nearest_away_begin(rop: mpfr_ptr);
1259 fn mpfr_round_nearest_away_end(rop: mpfr_ptr, inex: c_int) -> c_int;
1260 }
1261 mpfr_round_nearest_away_begin(rop);
1262 mpfr_round_nearest_away_end(
1263 rop,
1264 $foo(rop $(, $op)*, $crate::mpfr::rnd_t::RNDN),
1265 )
1266 }};
1267}
1268
1269extern "C" {
1270 // Miscellaneous Functions
1271
1272 /// See: [`mpfr_nexttoward`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fnexttoward)
1273 #[link_name = "mpfr_nexttoward"]
1274 pub fn nexttoward(x: mpfr_ptr, y: mpfr_srcptr);
1275 /// See: [`mpfr_nextabove`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fnextabove)
1276 #[link_name = "mpfr_nextabove"]
1277 pub fn nextabove(x: mpfr_ptr);
1278 /// See: [`mpfr_nextbelow`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fnextbelow)
1279 #[link_name = "mpfr_nextbelow"]
1280 pub fn nextbelow(x: mpfr_ptr);
1281 /// See: [`mpfr_min`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fmin)
1282 #[link_name = "mpfr_min"]
1283 pub fn min(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpfr_srcptr, rnd: rnd_t) -> c_int;
1284 /// See: [`mpfr_max`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fmax)
1285 #[link_name = "mpfr_max"]
1286 pub fn max(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpfr_srcptr, rnd: rnd_t) -> c_int;
1287 /// See: [`mpfr_urandomb`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005furandomb)
1288 #[link_name = "mpfr_urandomb"]
1289 pub fn urandomb(rop: mpfr_ptr, state: randstate_ptr) -> c_int;
1290 /// See: [`mpfr_urandom`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005furandom)
1291 #[link_name = "mpfr_urandom"]
1292 pub fn urandom(rop: mpfr_ptr, state: randstate_ptr, rnd: rnd_t) -> c_int;
1293 /// See: [`mpfr_nrandom`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fnrandom)
1294 #[link_name = "mpfr_nrandom"]
1295 pub fn nrandom(rop1: mpfr_ptr, state: randstate_ptr, rnd: rnd_t) -> c_int;
1296 /// See: [`mpfr_grandom`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fgrandom)
1297 #[link_name = "mpfr_grandom"]
1298 #[deprecated(since = "1.1.0", note = "replaced by `nrandom`")]
1299 pub fn grandom(rop1: mpfr_ptr, rop2: mpfr_ptr, state: randstate_ptr, rnd: rnd_t) -> c_int;
1300 /// See: [`mpfr_erandom`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ferandom)
1301 #[link_name = "mpfr_erandom"]
1302 pub fn erandom(rop1: mpfr_ptr, state: randstate_ptr, rnd: rnd_t) -> c_int;
1303}
1304/// See: [`mpfr_get_exp`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005fexp)
1305#[inline]
1306pub const unsafe extern "C" fn get_exp(x: mpfr_srcptr) -> exp_t {
1307 unsafe { (*x).exp }
1308}
1309extern "C" {
1310 /// See: [`mpfr_set_exp`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fexp)
1311 #[link_name = "mpfr_set_exp"]
1312 pub fn set_exp(x: mpfr_ptr, e: exp_t) -> c_int;
1313}
1314/// See: [`mpfr_signbit`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsignbit)
1315#[inline]
1316pub const unsafe extern "C" fn signbit(op: mpfr_srcptr) -> c_int {
1317 (unsafe { (*op).sign } < 0) as c_int
1318}
1319/// See: [`mpfr_setsign`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsetsign)
1320#[inline]
1321pub unsafe extern "C" fn setsign(rop: mpfr_ptr, op: mpfr_srcptr, s: c_int, rnd: rnd_t) -> c_int {
1322 unsafe { set4(rop, op, rnd, if s != 0 { -1 } else { 1 }) }
1323}
1324/// See: [`mpfr_copysign`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcopysign)
1325#[inline]
1326pub unsafe extern "C" fn copysign(
1327 rop: mpfr_ptr,
1328 op1: mpfr_srcptr,
1329 op2: mpfr_srcptr,
1330 rnd: rnd_t,
1331) -> c_int {
1332 unsafe { set4(rop, op1, rnd, (*op2).sign) }
1333}
1334extern "C" {
1335 /// See: [`mpfr_get_version`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005fversion)
1336 #[link_name = "mpfr_get_version"]
1337 pub fn get_version() -> *const c_char;
1338}
1339/// See: [`MPFR_VERSION`](../C/MPFR/constant.MPFR_Interface.html#index-MPFR_005fVERSION)
1340pub const VERSION: c_int = (VERSION_MAJOR << 16) | (VERSION_MINOR << 8) | VERSION_PATCHLEVEL;
1341/// See: [`MPFR_VERSION_MAJOR`](../C/MPFR/constant.MPFR_Interface.html#index-MPFR_005fVERSION_005fMAJOR)
1342pub const VERSION_MAJOR: c_int = MPFR_VERSION_MAJOR;
1343/// See: [`MPFR_VERSION_MINOR`](../C/MPFR/constant.MPFR_Interface.html#index-MPFR_005fVERSION_005fMINOR)
1344pub const VERSION_MINOR: c_int = MPFR_VERSION_MINOR;
1345/// See: [`MPFR_VERSION_PATCHLEVEL`](../C/MPFR/constant.MPFR_Interface.html#index-MPFR_005fVERSION_005fPATCHLEVEL)
1346pub const VERSION_PATCHLEVEL: c_int = MPFR_VERSION_PATCHLEVEL;
1347/// See: [`MPFR_VERSION_STRING`](../C/MPFR/constant.MPFR_Interface.html#index-MPFR_005fVERSION_005fSTRING)
1348pub const VERSION_STRING: *const c_char = MPFR_VERSION_STRING;
1349/// See: [`MPFR_VERSION_NUM`](../C/MPFR/constant.MPFR_Interface.html#index-MPFR_005fVERSION_005fNUM)
1350#[inline]
1351pub const extern "C" fn VERSION_NUM(major: c_int, minor: c_int, patchlevel: c_int) -> c_int {
1352 (major << 16) | (minor << 8) | patchlevel
1353}
1354extern "C" {
1355 /// See: [`mpfr_get_patches`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005fpatches)
1356 #[link_name = "mpfr_get_patches"]
1357 pub fn get_patches() -> *const c_char;
1358 /// See: [`mpfr_buildopt_tls_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fbuildopt_005ftls_005fp)
1359 #[link_name = "mpfr_buildopt_tls_p"]
1360 pub fn buildopt_tls_p() -> c_int;
1361 /// See: [`mpfr_buildopt_float128_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fbuildopt_005ffloat128_005fp)
1362 #[link_name = "mpfr_buildopt_float128_p"]
1363 pub fn buildopt_float128_p() -> c_int;
1364 /// See: [`mpfr_buildopt_decimal_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fbuildopt_005fdecimal_005fp)
1365 #[link_name = "mpfr_buildopt_decimal_p"]
1366 pub fn buildopt_decimal_p() -> c_int;
1367 /// See: [`mpfr_buildopt_gmpinternals_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fbuildopt_005fgmpinternals_005fp)
1368 #[link_name = "mpfr_buildopt_gmpinternals_p"]
1369 pub fn buildopt_gmpinternals_p() -> c_int;
1370 /// See: [`mpfr_buildopt_sharedcache_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fbuildopt_005fsharedcache_005fp)
1371 #[link_name = "mpfr_buildopt_sharedcache_p"]
1372 pub fn buildopt_sharedcache_p() -> c_int;
1373 /// See: [`mpfr_buildopt_tune_case`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fbuildopt_005ftune_005fcase)
1374 #[link_name = "mpfr_buildopt_tune_case"]
1375 pub fn buildopt_tune_case() -> *const c_char;
1376
1377 // Exception Related Functions
1378
1379 /// See: [`mpfr_get_emin`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005femin)
1380 #[link_name = "mpfr_get_emin"]
1381 pub fn get_emin() -> exp_t;
1382 /// See: [`mpfr_get_emax`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005femax)
1383 #[link_name = "mpfr_get_emax"]
1384 pub fn get_emax() -> exp_t;
1385 /// See: [`mpfr_set_emin`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005femin)
1386 #[link_name = "mpfr_set_emin"]
1387 pub fn set_emin(exp: exp_t) -> c_int;
1388 /// See: [`mpfr_set_emax`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005femax)
1389 #[link_name = "mpfr_set_emax"]
1390 pub fn set_emax(exp: exp_t) -> c_int;
1391 /// See: [`mpfr_get_emin_min`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005femin_005fmin)
1392 #[link_name = "mpfr_get_emin_min"]
1393 pub fn get_emin_min() -> exp_t;
1394 /// See: [`mpfr_get_emin_max`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005femin_005fmax)
1395 #[link_name = "mpfr_get_emin_max"]
1396 pub fn get_emin_max() -> exp_t;
1397 /// See: [`mpfr_get_emax_min`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005femax_005fmin)
1398 #[link_name = "mpfr_get_emax_min"]
1399 pub fn get_emax_min() -> exp_t;
1400 /// See: [`mpfr_get_emax_max`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fget_005femax_005fmax)
1401 #[link_name = "mpfr_get_emax_max"]
1402 pub fn get_emax_max() -> exp_t;
1403 /// See: [`mpfr_check_range`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcheck_005frange)
1404 #[link_name = "mpfr_check_range"]
1405 pub fn check_range(x: mpfr_ptr, t: c_int, rnd: rnd_t) -> c_int;
1406 /// See: [`mpfr_subnormalize`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fsubnormalize)
1407 #[link_name = "mpfr_subnormalize"]
1408 pub fn subnormalize(x: mpfr_ptr, t: c_int, rnd: rnd_t) -> c_int;
1409 /// See: [`mpfr_clear_underflow`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fclear_005funderflow)
1410 #[link_name = "mpfr_clear_underflow"]
1411 pub fn clear_underflow();
1412 /// See: [`mpfr_clear_overflow`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fclear_005foverflow)
1413 #[link_name = "mpfr_clear_overflow"]
1414 pub fn clear_overflow();
1415 /// See: [`mpfr_clear_divby0`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fclear_005fdivby0)
1416 #[link_name = "mpfr_clear_divby0"]
1417 pub fn clear_divby0();
1418 /// See: [`mpfr_clear_nanflag`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fclear_005fnanflag)
1419 #[link_name = "mpfr_clear_nanflag"]
1420 pub fn clear_nanflag();
1421 /// See: [`mpfr_clear_inexflag`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fclear_005finexflag)
1422 #[link_name = "mpfr_clear_inexflag"]
1423 pub fn clear_inexflag();
1424 /// See: [`mpfr_clear_erangeflag`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fclear_005ferangeflag)
1425 #[link_name = "mpfr_clear_erangeflag"]
1426 pub fn clear_erangeflag();
1427 /// See: [`mpfr_set_underflow`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005funderflow)
1428 #[link_name = "mpfr_set_underflow"]
1429 pub fn set_underflow();
1430 /// See: [`mpfr_set_overflow`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005foverflow)
1431 #[link_name = "mpfr_set_overflow"]
1432 pub fn set_overflow();
1433 /// See: [`mpfr_set_divby0`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fdivby0)
1434 #[link_name = "mpfr_set_divby0"]
1435 pub fn set_divby0();
1436 /// See: [`mpfr_set_nanflag`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fnanflag)
1437 #[link_name = "mpfr_set_nanflag"]
1438 pub fn set_nanflag();
1439 /// See: [`mpfr_set_inexflag`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005finexflag)
1440 #[link_name = "mpfr_set_inexflag"]
1441 pub fn set_inexflag();
1442 /// See: [`mpfr_set_erangeflag`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005ferangeflag)
1443 #[link_name = "mpfr_set_erangeflag"]
1444 pub fn set_erangeflag();
1445 /// See: [`mpfr_clear_flags`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fclear_005fflags)
1446 #[link_name = "mpfr_clear_flags"]
1447 pub fn clear_flags();
1448 /// See: [`mpfr_underflow_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005funderflow_005fp)
1449 #[link_name = "mpfr_underflow_p"]
1450 pub fn underflow_p() -> c_int;
1451 /// See: [`mpfr_overflow_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005foverflow_005fp)
1452 #[link_name = "mpfr_overflow_p"]
1453 pub fn overflow_p() -> c_int;
1454 /// See: [`mpfr_divby0_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fdivby0_005fp)
1455 #[link_name = "mpfr_divby0_p"]
1456 pub fn divby0_p() -> c_int;
1457 /// See: [`mpfr_nanflag_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fnanflag_005fp)
1458 #[link_name = "mpfr_nanflag_p"]
1459 pub fn nanflag_p() -> c_int;
1460 /// See: [`mpfr_inexflag_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005finexflag_005fp)
1461 #[link_name = "mpfr_inexflag_p"]
1462 pub fn inexflag_p() -> c_int;
1463 /// See: [`mpfr_erangeflag_p`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ferangeflag_005fp)
1464 #[link_name = "mpfr_erangeflag_p"]
1465 pub fn erangeflag_p() -> c_int;
1466 /// See: [`mpfr_flags_clear`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fflags_005fclear)
1467 #[link_name = "mpfr_flags_clear"]
1468 pub fn flags_clear(mask: flags_t);
1469 /// See: [`mpfr_flags_set`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fflags_005fset)
1470 #[link_name = "mpfr_flags_set"]
1471 pub fn flags_set(mask: flags_t);
1472 /// See: [`mpfr_flags_test `](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fflags_005ftest)
1473 #[link_name = "mpfr_flags_test"]
1474 pub fn flags_test(mask: flags_t) -> flags_t;
1475 /// See: [`mpfr_flags_save`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fflags_005fsave)
1476 #[link_name = "mpfr_flags_save"]
1477 pub fn flags_save() -> flags_t;
1478 /// See: [`mpfr_flags_restore`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fflags_005frestore)
1479 #[link_name = "mpfr_flags_restore"]
1480 pub fn flags_restore(flags: flags_t, mask: flags_t);
1481
1482 // Memory Handling Functions
1483
1484 /// See: [`mpfr_free_cache`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffree_005fcache)
1485 #[link_name = "mpfr_free_cache"]
1486 pub fn free_cache();
1487 /// See: [`mpfr_free_cache2`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffree_005fcache2)
1488 #[link_name = "mpfr_free_cache2"]
1489 pub fn free_cache2(way: c_int);
1490 /// See: [`mpfr_free_pool`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005ffree_005fpool)
1491 #[link_name = "mpfr_free_pool"]
1492 pub fn free_pool();
1493 /// See: [`mpfr_mp_memory_cleanup`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fmp_005fmemory_005fcleanup)
1494 #[link_name = "mpfr_mp_memory_cleanup"]
1495 pub fn mp_memory_cleanup();
1496
1497 // Compatibility with MPF
1498
1499 /// See: [`mpfr_set_prec_raw`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fset_005fprec_005fraw)
1500 #[link_name = "mpfr_set_prec_raw"]
1501 pub fn set_prec_raw(x: mpfr_ptr, prec: prec_t);
1502 /// See: [`mpfr_eq`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005feq)
1503 #[link_name = "mpfr_eq"]
1504 pub fn eq(op1: mpfr_srcptr, op2: mpfr_srcptr, op3: c_ulong) -> c_int;
1505 /// See: [`mpfr_reldiff`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005freldiff)
1506 #[link_name = "mpfr_reldiff"]
1507 pub fn reldiff(rop: mpfr_ptr, op1: mpfr_srcptr, op2: mpfr_srcptr, rnd: rnd_t);
1508}
1509/// See: [`mpfr_mul_2exp`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fmul_005f2exp)
1510#[inline]
1511pub unsafe extern "C" fn mul_2exp(
1512 rop: mpfr_ptr,
1513 op1: mpfr_srcptr,
1514 op2: c_ulong,
1515 rnd: rnd_t,
1516) -> c_int {
1517 unsafe { mul_2ui(rop, op1, op2, rnd) }
1518}
1519/// See: [`mpfr_div_2exp`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fdiv_005f2exp)
1520#[inline]
1521pub unsafe extern "C" fn div_2exp(
1522 rop: mpfr_ptr,
1523 op1: mpfr_srcptr,
1524 op2: c_ulong,
1525 rnd: rnd_t,
1526) -> c_int {
1527 unsafe { div_2ui(rop, op1, op2, rnd) }
1528}
1529
1530// Custom Interface
1531
1532/// See: [`mpfr_custom_get_size`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcustom_005fget_005fsize)
1533#[inline]
1534pub const unsafe extern "C" fn custom_get_size(prec: prec_t) -> usize {
1535 let bits = NUMB_BITS as prec_t;
1536 ((prec + bits - 1) / bits) as usize * mem::size_of::<limb_t>()
1537}
1538/// See: [`mpfr_custom_init`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcustom_005finit)
1539#[inline]
1540pub const unsafe extern "C" fn custom_init(significand: *mut c_void, prec: prec_t) {
1541 let _ = (significand, prec);
1542}
1543/// See: [`mpfr_custom_init_set`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcustom_005finit_005fset)
1544#[inline]
1545pub unsafe extern "C" fn custom_init_set(
1546 x: mpfr_ptr,
1547 kind: c_int,
1548 exp: exp_t,
1549 prec: prec_t,
1550 significand: *mut c_void,
1551) {
1552 let (t, s) = if kind >= 0 { (kind, 1) } else { (-kind, -1) };
1553 let e = match t {
1554 REGULAR_KIND => exp,
1555 NAN_KIND => EXP_NAN,
1556 INF_KIND => EXP_INF,
1557 _ => EXP_ZERO,
1558 };
1559 unsafe {
1560 (*x).prec = prec;
1561 (*x).sign = s;
1562 (*x).exp = e;
1563 (*x).d = NonNull::new_unchecked(significand.cast());
1564 }
1565}
1566/// See: [`mpfr_custom_get_kind`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcustom_005fget_005fkind)
1567#[inline]
1568pub const unsafe extern "C" fn custom_get_kind(x: mpfr_srcptr) -> c_int {
1569 unsafe {
1570 if (*x).exp > EXP_INF {
1571 REGULAR_KIND * (*x).sign
1572 } else if (*x).exp == EXP_INF {
1573 INF_KIND * (*x).sign
1574 } else if (*x).exp == EXP_NAN {
1575 NAN_KIND
1576 } else {
1577 ZERO_KIND * (*x).sign
1578 }
1579 }
1580}
1581/// See: [`mpfr_custom_get_significand`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcustom_005fget_005fsignificand)
1582#[inline]
1583pub const unsafe extern "C" fn custom_get_significand(x: mpfr_srcptr) -> *mut c_void {
1584 unsafe { (*x).d }.as_ptr().cast()
1585}
1586/// See: [`mpfr_custom_get_exp`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcustom_005fget_005fexp)
1587#[inline]
1588pub const unsafe extern "C" fn custom_get_exp(x: mpfr_srcptr) -> exp_t {
1589 unsafe { (*x).exp }
1590}
1591/// See: [`mpfr_custom_move`](../C/MPFR/constant.MPFR_Interface.html#index-mpfr_005fcustom_005fmove)
1592#[inline]
1593pub unsafe extern "C" fn custom_move(x: mpfr_ptr, new_position: *mut c_void) {
1594 unsafe { (*x).d = NonNull::new_unchecked(new_position.cast()) }
1595}
1596
1597#[cfg(test)]
1598mod tests {
1599 use crate::mpfr;
1600 use core::mem::MaybeUninit;
1601
1602 fn version_matches_with_optional_p_suffix(to_test: &str, check: &str) -> bool {
1603 if to_test == check {
1604 true
1605 } else if !to_test.starts_with(check) {
1606 false
1607 } else {
1608 to_test[check.len()..].starts_with("-p")
1609 }
1610 }
1611
1612 #[test]
1613 fn check_version() {
1614 use crate::tests;
1615
1616 let (major, minor, patchlevel) = (4, 2, 2);
1617 // do not include "-p*" suffix
1618 let version = "4.2.2";
1619
1620 assert_eq!(mpfr::VERSION_MAJOR, major);
1621 assert!(mpfr::VERSION_MINOR >= minor);
1622 if cfg!(not(feature = "use-system-libs")) {
1623 assert!(mpfr::VERSION_MINOR > minor || mpfr::VERSION_PATCHLEVEL >= patchlevel);
1624 if mpfr::VERSION_MINOR == minor && mpfr::VERSION_PATCHLEVEL == patchlevel {
1625 // tested string can have "-p*" suffix
1626 assert!(version_matches_with_optional_p_suffix(
1627 unsafe { tests::str_from_cstr(mpfr::get_version()) },
1628 version
1629 ));
1630 assert!(version_matches_with_optional_p_suffix(
1631 unsafe { tests::str_from_cstr(mpfr::VERSION_STRING) },
1632 version
1633 ));
1634 }
1635 }
1636 }
1637
1638 #[test]
1639 fn check_round_nearest_away() {
1640 unsafe {
1641 let mut f = MaybeUninit::uninit();
1642 mpfr::init2(f.as_mut_ptr(), 4);
1643 let mut f = f.assume_init();
1644
1645 // mpfr_round_nearest_away needs emin > emin_min
1646 if mpfr::get_emin() == mpfr::get_emin_min() {
1647 mpfr::set_emin(mpfr::get_emin_min() + 1);
1648 }
1649
1650 // tie to even: 10101 becomes 10100
1651 let dir_tie_even = mpfr::set_ui(&mut f, 21, mpfr::rnd_t::RNDN);
1652 assert!(dir_tie_even < 0);
1653 let tie_even = mpfr::get_ui(&f, mpfr::rnd_t::RNDN);
1654 assert_eq!(tie_even, 20);
1655
1656 // tie away from zero, 10101 becomes 10110
1657 let dir_tie_away = mpfr_round_nearest_away!(mpfr::set_ui, &mut f, 21);
1658 assert!(dir_tie_away > 0);
1659 let tie_away = mpfr::get_ui(&f, mpfr::rnd_t::RNDN);
1660 assert_eq!(tie_away, 22);
1661
1662 // tie away from zero, 101001 becomes 101000
1663 let dir_tie_away2 = mpfr_round_nearest_away!(mpfr::set_ui, &mut f, 41);
1664 assert!(dir_tie_away2 < 0);
1665 let tie_away2 = mpfr::get_ui(&f, mpfr::rnd_t::RNDN);
1666 assert_eq!(tie_away2, 40);
1667
1668 mpfr::clear(&mut f);
1669 }
1670 }
1671
1672 #[test]
1673 fn check_decl_init() {
1674 MPFR_DECL_INIT!(f, 5);
1675 unsafe {
1676 assert_eq!(mpfr::get_prec(&f), 5);
1677 assert_ne!(mpfr::nan_p(&f), 0);
1678 assert!(mpfr::set_ui(&mut f, 0xff, mpfr::rnd_t::RNDD) < 0);
1679 assert_eq!(mpfr::nan_p(&f), 0);
1680 assert_eq!(mpfr::get_ui(&f, mpfr::rnd_t::RNDN), 0xf8);
1681 }
1682 }
1683}