// Copyright © 2016–2023 Trevor Spiteri
// This program is free software: you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option) any
// later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License and
// a copy of the GNU General Public License along with this program. If not, see
// <https://www.gnu.org/licenses/>.
/*!
Multi-precision floating-point numbers with correct rounding.
This module provides support for floating-point numbers of type
[`Float`][crate::Float].
*/
pub
pub
pub
pub
pub use crate ParseFloatError;
pub use crate BorrowFloat;
pub use crate OrdFloat;
pub use crate;
use SaturatingCast;
use mpfr;
use prec_t;
/**
Returns the minimum value for the exponent.
# Examples
```rust
use rug::float;
println!("Minimum exponent is {}", float::exp_min());
```
*/
/**
Returns the maximum value for the exponent.
# Examples
```rust
use rug::float;
println!("Maximum exponent is {}", float::exp_max());
```
*/
/**
Returns the maximum allowed range for the exponent.
# Examples
```rust
use rug::float;
let (min, max) = float::allowed_exp_range();
println!("Minimum and maximum exponents are in [{}, {}]", min, max);
```
*/
/**
Returns the minimum value for the precision.
# Examples
```rust
use rug::float;
println!("Minimum precision is {}", float::prec_min());
```
*/
pub const
/**
Returns the maximum value for the precision.
# Examples
```rust
use rug::float;
println!("Maximum precision is {}", float::prec_max());
```
*/
pub const
/**
The rounding methods for floating-point values.
When rounding to the nearest, if the number to be rounded is exactly between two
representable numbers, it is rounded to the even one, that is, the one with the
least significant bit set to zero.
# Examples
```rust
use rug::float::Round;
use rug::ops::AssignRound;
use rug::Float;
let mut f4 = Float::new(4);
f4.assign_round(10.4, Round::Nearest);
assert_eq!(f4, 10);
f4.assign_round(10.6, Round::Nearest);
assert_eq!(f4, 11);
f4.assign_round(-10.7, Round::Zero);
assert_eq!(f4, -10);
f4.assign_round(10.3, Round::Up);
assert_eq!(f4, 11);
```
Rounding to the nearest will round numbers exactly between two representable
numbers to the even one.
```rust
use rug::float::Round;
use rug::ops::AssignRound;
use rug::Float;
// 24 is 11000 in binary
// 25 is 11001 in binary
// 26 is 11010 in binary
// 27 is 11011 in binary
// 28 is 11100 in binary
let mut f4 = Float::new(4);
f4.assign_round(25, Round::Nearest);
assert_eq!(f4, 24);
f4.assign_round(27, Round::Nearest);
assert_eq!(f4, 28);
```
*/
/**
The available floating-point constants.
# Examples
```rust
use rug::float::Constant;
use rug::Float;
let log2 = Float::with_val(53, Constant::Log2);
let pi = Float::with_val(53, Constant::Pi);
let euler = Float::with_val(53, Constant::Euler);
let catalan = Float::with_val(53, Constant::Catalan);
assert_eq!(log2.to_string_radix(10, Some(5)), "6.9315e-1");
assert_eq!(pi.to_string_radix(10, Some(5)), "3.1416");
assert_eq!(euler.to_string_radix(10, Some(5)), "5.7722e-1");
assert_eq!(catalan.to_string_radix(10, Some(5)), "9.1597e-1");
```
*/
/**
Special floating-point values.
# Examples
```rust
use rug::float::Special;
use rug::Float;
let zero = Float::with_val(53, Special::Zero);
let neg_zero = Float::with_val(53, Special::NegZero);
let infinity = Float::with_val(53, Special::Infinity);
let neg_infinity = Float::with_val(53, Special::NegInfinity);
let nan = Float::with_val(53, Special::Nan);
assert_eq!(zero, 0);
assert!(zero.is_sign_positive());
assert_eq!(neg_zero, 0);
assert!(neg_zero.is_sign_negative());
assert!(infinity.is_infinite());
assert!(infinity.is_sign_positive());
assert!(neg_infinity.is_infinite());
assert!(neg_infinity.is_sign_negative());
assert!(nan.is_nan());
```
*/
/**
Specifies which cache to free.
# Examples
```rust
use rug::float;
use rug::float::FreeCache;
use std::thread;
fn main() {
let child = thread::spawn(move || {
// some work here that uses Float
float::free_cache(FreeCache::Local);
});
// some work here
child.join().expect("couldn't join thread");
float::free_cache(FreeCache::All);
}
```
*/
/**
Frees various caches and memory pools that are used internally.
To avoid memory leaks being reported when using tools like [Valgrind], it is
advisable to free thread-local caches before terminating a thread and all caches
before exiting.
# Examples
```rust
use rug::float;
use rug::float::FreeCache;
use std::thread;
fn main() {
let child = thread::spawn(move || {
// some work here that uses Float
float::free_cache(FreeCache::Local);
});
// some work here
child.join().expect("couldn't join thread");
float::free_cache(FreeCache::All);
}
```
[Valgrind]: https://www.valgrind.org/
*/