Skip to main content

malachite_float/float/conversion/
is_gaussian_integer.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
9use crate::Float;
10use malachite_base::num::conversion::traits::{IsGaussianInteger, IsInteger};
11
12impl IsGaussianInteger for &Float {
13    /// Determines whether a [`Float`] is a Gaussian integer.
14    ///
15    /// A [`Float`] is real (or `NaN` or infinite), so it is a Gaussian integer if and only if it is
16    /// an integer.
17    ///
18    /// $f(x) = x \in \Z\[i\]$.
19    ///
20    /// # Worst-case complexity
21    /// Constant time and additional memory.
22    ///
23    /// # Examples
24    /// ```
25    /// use malachite_base::num::basic::traits::{Infinity, NaN, One, OneHalf, Zero};
26    /// use malachite_base::num::conversion::traits::IsGaussianInteger;
27    /// use malachite_float::Float;
28    ///
29    /// assert_eq!(Float::ZERO.is_gaussian_integer(), true);
30    /// assert_eq!(Float::ONE.is_gaussian_integer(), true);
31    /// assert_eq!(Float::from(-100).is_gaussian_integer(), true);
32    /// assert_eq!(Float::ONE_HALF.is_gaussian_integer(), false);
33    /// assert_eq!(Float::NAN.is_gaussian_integer(), false);
34    /// assert_eq!(Float::INFINITY.is_gaussian_integer(), false);
35    /// ```
36    #[inline]
37    fn is_gaussian_integer(self) -> bool {
38        self.is_integer()
39    }
40}