malachite_base/num/arithmetic/ceiling.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::{Ceiling, CeilingAssign};
10
11macro_rules! impl_ceiling {
12 ($f:ident) => {
13 impl Ceiling for $f {
14 type Output = $f;
15
16 /// This is a wrapper over the `ceil` functions in [`libm`]
17 #[inline]
18 fn ceiling(self) -> $f {
19 libm::Libm::<$f>::ceil(self)
20 }
21 }
22
23 impl CeilingAssign for $f {
24 /// Replaces a number with its ceiling.
25 ///
26 /// A number's ceiling is the smallest integer greater than or equal to the number.
27 ///
28 /// $x \gets \lceil x \rceil$.
29 ///
30 /// # Worst-case complexity
31 /// Constant time and additional memory.
32 ///
33 /// # Examples
34 /// See [here](super::ceiling#ceiling_assign).
35 #[inline]
36 fn ceiling_assign(&mut self) {
37 *self = self.ceiling();
38 }
39 }
40 };
41}
42apply_to_primitive_floats!(impl_ceiling);