Skip to main content

malachite_nz/gaussian_integer/conversion/
is_real.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::gaussian_integer::GaussianInteger;
10use malachite_base::num::conversion::traits::IsReal;
11
12impl IsReal for &GaussianInteger {
13    /// Determines whether a [`GaussianInteger`] is a real number: that is, whether its imaginary
14    /// part is zero.
15    ///
16    /// $f(x) = x \in \R$.
17    ///
18    /// # Worst-case complexity
19    /// Constant time and additional memory.
20    ///
21    /// # Examples
22    /// ```
23    /// use malachite_base::num::basic::traits::{I, One, Zero};
24    /// use malachite_base::num::conversion::traits::IsReal;
25    /// use malachite_nz::gaussian_integer::GaussianInteger;
26    ///
27    /// assert_eq!(GaussianInteger::ZERO.is_real(), true);
28    /// assert_eq!(GaussianInteger::ONE.is_real(), true);
29    /// assert_eq!(GaussianInteger::I.is_real(), false);
30    /// assert_eq!(GaussianInteger::from(-100).is_real(), true);
31    /// ```
32    #[inline]
33    fn is_real(self) -> bool {
34        self.imaginary == 0u32
35    }
36}