malachite_base/num/arithmetic/neg.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::NegAssign;
10
11macro_rules! impl_neg_signed {
12 ($t:ident) => {
13 impl NegAssign for $t {
14 /// Negates a number in place.
15 ///
16 /// Assumes that the negative can be represented.
17 ///
18 /// $x \gets -x$.
19 ///
20 /// # Worst-case complexity
21 /// Constant time and additional memory.
22 ///
23 /// # Examples
24 /// See [here](super::neg#neg_assign).
25 #[inline]
26 fn neg_assign(&mut self) {
27 *self = -*self;
28 }
29 }
30 };
31}
32apply_to_signeds!(impl_neg_signed);
33
34macro_rules! impl_neg_float {
35 ($t:ident) => {
36 impl NegAssign for $t {
37 /// Negates a number in place.
38 ///
39 /// Assumes that the negative can be represented.
40 ///
41 /// $x \gets -x$.
42 ///
43 /// # Worst-case complexity
44 /// Constant time and additional memory.
45 ///
46 /// # Examples
47 /// See [here](super::neg#neg_assign).
48 #[inline]
49 fn neg_assign(&mut self) {
50 *self = -*self;
51 }
52 }
53 };
54}
55apply_to_primitive_floats!(impl_neg_float);