malachite_float/float/arithmetic/mod.rs
1// Copyright © 2026 Mikhail Hogrefe
2//
3// This file is part of Malachite.
4//
5// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
6// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
7// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
8
9/// Absolute value of [`Float`](super::Float)s.
10pub mod abs;
11/// Implementations of [`AbsSquared`](malachite_base::num::arithmetic::traits::AbsSquared) and
12/// [`AbsSquaredAssign`](malachite_base::num::arithmetic::traits::AbsSquaredAssign), traits for
13/// computing the squared absolute value of a number. For real types this is the same as squaring.
14pub mod abs_squared;
15/// Implementations of [`Acos`](malachite_base::num::arithmetic::traits::Acos) and
16/// [`AcosAssign`](malachite_base::num::arithmetic::traits::AcosAssign), traits for computing the
17/// arccosine of [`Float`](super::Float)s.
18pub mod acos;
19pub mod acot;
20pub mod acsc;
21/// Addition of [`Float`](super::Float)s, and of [`Float`](super::Float)s with
22/// [`Rational`](malachite_q::Rational)s.
23pub mod add;
24/// [`AddMul`](malachite_base::num::arithmetic::traits::AddMul) and
25/// [`AddMulAssign`](malachite_base::num::arithmetic::traits::AddMulAssign), traits for adding a
26/// [`Float`](super::Float) and the product of two other [`Float`](super::Float)s — or of a
27/// [`Float`](super::Float) and a [`Rational`](malachite_q::Rational) — with a single rounding
28/// (fused multiply-add), and the associated precision- and rounding-mode-aware functions.
29pub mod add_mul;
30/// Taking the AGM (arithmetic-geometric mean) of two [`Float`](super::Float)s, and of
31/// [`Float`](super::Float)s with [`Rational`](malachite_q::Rational)s.
32pub mod agm;
33/// Implementations of [`Asec`](malachite_base::num::arithmetic::traits::Asec) and
34/// [`AsecAssign`](malachite_base::num::arithmetic::traits::AsecAssign), traits for computing the
35/// arcsecant of [`Float`](super::Float)s.
36pub mod asec;
37/// Implementations of [`Asin`](malachite_base::num::arithmetic::traits::Asin) and
38/// [`AsinAssign`](malachite_base::num::arithmetic::traits::AsinAssign), traits for computing the
39/// arcsine of [`Float`](super::Float)s.
40pub mod asin;
41/// Implementations of [`Atan`](malachite_base::num::arithmetic::traits::Atan) and
42/// [`AtanAssign`](malachite_base::num::arithmetic::traits::AtanAssign), traits for computing the
43/// arctangent of [`Float`](super::Float)s.
44pub mod atan;
45/// Implementations of [`Atan2`](malachite_base::num::arithmetic::traits::Atan2) and
46/// [`Atan2Assign`](malachite_base::num::arithmetic::traits::Atan2Assign), traits for computing the
47/// angle of a point given by two [`Float`](super::Float) coordinates.
48pub mod atan2;
49/// [`Average`](malachite_base::num::arithmetic::traits::Average) and
50/// [`AverageAssign`](malachite_base::num::arithmetic::traits::AverageAssign), traits for computing
51/// the average (arithmetic mean) of two numbers, and the associated precision- and
52/// rounding-mode-aware functions.
53///
54/// # average
55/// ```
56/// use malachite_base::num::arithmetic::traits::Average;
57/// use malachite_float::Float;
58///
59/// assert_eq!(Float::from(1.5).average(Float::from(2.5)), 2.0);
60/// assert_eq!((&Float::from(1.5)).average(&Float::from(2.5)), 2.0);
61/// // the output precision is the maximum of the inputs', so the average of two one-bit
62/// // `Float`s is itself rounded to one bit, here to the even neighbor
63/// assert_eq!(Float::from(1.0).average(Float::from(2.0)), 2.0);
64/// // the sum would overflow, but the average is in range
65/// let max = Float::max_finite_value_with_prec(10);
66/// assert_eq!((&max).average(&max), max);
67/// ```
68///
69/// # average_assign
70/// ```
71/// use malachite_base::num::arithmetic::traits::AverageAssign;
72/// use malachite_float::Float;
73///
74/// let mut x = Float::from(1.5);
75/// x.average_assign(Float::from(2.5));
76/// assert_eq!(x, 2.0);
77/// ```
78///
79/// # average_prec_round
80/// ```
81/// use malachite_base::rounding_modes::RoundingMode::*;
82/// use malachite_float::Float;
83/// use std::cmp::Ordering::*;
84///
85/// // the exact average of 1 and 2 is 1.5, which needs 2 bits
86/// let (avg, o) = Float::from(1.0).average_prec_round(Float::from(2.0), 2, Exact);
87/// assert_eq!(avg, 1.5);
88/// assert_eq!(o, Equal);
89///
90/// // at one bit it must be rounded
91/// let (avg, o) = Float::from(1.0).average_prec_round(Float::from(2.0), 1, Floor);
92/// assert_eq!(avg, 1.0);
93/// assert_eq!(o, Less);
94/// let (avg, o) = Float::from(1.0).average_prec_round(Float::from(2.0), 1, Ceiling);
95/// assert_eq!(avg, 2.0);
96/// assert_eq!(o, Greater);
97/// ```
98///
99/// # average_prec
100/// ```
101/// use malachite_float::Float;
102/// use std::cmp::Ordering::*;
103///
104/// let (avg, o) = Float::from(1.0).average_prec(Float::from(2.0), 10);
105/// assert_eq!(avg, 1.5);
106/// assert_eq!(o, Equal);
107/// ```
108///
109/// # average_round
110/// ```
111/// use malachite_base::rounding_modes::RoundingMode::*;
112/// use malachite_float::Float;
113/// use std::cmp::Ordering::*;
114///
115/// // the output precision is the maximum of the inputs' precisions
116/// let (avg, o) = Float::from(1.5).average_round(Float::from(2.5), Nearest);
117/// assert_eq!(avg, 2.0);
118/// assert_eq!(o, Equal);
119/// ```
120///
121/// # average_prec_round_assign
122/// ```
123/// use malachite_base::rounding_modes::RoundingMode::*;
124/// use malachite_float::Float;
125/// use std::cmp::Ordering::*;
126///
127/// let mut x = Float::from(1.0);
128/// assert_eq!(
129/// x.average_prec_round_assign(Float::from(2.0), 1, Floor),
130/// Less
131/// );
132/// assert_eq!(x, 1.0);
133///
134/// let mut x = Float::from(1.0);
135/// assert_eq!(
136/// x.average_prec_round_assign_ref(&Float::from(2.0), 2, Exact),
137/// Equal
138/// );
139/// assert_eq!(x, 1.5);
140/// ```
141///
142/// # average_prec_assign
143/// ```
144/// use malachite_float::Float;
145/// use std::cmp::Ordering::*;
146///
147/// let mut x = Float::from(1.0);
148/// assert_eq!(x.average_prec_assign(Float::from(2.0), 10), Equal);
149/// assert_eq!(x, 1.5);
150///
151/// let mut x = Float::from(1.0);
152/// assert_eq!(x.average_prec_assign_ref(&Float::from(2.0), 10), Equal);
153/// assert_eq!(x, 1.5);
154/// ```
155///
156/// # average_round_assign
157/// ```
158/// use malachite_base::rounding_modes::RoundingMode::*;
159/// use malachite_float::Float;
160/// use std::cmp::Ordering::*;
161///
162/// let mut x = Float::from(1.5);
163/// assert_eq!(x.average_round_assign(Float::from(2.5), Nearest), Equal);
164/// assert_eq!(x, 2.0);
165///
166/// let mut x = Float::from(1.5);
167/// assert_eq!(
168/// x.average_round_assign_ref(&Float::from(2.5), Nearest),
169/// Equal
170/// );
171/// assert_eq!(x, 2.0);
172/// ```
173pub mod average;
174/// An implementation of
175/// [`CanonicalUnitIPow`](malachite_base::num::arithmetic::traits::CanonicalUnitIPow), a trait for
176/// finding the power of $i$ that brings a number into canonical unit form.
177pub mod canonical_unit_i_pow;
178/// Implementations of
179/// [`CanonicalizeUnit`](malachite_base::num::arithmetic::traits::CanonicalizeUnit) and
180/// [`CanonicalizeUnitAssign`](malachite_base::num::arithmetic::traits::CanonicalizeUnitAssign),
181/// traits for bringing a number into canonical unit form.
182pub mod canonicalize_unit;
183/// Cube root of [`Float`](super::Float)s and of [`Rational`](malachite_q::Rational)s.
184pub mod cbrt;
185/// [`Compound`](malachite_base::num::arithmetic::traits::Compound) and
186/// [`CompoundAssign`](malachite_base::num::arithmetic::traits::CompoundAssign), traits for
187/// computing the compound function $(1+x)^n$ for [`Float`](super::Float)s.
188pub mod compound;
189/// Implementations of [`Conjugate`](malachite_base::num::arithmetic::traits::Conjugate) and
190/// [`ConjugateAssign`](malachite_base::num::arithmetic::traits::ConjugateAssign), traits for
191/// computing the complex conjugate of a number. A real number is its own conjugate.
192pub mod conjugate;
193/// Implementations of [`Cos`](malachite_base::num::arithmetic::traits::Cos) and
194/// [`CosAssign`](malachite_base::num::arithmetic::traits::CosAssign), traits for computing the
195/// cosine of [`Float`](super::Float)s.
196pub mod cos;
197/// Implementations of [`Cot`](malachite_base::num::arithmetic::traits::Cot) and
198/// [`CotAssign`](malachite_base::num::arithmetic::traits::CotAssign), traits for computing the
199/// cotangent of [`Float`](super::Float)s.
200pub mod cot;
201/// Implementations of [`Csc`](malachite_base::num::arithmetic::traits::Csc) and
202/// [`CscAssign`](malachite_base::num::arithmetic::traits::CscAssign), traits for computing the
203/// cosecant of [`Float`](super::Float)s.
204pub mod csc;
205/// Division of [`Float`](super::Float)s, of [`Float`](super::Float)s by
206/// [`Rational`](malachite_q::Rational)s, and of [`Rational`](malachite_q::Rational)s by
207/// [`Float`](super::Float)s.
208pub mod div;
209/// Correctly-rounded dot products of [`Float`](super::Float) slices, with the products computed
210/// exactly and a single rounding at the end, so that intermediate overflow and underflow cannot
211/// occur.
212pub mod dot;
213/// [`Exp`](malachite_base::num::arithmetic::traits::Exp) and
214/// [`ExpAssign`](malachite_base::num::arithmetic::traits::ExpAssign), traits for computing $e^x$
215/// for [`Float`](super::Float)s.
216pub mod exp;
217/// [`ExpXMinus1`](malachite_base::num::arithmetic::traits::ExpXMinus1) and
218/// [`ExpXMinus1Assign`](malachite_base::num::arithmetic::traits::ExpXMinus1Assign), traits for
219/// computing $e^x-1$ for [`Float`](super::Float)s.
220pub mod exp_x_minus_1;
221/// [`factorial_prec_round`](super::Float::factorial_prec_round) and
222/// [`factorial_prec`](super::Float::factorial_prec), for computing correctly-rounded factorials.
223pub mod factorial;
224/// Fractional parts of [`Float`](super::Float)s: the `fractional_part` and
225/// `integer_and_fractional_parts` families.
226pub mod fractional_part;
227/// [`Hypot`](malachite_base::num::arithmetic::traits::Hypot) and
228/// [`HypotAssign`](malachite_base::num::arithmetic::traits::HypotAssign), traits for computing the
229/// hypotenuse of two numbers, $\sqrt{x^2+y^2}$.
230///
231/// # hypot
232/// ```
233/// use core::f64::consts::{E, PI};
234/// use malachite_base::num::arithmetic::traits::Hypot;
235/// use malachite_float::Float;
236///
237/// assert_eq!(
238/// Float::from(PI).hypot(Float::from(E)).to_string(),
239/// "4.1543544023133130"
240/// );
241/// ```
242pub mod hypot;
243/// An implementation of [`IsPowerOf2`](malachite_base::num::arithmetic::traits::IsPowerOf2), a
244/// trait for determining whether a number is an integer power of 2.
245pub mod is_power_of_2;
246/// An implementation of [`IsUnit`](malachite_base::num::arithmetic::traits::IsUnit), a trait for
247/// determining whether a number is a unit of its ring.
248pub mod is_unit;
249/// [`Ln`](malachite_base::num::arithmetic::traits::Ln) and
250/// [`LnAssign`](malachite_base::num::arithmetic::traits::LnAssign), traits for computing the
251/// natural logarithm of [`Float`](super::Float)s.
252pub mod ln;
253/// [`Ln1PlusX`](malachite_base::num::arithmetic::traits::Ln1PlusX) and
254/// [`Ln1PlusXAssign`](malachite_base::num::arithmetic::traits::Ln1PlusXAssign), traits for
255/// computing $\ln(1+x)$ for [`Float`](super::Float)s.
256pub mod ln_1_plus_x;
257/// [`LogBase`](malachite_base::num::arithmetic::traits::LogBase) and
258/// [`LogBaseAssign`](malachite_base::num::arithmetic::traits::LogBaseAssign), traits for computing
259/// the base-$b$ logarithm of [`Float`](super::Float)s for an arbitrary integer base $b>1$.
260pub mod log_base;
261/// [`LogBase10`](malachite_base::num::arithmetic::traits::LogBase10) and
262/// [`LogBase10Assign`](malachite_base::num::arithmetic::traits::LogBase10Assign), traits for
263/// computing the base-10 logarithm of [`Float`](super::Float)s.
264pub mod log_base_10;
265/// [`LogBase10Of1PlusX`](malachite_base::num::arithmetic::traits::LogBase10Of1PlusX) and
266/// [`LogBase10Of1PlusXAssign`](malachite_base::num::arithmetic::traits::LogBase10Of1PlusXAssign),
267/// traits for computing $\log_{10}(1+x)$ of [`Float`](super::Float)s.
268pub mod log_base_10_1_plus_x;
269/// [`LogBaseOf1PlusX`](malachite_base::num::arithmetic::traits::LogBaseOf1PlusX) and
270/// [`LogBaseOf1PlusXAssign`](malachite_base::num::arithmetic::traits::LogBaseOf1PlusXAssign),
271/// traits for computing $\log_b(1+x)$ of [`Float`](super::Float)s for an arbitrary integer base
272/// $b>1$.
273pub mod log_base_1_plus_x;
274/// [`LogBase2`](malachite_base::num::arithmetic::traits::LogBase2) and
275/// [`LogBase2Assign`](malachite_base::num::arithmetic::traits::LogBase2Assign), traits for
276/// computing the base-2 logarithm of [`Float`](super::Float)s.
277pub mod log_base_2;
278/// [`LogBase2Of1PlusX`](malachite_base::num::arithmetic::traits::LogBase2Of1PlusX) and
279/// [`LogBase2Of1PlusXAssign`](malachite_base::num::arithmetic::traits::LogBase2Of1PlusXAssign),
280/// traits for computing $\log_2(1+x)$ for [`Float`](super::Float)s.
281pub mod log_base_2_1_plus_x;
282/// [`LogBase`](malachite_base::num::arithmetic::traits::LogBase) and
283/// [`LogBaseAssign`](malachite_base::num::arithmetic::traits::LogBaseAssign), implemented for a
284/// [`Float`](super::Float) base, for computing $\log_b x$ of a [`Float`](super::Float) with an
285/// arbitrary [`Float`](super::Float) base.
286pub mod log_base_float_base;
287/// [`LogBaseOf1PlusX`](malachite_base::num::arithmetic::traits::LogBaseOf1PlusX) and
288/// [`LogBaseOf1PlusXAssign`](malachite_base::num::arithmetic::traits::LogBaseOf1PlusXAssign),
289/// implemented for a [`Float`](super::Float) base, for computing $\log_b(1+x)$ of a
290/// [`Float`](super::Float) with an arbitrary [`Float`](super::Float) base.
291pub mod log_base_float_base_1_plus_x;
292/// [`LogBasePowerOf2`](malachite_base::num::arithmetic::traits::LogBasePowerOf2) and
293/// [`LogBasePowerOf2Assign`](malachite_base::num::arithmetic::traits::LogBasePowerOf2Assign),
294/// traits for computing $\log_{2^k} x$ for [`Float`](super::Float)s.
295pub mod log_base_power_of_2;
296/// [`LogBasePowerOf2Of1PlusX`](malachite_base::num::arithmetic::traits::LogBasePowerOf2Of1PlusX)
297/// and
298/// [`LogBasePowerOf2Of1PlusXAssign`](malachite_base::num::arithmetic::traits::LogBasePowerOf2Of1PlusXAssign),
299/// traits for computing $\log_{2^k}(1+x)$ for [`Float`](super::Float)s.
300#[cfg_attr(dylint_lib = "malachite_lints", expect(long_lines))]
301pub mod log_base_power_of_2_1_plus_x;
302/// [`LogBase`](malachite_base::num::arithmetic::traits::LogBase) and
303/// [`LogBaseAssign`](malachite_base::num::arithmetic::traits::LogBaseAssign), implemented for a
304/// [`Rational`](malachite_q::Rational) base, for computing $\log_b x$ of a [`Float`](super::Float)
305/// with an arbitrary rational base $b>1$.
306pub mod log_base_rational_base;
307/// [`LogBaseOf1PlusX`](malachite_base::num::arithmetic::traits::LogBaseOf1PlusX) and
308/// [`LogBaseOf1PlusXAssign`](malachite_base::num::arithmetic::traits::LogBaseOf1PlusXAssign),
309/// implemented for a [`Rational`](malachite_q::Rational) base, for computing $\log_b(1+x)$ of a
310/// [`Float`](super::Float) with an arbitrary rational base $b>1$.
311pub mod log_base_rational_base_1_plus_x;
312/// Functions for computing $\log_b x$ of a [`Rational`](malachite_q::Rational) $x$ with an
313/// arbitrary [`Float`](super::Float) base, returning a [`Float`](super::Float).
314pub mod log_base_rational_float_base;
315/// Functions for computing $\log_b x$ of a [`Rational`](malachite_q::Rational) $x$ with an
316/// arbitrary [`Rational`](malachite_q::Rational) base $b>1$, returning a [`Float`](super::Float).
317pub mod log_base_rational_rational_base;
318/// Multiplication of [`Float`](super::Float)s, and of [`Float`](super::Float)s with
319/// [`Rational`](malachite_q::Rational)s.
320pub mod mul;
321/// [`MulAddMul`](malachite_base::num::arithmetic::traits::MulAddMul) and
322/// [`MulAddMulAssign`](malachite_base::num::arithmetic::traits::MulAddMulAssign), traits for adding
323/// the products of two pairs of [`Float`](super::Float)s with a single rounding, and the associated
324/// precision- and rounding-mode-aware functions.
325pub mod mul_add_mul;
326/// [`MulSubMul`](malachite_base::num::arithmetic::traits::MulSubMul) and
327/// [`MulSubMulAssign`](malachite_base::num::arithmetic::traits::MulSubMulAssign), traits for
328/// subtracting the product of one pair of [`Float`](super::Float)s from the product of another pair
329/// with a single rounding, and the associated precision- and rounding-mode-aware functions.
330pub mod mul_sub_mul;
331/// Negation of [`Float`](super::Float)s.
332pub mod neg;
333/// [`positive_difference_prec_round`](super::Float::positive_difference_prec_round) and related
334/// functions, for computing positive differences of [`Float`](super::Float)s.
335pub mod positive_difference;
336/// Implementations of [`PowerOf2`](malachite_base::num::arithmetic::traits::PowerOf2), a trait for
337/// computing a power of 2.
338pub mod pow;
339/// An implementation of [`PowerOf2`](malachite_base::num::arithmetic::traits::PowerOf2) with a
340/// [`Float`](super::Float) exponent, computing $2^x$ for [`Float`](super::Float)s.
341pub mod power_of_10;
342pub mod power_of_10_x_minus_1;
343pub mod power_of_2;
344pub mod power_of_2_of_float;
345/// Implementations of [`PowerOf2XMinus1`](malachite_base::num::arithmetic::traits::PowerOf2XMinus1)
346/// and [`PowerOf2XMinus1Assign`](malachite_base::num::arithmetic::traits::PowerOf2XMinus1Assign),
347/// traits for computing $2^x-1$.
348pub mod power_of_2_x_minus_1;
349/// Correctly-rounded multiplication of any number of [`Float`](super::Float)s: functions computing
350/// a slice's product with a single rounding at the end, and the [`Product`](core::iter::Product)
351/// implementations built on them.
352pub mod product;
353/// Implementations of [`Reciprocal`](malachite_base::num::arithmetic::traits::Reciprocal) and
354/// [`ReciprocalAssign`](malachite_base::num::arithmetic::traits::ReciprocalAssign), traits for
355/// computing the reciprocal of a number.
356pub mod reciprocal;
357/// [`ReciprocalSqrt`](malachite_base::num::arithmetic::traits::ReciprocalSqrt) and
358/// [`ReciprocalSqrtAssign`](malachite_base::num::arithmetic::traits::ReciprocalSqrtAssign), traits
359/// for computing the reciprocal of the square root of [`Float`](super::Float)s.
360pub mod reciprocal_sqrt;
361/// [`rem_prec_round`](super::Float::rem_prec_round) and related functions, for computing
362/// floating-point remainders of [`Float`](super::Float)s.
363pub mod rem;
364/// [`root_u_prec_round`](super::Float::root_u_prec_round) and related functions, for computing
365/// roots of [`Float`](super::Float)s.
366pub mod root;
367pub(crate) mod round_near_x;
368pub mod round_to_integer;
369/// Implementations of [`Sec`](malachite_base::num::arithmetic::traits::Sec) and
370/// [`SecAssign`](malachite_base::num::arithmetic::traits::SecAssign), traits for computing the
371/// secant of [`Float`](super::Float)s.
372pub mod sec;
373/// Left-shifting a [`Float`](super::Float) (multiplying it by a power of 2).
374///
375/// # shl
376/// ```
377/// use malachite_base::num::basic::traits::{Infinity, Zero};
378/// use malachite_float::Float;
379///
380/// assert_eq!(Float::ZERO << 10, 0);
381/// assert_eq!(Float::INFINITY << 10, Float::INFINITY);
382/// assert_eq!(
383/// (Float::from(std::f64::consts::PI) << 10u8).to_string(),
384/// "3216.9908772759482"
385/// );
386/// assert_eq!(
387/// (Float::from(std::f64::consts::PI) << -10i8).to_string(),
388/// "0.0030679615757712823"
389/// );
390///
391/// assert_eq!(&Float::ZERO << 10, 0);
392/// assert_eq!(&Float::INFINITY << 10, Float::INFINITY);
393/// assert_eq!(
394/// (&Float::from(std::f64::consts::PI) << 10u8).to_string(),
395/// "3216.9908772759482"
396/// );
397/// assert_eq!(
398/// (&Float::from(std::f64::consts::PI) << -10i8).to_string(),
399/// "0.0030679615757712823"
400/// );
401/// ```
402///
403/// # shl_assign
404/// ```
405/// use malachite_base::num::basic::traits::{Infinity, Zero};
406/// use malachite_float::Float;
407///
408/// let mut x = Float::ZERO;
409/// x <<= 10;
410/// assert_eq!(x, 0);
411///
412/// let mut x = Float::INFINITY;
413/// x <<= 10;
414/// assert_eq!(x, Float::INFINITY);
415///
416/// let mut x = Float::from(std::f64::consts::PI);
417/// x <<= 10;
418/// assert_eq!(x.to_string(), "3216.9908772759482");
419///
420/// let mut x = Float::from(std::f64::consts::PI);
421/// x <<= -10;
422/// assert_eq!(x.to_string(), "0.0030679615757712823");
423/// ```
424pub mod shl;
425/// Implementations of [`ShlRound`](malachite_base::num::arithmetic::traits::ShlRound) and
426/// [`ShlRoundAssign`](malachite_base::num::arithmetic::traits::ShlRoundAssign), traits for
427/// multiplying a number by a power of 2 and rounding according to a specified
428/// [`RoundingMode`](malachite_base::rounding_modes::RoundingMode). For [`Float`](super::Float)s,
429/// rounding is only necessary in the cases of overflow and underflow.
430///
431/// # shl_prec_round
432/// ```
433/// use malachite_base::rounding_modes::RoundingMode::*;
434/// use malachite_float::Float;
435/// use std::cmp::Ordering::*;
436///
437/// let (shifted, o) = Float::from(std::f64::consts::PI).shl_prec_round(10u8, 10, Nearest);
438/// assert_eq!(shifted.to_string(), "3216.0");
439/// assert_eq!(o, Less);
440///
441/// let (shifted, o) = Float::from(std::f64::consts::PI).shl_prec_round(-10i8, 10, Nearest);
442/// assert_eq!(shifted.to_string(), "0.0030670");
443/// assert_eq!(o, Less);
444///
445/// let (shifted, o) = Float::from(std::f64::consts::PI).shl_prec_round(u32::MAX, 10, Floor);
446/// assert_eq!(shifted.to_string(), "2.0965e323228496");
447/// assert_eq!(o, Less);
448///
449/// let (shifted, o) = Float::from(std::f64::consts::PI).shl_prec_round(u32::MAX, 10, Ceiling);
450/// assert_eq!(shifted.to_string(), "Infinity");
451/// assert_eq!(o, Greater);
452///
453/// let (shifted, o) = Float::from(std::f64::consts::PI).shl_prec_round_ref(10u8, 10, Nearest);
454/// assert_eq!(shifted.to_string(), "3216.0");
455/// assert_eq!(o, Less);
456///
457/// let (shifted, o) = Float::from(std::f64::consts::PI).shl_prec_round_ref(-10i8, 10, Nearest);
458/// assert_eq!(shifted.to_string(), "0.0030670");
459/// assert_eq!(o, Less);
460///
461/// let (shifted, o) = Float::from(std::f64::consts::PI).shl_prec_round_ref(u32::MAX, 10, Floor);
462/// assert_eq!(shifted.to_string(), "2.0965e323228496");
463/// assert_eq!(o, Less);
464///
465/// let (shifted, o) = Float::from(std::f64::consts::PI).shl_prec_round_ref(u32::MAX, 10, Ceiling);
466/// assert_eq!(shifted.to_string(), "Infinity");
467/// assert_eq!(o, Greater);
468/// ```
469///
470/// # shl_prec_round_assign
471/// ```
472/// use malachite_base::rounding_modes::RoundingMode::*;
473/// use malachite_float::Float;
474/// use std::cmp::Ordering::*;
475///
476/// let mut x = Float::from(std::f64::consts::PI);
477/// assert_eq!(x.shl_prec_round_assign(10u8, 10, Nearest), Less);
478/// assert_eq!(x.to_string(), "3216.0");
479///
480/// let mut x = Float::from(std::f64::consts::PI);
481/// assert_eq!(x.shl_prec_round_assign(-10i8, 10, Nearest), Less);
482/// assert_eq!(x.to_string(), "0.0030670");
483///
484/// let mut x = Float::from(std::f64::consts::PI);
485/// assert_eq!(x.shl_prec_round_assign(u32::MAX, 10, Floor), Less);
486/// assert_eq!(x.to_string(), "2.0965e323228496");
487///
488/// let mut x = Float::from(std::f64::consts::PI);
489/// assert_eq!(x.shl_prec_round_assign(u32::MAX, 10, Ceiling), Greater);
490/// assert_eq!(x.to_string(), "Infinity");
491/// ```
492///
493/// # shl_prec
494/// ```
495/// use malachite_float::Float;
496/// use std::cmp::Ordering::*;
497///
498/// let (shifted, o) = Float::from(std::f64::consts::PI).shl_prec(10u8, 10);
499/// assert_eq!(shifted.to_string(), "3216.0");
500/// assert_eq!(o, Less);
501///
502/// let (shifted, o) = Float::from(std::f64::consts::PI).shl_prec(-10i8, 10);
503/// assert_eq!(shifted.to_string(), "0.0030670");
504/// assert_eq!(o, Less);
505///
506/// let (shifted, o) = Float::from(std::f64::consts::PI).shl_prec(u32::MAX, 10);
507/// assert_eq!(shifted.to_string(), "Infinity");
508/// assert_eq!(o, Greater);
509///
510/// let (shifted, o) = Float::from(std::f64::consts::PI).shl_prec_ref(10u8, 10);
511/// assert_eq!(shifted.to_string(), "3216.0");
512/// assert_eq!(o, Less);
513///
514/// let (shifted, o) = Float::from(std::f64::consts::PI).shl_prec_ref(-10i8, 10);
515/// assert_eq!(shifted.to_string(), "0.0030670");
516/// assert_eq!(o, Less);
517///
518/// let (shifted, o) = Float::from(std::f64::consts::PI).shl_prec_ref(u32::MAX, 10);
519/// assert_eq!(shifted.to_string(), "Infinity");
520/// assert_eq!(o, Greater);
521/// ```
522///
523/// # shl_prec_assign
524/// ```
525/// use malachite_float::Float;
526/// use std::cmp::Ordering::*;
527///
528/// let mut x = Float::from(std::f64::consts::PI);
529/// assert_eq!(x.shl_prec_assign(10u8, 10), Less);
530/// assert_eq!(x.to_string(), "3216.0");
531///
532/// let mut x = Float::from(std::f64::consts::PI);
533/// assert_eq!(x.shl_prec_assign(-10i8, 10), Less);
534/// assert_eq!(x.to_string(), "0.0030670");
535///
536/// let mut x = Float::from(std::f64::consts::PI);
537/// assert_eq!(x.shl_prec_assign(u32::MAX, 10), Greater);
538/// assert_eq!(x.to_string(), "Infinity");
539/// ```
540///
541/// # shl_round
542/// ```
543/// use malachite_base::num::arithmetic::traits::ShlRound;
544/// use malachite_base::rounding_modes::RoundingMode::*;
545/// use malachite_float::Float;
546/// use std::cmp::Ordering::*;
547///
548/// let (shifted, o) = Float::from(std::f64::consts::PI).shl_round(10u8, Nearest);
549/// assert_eq!(shifted.to_string(), "3216.9908772759482");
550/// assert_eq!(o, Equal);
551///
552/// let (shifted, o) = Float::from(std::f64::consts::PI).shl_round(-10i8, Nearest);
553/// assert_eq!(shifted.to_string(), "0.0030679615757712823");
554/// assert_eq!(o, Equal);
555///
556/// let (shifted, o) = Float::from(std::f64::consts::PI).shl_round(u32::MAX, Floor);
557/// assert_eq!(shifted.to_string(), "2.0985787164673858e323228496");
558/// assert_eq!(o, Less);
559///
560/// let (shifted, o) = Float::from(std::f64::consts::PI).shl_round(u32::MAX, Ceiling);
561/// assert_eq!(shifted.to_string(), "Infinity");
562/// assert_eq!(o, Greater);
563///
564/// let (shifted, o) = (&Float::from(std::f64::consts::PI)).shl_round(10u8, Nearest);
565/// assert_eq!(shifted.to_string(), "3216.9908772759482");
566/// assert_eq!(o, Equal);
567///
568/// let (shifted, o) = (&Float::from(std::f64::consts::PI)).shl_round(-10i8, Nearest);
569/// assert_eq!(shifted.to_string(), "0.0030679615757712823");
570/// assert_eq!(o, Equal);
571///
572/// let (shifted, o) = (&Float::from(std::f64::consts::PI)).shl_round(u32::MAX, Floor);
573/// assert_eq!(shifted.to_string(), "2.0985787164673858e323228496");
574/// assert_eq!(o, Less);
575///
576/// let (shifted, o) = (&Float::from(std::f64::consts::PI)).shl_round(u32::MAX, Ceiling);
577/// assert_eq!(shifted.to_string(), "Infinity");
578/// assert_eq!(o, Greater);
579/// ```
580///
581/// # shl_round_assign
582/// ```
583/// use malachite_base::num::arithmetic::traits::ShlRoundAssign;
584/// use malachite_base::rounding_modes::RoundingMode::*;
585/// use malachite_float::Float;
586/// use std::cmp::Ordering::*;
587///
588/// let mut x = Float::from(std::f64::consts::PI);
589/// assert_eq!(x.shl_round_assign(10u8, Nearest), Equal);
590/// assert_eq!(x.to_string(), "3216.9908772759482");
591///
592/// let mut x = Float::from(std::f64::consts::PI);
593/// assert_eq!(x.shl_round_assign(-10i8, Nearest), Equal);
594/// assert_eq!(x.to_string(), "0.0030679615757712823");
595///
596/// let mut x = Float::from(std::f64::consts::PI);
597/// assert_eq!(x.shl_round_assign(u32::MAX, Floor), Less);
598/// assert_eq!(x.to_string(), "2.0985787164673858e323228496");
599///
600/// let mut x = Float::from(std::f64::consts::PI);
601/// assert_eq!(x.shl_round_assign(u32::MAX, Ceiling), Greater);
602/// assert_eq!(x.to_string(), "Infinity");
603/// ```
604pub mod shl_round;
605/// Right-shifting a [`Float`](super::Float) (dividing it by a power of 2).
606///
607/// # shr
608/// ```
609/// use malachite_base::num::basic::traits::{Infinity, Zero};
610/// use malachite_float::Float;
611///
612/// assert_eq!(Float::ZERO >> 10, 0);
613/// assert_eq!(Float::INFINITY >> 10, Float::INFINITY);
614/// assert_eq!(
615/// (Float::from(std::f64::consts::PI) >> 10u8).to_string(),
616/// "0.0030679615757712823"
617/// );
618/// assert_eq!(
619/// (Float::from(std::f64::consts::PI) >> -10i8).to_string(),
620/// "3216.9908772759482"
621/// );
622///
623/// assert_eq!(&Float::ZERO >> 10, 0);
624/// assert_eq!(&Float::INFINITY >> 10, Float::INFINITY);
625/// assert_eq!(
626/// (&Float::from(std::f64::consts::PI) >> 10u8).to_string(),
627/// "0.0030679615757712823"
628/// );
629/// assert_eq!(
630/// (&Float::from(std::f64::consts::PI) >> -10i8).to_string(),
631/// "3216.9908772759482"
632/// );
633/// ```
634///
635/// # shr_assign
636/// ```
637/// use malachite_base::num::basic::traits::{Infinity, Zero};
638/// use malachite_float::Float;
639///
640/// let mut x = Float::ZERO;
641/// x >>= 10;
642/// assert_eq!(x, 0);
643///
644/// let mut x = Float::INFINITY;
645/// x >>= 10;
646/// assert_eq!(x, Float::INFINITY);
647///
648/// let mut x = Float::from(std::f64::consts::PI);
649/// x >>= 10;
650/// assert_eq!(x.to_string(), "0.0030679615757712823");
651///
652/// let mut x = Float::from(std::f64::consts::PI);
653/// x >>= -10;
654/// assert_eq!(x.to_string(), "3216.9908772759482");
655/// ```
656pub mod shr;
657/// Implementations of [`ShlRound`](malachite_base::num::arithmetic::traits::ShrRound) and
658/// [`ShrRoundAssign`](malachite_base::num::arithmetic::traits::ShrRoundAssign), traits for dividing
659/// a number by a power of 2 and rounding according to a specified
660/// [`RoundingMode`](malachite_base::rounding_modes::RoundingMode). For [`Float`](super::Float)s,
661/// rounding is only necessary in the cases of overflow and underflow.
662///
663/// # shr_prec_round
664/// ```
665/// use malachite_base::rounding_modes::RoundingMode::*;
666/// use malachite_float::Float;
667/// use std::cmp::Ordering::*;
668///
669/// let (shifted, o) = Float::from(std::f64::consts::PI).shr_prec_round(10u8, 10, Nearest);
670/// assert_eq!(shifted.to_string(), "0.0030670");
671/// assert_eq!(o, Less);
672///
673/// let (shifted, o) = Float::from(std::f64::consts::PI).shr_prec_round(-10i8, 10, Nearest);
674/// assert_eq!(shifted.to_string(), "3216.0");
675/// assert_eq!(o, Less);
676///
677/// let (shifted, o) = Float::from(std::f64::consts::PI).shr_prec_round(u32::MAX, 10, Floor);
678/// assert_eq!(shifted.to_string(), "0.0");
679/// assert_eq!(o, Less);
680///
681/// let (shifted, o) = Float::from(std::f64::consts::PI).shr_prec_round(u32::MAX, 10, Ceiling);
682/// assert_eq!(shifted.to_string(), "2.3826e-323228497");
683/// assert_eq!(o, Greater);
684///
685/// let (shifted, o) = Float::from(std::f64::consts::PI).shr_prec_round_ref(10u8, 10, Nearest);
686/// assert_eq!(shifted.to_string(), "0.0030670");
687/// assert_eq!(o, Less);
688///
689/// let (shifted, o) = Float::from(std::f64::consts::PI).shr_prec_round_ref(-10i8, 10, Nearest);
690/// assert_eq!(shifted.to_string(), "3216.0");
691/// assert_eq!(o, Less);
692///
693/// let (shifted, o) = Float::from(std::f64::consts::PI).shr_prec_round_ref(u32::MAX, 10, Floor);
694/// assert_eq!(shifted.to_string(), "0.0");
695/// assert_eq!(o, Less);
696///
697/// let (shifted, o) = Float::from(std::f64::consts::PI).shr_prec_round_ref(u32::MAX, 10, Ceiling);
698/// assert_eq!(shifted.to_string(), "2.3826e-323228497");
699/// assert_eq!(o, Greater);
700/// ```
701///
702/// # shr_prec_round_assign
703/// ```
704/// use malachite_base::rounding_modes::RoundingMode::*;
705/// use malachite_float::Float;
706/// use std::cmp::Ordering::*;
707///
708/// let mut x = Float::from(std::f64::consts::PI);
709/// assert_eq!(x.shr_prec_round_assign(10u8, 10, Nearest), Less);
710/// assert_eq!(x.to_string(), "0.0030670");
711///
712/// let mut x = Float::from(std::f64::consts::PI);
713/// assert_eq!(x.shr_prec_round_assign(-10i8, 10, Nearest), Less);
714/// assert_eq!(x.to_string(), "3216.0");
715///
716/// let mut x = Float::from(std::f64::consts::PI);
717/// assert_eq!(x.shr_prec_round_assign(u32::MAX, 10, Floor), Less);
718/// assert_eq!(x.to_string(), "0.0");
719///
720/// let mut x = Float::from(std::f64::consts::PI);
721/// assert_eq!(x.shr_prec_round_assign(u32::MAX, 10, Ceiling), Greater);
722/// assert_eq!(x.to_string(), "2.3826e-323228497");
723/// ```
724///
725/// # shr_prec
726/// ```
727/// use malachite_float::Float;
728/// use std::cmp::Ordering::*;
729///
730/// let (shifted, o) = Float::from(std::f64::consts::PI).shr_prec(10u8, 10);
731/// assert_eq!(shifted.to_string(), "0.0030670");
732/// assert_eq!(o, Less);
733///
734/// let (shifted, o) = Float::from(std::f64::consts::PI).shr_prec(-10i8, 10);
735/// assert_eq!(shifted.to_string(), "3216.0");
736/// assert_eq!(o, Less);
737///
738/// let (shifted, o) = Float::from(std::f64::consts::PI).shr_prec(u32::MAX, 10);
739/// assert_eq!(shifted.to_string(), "0.0");
740/// assert_eq!(o, Less);
741///
742/// let (shifted, o) = Float::from(std::f64::consts::PI).shr_prec_ref(10u8, 10);
743/// assert_eq!(shifted.to_string(), "0.0030670");
744/// assert_eq!(o, Less);
745///
746/// let (shifted, o) = Float::from(std::f64::consts::PI).shr_prec_ref(-10i8, 10);
747/// assert_eq!(shifted.to_string(), "3216.0");
748/// assert_eq!(o, Less);
749///
750/// let (shifted, o) = Float::from(std::f64::consts::PI).shr_prec_ref(u32::MAX, 10);
751/// assert_eq!(shifted.to_string(), "0.0");
752/// assert_eq!(o, Less);
753/// ```
754///
755/// # shr_prec_assign
756/// ```
757/// use malachite_float::Float;
758/// use std::cmp::Ordering::*;
759///
760/// let mut x = Float::from(std::f64::consts::PI);
761/// assert_eq!(x.shr_prec_assign(10u8, 10), Less);
762/// assert_eq!(x.to_string(), "0.0030670");
763///
764/// let mut x = Float::from(std::f64::consts::PI);
765/// assert_eq!(x.shr_prec_assign(-10i8, 10), Less);
766/// assert_eq!(x.to_string(), "3216.0");
767///
768/// let mut x = Float::from(std::f64::consts::PI);
769/// assert_eq!(x.shr_prec_assign(u32::MAX, 10), Less);
770/// assert_eq!(x.to_string(), "0.0");
771/// ```
772///
773/// # shr_round
774/// ```
775/// use malachite_base::num::arithmetic::traits::ShrRound;
776/// use malachite_base::rounding_modes::RoundingMode::*;
777/// use malachite_float::Float;
778/// use std::cmp::Ordering::*;
779///
780/// let (shifted, o) = Float::from(std::f64::consts::PI).shr_round(10u8, Nearest);
781/// assert_eq!(shifted.to_string(), "0.0030679615757712823");
782/// assert_eq!(o, Equal);
783///
784/// let (shifted, o) = Float::from(std::f64::consts::PI).shr_round(-10i8, Nearest);
785/// assert_eq!(shifted.to_string(), "3216.9908772759482");
786/// assert_eq!(o, Equal);
787///
788/// let (shifted, o) = Float::from(std::f64::consts::PI).shr_round(u32::MAX, Floor);
789/// assert_eq!(shifted.to_string(), "0.0");
790/// assert_eq!(o, Less);
791///
792/// let (shifted, o) = Float::from(std::f64::consts::PI).shr_round(u32::MAX, Ceiling);
793/// assert_eq!(shifted.to_string(), "2.3825649048879511e-323228497");
794/// assert_eq!(o, Greater);
795///
796/// let (shifted, o) = (&Float::from(std::f64::consts::PI)).shr_round(10u8, Nearest);
797/// assert_eq!(shifted.to_string(), "0.0030679615757712823");
798/// assert_eq!(o, Equal);
799///
800/// let (shifted, o) = (&Float::from(std::f64::consts::PI)).shr_round(-10i8, Nearest);
801/// assert_eq!(shifted.to_string(), "3216.9908772759482");
802/// assert_eq!(o, Equal);
803///
804/// let (shifted, o) = (&Float::from(std::f64::consts::PI)).shr_round(u32::MAX, Floor);
805/// assert_eq!(shifted.to_string(), "0.0");
806/// assert_eq!(o, Less);
807///
808/// let (shifted, o) = (&Float::from(std::f64::consts::PI)).shr_round(u32::MAX, Ceiling);
809/// assert_eq!(shifted.to_string(), "2.3825649048879511e-323228497");
810/// assert_eq!(o, Greater);
811/// ```
812///
813/// # shr_round_assign
814/// ```
815/// use malachite_base::num::arithmetic::traits::ShrRoundAssign;
816/// use malachite_base::rounding_modes::RoundingMode::*;
817/// use malachite_float::Float;
818/// use std::cmp::Ordering::*;
819///
820/// let mut x = Float::from(std::f64::consts::PI);
821/// assert_eq!(x.shr_round_assign(10u8, Nearest), Equal);
822/// assert_eq!(x.to_string(), "0.0030679615757712823");
823///
824/// let mut x = Float::from(std::f64::consts::PI);
825/// assert_eq!(x.shr_round_assign(-10i8, Nearest), Equal);
826/// assert_eq!(x.to_string(), "3216.9908772759482");
827///
828/// let mut x = Float::from(std::f64::consts::PI);
829/// assert_eq!(x.shr_round_assign(u32::MAX, Floor), Less);
830/// assert_eq!(x.to_string(), "0.0");
831///
832/// let mut x = Float::from(std::f64::consts::PI);
833/// assert_eq!(x.shr_round_assign(u32::MAX, Ceiling), Greater);
834/// assert_eq!(x.to_string(), "2.3825649048879511e-323228497");
835/// ```
836pub mod shr_round;
837/// An implementation of [`Sign`](malachite_base::num::arithmetic::traits::Sign), a trait for
838/// determining the sign of a number.
839pub mod sign;
840/// Implementations of [`Sin`](malachite_base::num::arithmetic::traits::Sin) and
841/// [`SinAssign`](malachite_base::num::arithmetic::traits::SinAssign), traits for computing the sine
842/// of [`Float`](super::Float)s.
843pub mod sin;
844/// Implementations of [`SinCos`](malachite_base::num::arithmetic::traits::SinCos) and
845/// [`SinCosAssign`](malachite_base::num::arithmetic::traits::SinCosAssign), traits for computing
846/// the sine and cosine of [`Float`](super::Float)s together.
847pub mod sin_cos;
848/// [`Sqrt`](malachite_base::num::arithmetic::traits::Sqrt) and
849/// [`SqrtAssign`](malachite_base::num::arithmetic::traits::SqrtAssign), traits for computing the
850/// square root of [`Float`](super::Float)s.
851pub mod sqrt;
852/// Squaring of [`Float`](super::Float)s.
853pub mod square;
854/// Subtraction of [`Float`](super::Float)s, of [`Float`](super::Float)s by
855/// [`Rational`](malachite_q::Rational)s, and of [`Rational`](malachite_q::Rational)s by
856/// [`Float`](super::Float)s.
857pub mod sub;
858/// [`SubMul`](malachite_base::num::arithmetic::traits::SubMul) and
859/// [`SubMulAssign`](malachite_base::num::arithmetic::traits::SubMulAssign), traits for subtracting
860/// the product of two [`Float`](super::Float)s — or of a [`Float`](super::Float) and a
861/// [`Rational`](malachite_q::Rational) — from another [`Float`](super::Float) with a single
862/// rounding (fused multiply-subtract), and the associated precision- and rounding-mode-aware
863/// functions.
864pub mod sub_mul;
865/// Correctly-rounded summation of any number of [`Float`](super::Float)s: functions computing a
866/// slice's sum with a single rounding at the end, and the [`Sum`](core::iter::Sum) implementations
867/// built on them.
868pub mod sum;
869pub mod tan;