malachite_nz/gaussian_integer/arithmetic/power_of_2.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 crate::integer::Integer;
11use malachite_base::num::arithmetic::traits::PowerOf2;
12
13impl PowerOf2<u64> for GaussianInteger {
14 /// Raises 2 to an integer power, producing a purely real [`GaussianInteger`].
15 ///
16 /// $f(k) = 2^k$.
17 ///
18 /// # Worst-case complexity
19 /// $T(n) = O(n)$
20 ///
21 /// $M(n) = O(n)$
22 ///
23 /// where $T$ is time, $M$ is additional memory, and $n$ is `pow`.
24 ///
25 /// # Examples
26 /// ```
27 /// use malachite_base::num::arithmetic::traits::PowerOf2;
28 /// use malachite_nz::gaussian_integer::GaussianInteger;
29 ///
30 /// assert_eq!(GaussianInteger::power_of_2(0).to_string(), "1");
31 /// assert_eq!(GaussianInteger::power_of_2(3).to_string(), "8");
32 /// assert_eq!(
33 /// GaussianInteger::power_of_2(100).to_string(),
34 /// "1267650600228229401496703205376"
35 /// );
36 /// ```
37 #[inline]
38 fn power_of_2(pow: u64) -> Self {
39 Self::from(Integer::power_of_2(pow))
40 }
41}