malachite_base/num/arithmetic/
floor.rs

1// Copyright © 2025 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
9use crate::num::arithmetic::traits::{Floor, FloorAssign};
10
11macro_rules! impl_floor {
12    ($f:ident) => {
13        impl Floor for $f {
14            type Output = $f;
15
16            /// This is a wrapper over the `floor` functions in [`libm`].
17            #[inline]
18            fn floor(self) -> $f {
19                libm::Libm::<$f>::floor(self)
20            }
21        }
22
23        impl FloorAssign for $f {
24            /// Replaces a number with its floor.
25            ///
26            /// A number's floor is the largest integer less than or equal to the number.
27            ///
28            /// $x \gets \lfloor x \rfloor$.
29            ///
30            /// # Worst-case complexity
31            /// Constant time and additional memory.
32            ///
33            /// # Examples
34            /// See [here](super::floor#floor_assign).
35            #[inline]
36            fn floor_assign(&mut self) {
37                *self = self.floor();
38            }
39        }
40    };
41}
42apply_to_primitive_floats!(impl_floor);