1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
15 #[allow(unused_macros)]
16 macro_rules
! sh_impl_signed
{
17 ($t
:ident
, $f
:ident
) => (
18 #[stable(feature = "rust1", since = "1.0.0")]
19 impl Shl
<$f
> for Wrapping
<$t
> {
20 type Output
= Wrapping
<$t
>;
23 fn shl(self, other
: $f
) -> Wrapping
<$t
> {
25 Wrapping(self.0.wrapping_shr((-other
& self::shift_max
::$t
as $f
) as u32))
27 Wrapping(self.0.wrapping_shl((other
& self::shift_max
::$t
as $f
) as u32))
32 #[stable(feature = "op_assign_traits", since = "1.8.0")]
33 impl ShlAssign
<$f
> for Wrapping
<$t
> {
35 fn shl_assign(&mut self, other
: $f
) {
36 *self = *self << other
;
40 #[stable(feature = "rust1", since = "1.0.0")]
41 impl Shr
<$f
> for Wrapping
<$t
> {
42 type Output
= Wrapping
<$t
>;
45 fn shr(self, other
: $f
) -> Wrapping
<$t
> {
47 Wrapping(self.0.wrapping_shl((-other
& self::shift_max
::$t
as $f
) as u32))
49 Wrapping(self.0.wrapping_shr((other
& self::shift_max
::$t
as $f
) as u32))
54 #[stable(feature = "op_assign_traits", since = "1.8.0")]
55 impl ShrAssign
<$f
> for Wrapping
<$t
> {
57 fn shr_assign(&mut self, other
: $f
) {
58 *self = *self >> other
;
64 macro_rules
! sh_impl_unsigned
{
65 ($t
:ident
, $f
:ident
) => (
66 #[stable(feature = "rust1", since = "1.0.0")]
67 impl Shl
<$f
> for Wrapping
<$t
> {
68 type Output
= Wrapping
<$t
>;
71 fn shl(self, other
: $f
) -> Wrapping
<$t
> {
72 Wrapping(self.0.wrapping_shl((other
& self::shift_max
::$t
as $f
) as u32))
76 #[stable(feature = "op_assign_traits", since = "1.8.0")]
77 impl ShlAssign
<$f
> for Wrapping
<$t
> {
79 fn shl_assign(&mut self, other
: $f
) {
80 *self = *self << other
;
84 #[stable(feature = "rust1", since = "1.0.0")]
85 impl Shr
<$f
> for Wrapping
<$t
> {
86 type Output
= Wrapping
<$t
>;
89 fn shr(self, other
: $f
) -> Wrapping
<$t
> {
90 Wrapping(self.0.wrapping_shr((other
& self::shift_max
::$t
as $f
) as u32))
94 #[stable(feature = "op_assign_traits", since = "1.8.0")]
95 impl ShrAssign
<$f
> for Wrapping
<$t
> {
97 fn shr_assign(&mut self, other
: $f
) {
98 *self = *self >> other
;
104 // FIXME (#23545): uncomment the remaining impls
105 macro_rules
! sh_impl_all
{
106 ($
($t
:ident
)*) => ($
(
107 //sh_impl_unsigned! { $t, u8 }
108 //sh_impl_unsigned! { $t, u16 }
109 //sh_impl_unsigned! { $t, u32 }
110 //sh_impl_unsigned! { $t, u64 }
111 sh_impl_unsigned
! { $t, usize }
113 //sh_impl_signed! { $t, i8 }
114 //sh_impl_signed! { $t, i16 }
115 //sh_impl_signed! { $t, i32 }
116 //sh_impl_signed! { $t, i64 }
117 //sh_impl_signed! { $t, isize }
121 sh_impl_all
! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
123 // FIXME(30524): impl Op<T> for Wrapping<T>, impl OpAssign<T> for Wrapping<T>
124 macro_rules
! wrapping_impl
{
126 #[stable(feature = "rust1", since = "1.0.0")]
127 impl Add
for Wrapping
<$t
> {
128 type Output
= Wrapping
<$t
>;
131 fn add(self, other
: Wrapping
<$t
>) -> Wrapping
<$t
> {
132 Wrapping(self.0.wrapping_add(other
.0))
135 forward_ref_binop
! { impl Add
, add
for Wrapping
<$t
>, Wrapping
<$t
>,
136 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
138 #[stable(feature = "op_assign_traits", since = "1.8.0")]
139 impl AddAssign
for Wrapping
<$t
> {
141 fn add_assign(&mut self, other
: Wrapping
<$t
>) {
142 *self = *self + other
;
146 #[stable(feature = "rust1", since = "1.0.0")]
147 impl Sub
for Wrapping
<$t
> {
148 type Output
= Wrapping
<$t
>;
151 fn sub(self, other
: Wrapping
<$t
>) -> Wrapping
<$t
> {
152 Wrapping(self.0.wrapping_sub(other
.0))
155 forward_ref_binop
! { impl Sub
, sub
for Wrapping
<$t
>, Wrapping
<$t
>,
156 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
158 #[stable(feature = "op_assign_traits", since = "1.8.0")]
159 impl SubAssign
for Wrapping
<$t
> {
161 fn sub_assign(&mut self, other
: Wrapping
<$t
>) {
162 *self = *self - other
;
166 #[stable(feature = "rust1", since = "1.0.0")]
167 impl Mul
for Wrapping
<$t
> {
168 type Output
= Wrapping
<$t
>;
171 fn mul(self, other
: Wrapping
<$t
>) -> Wrapping
<$t
> {
172 Wrapping(self.0.wrapping_mul(other
.0))
175 forward_ref_binop
! { impl Mul
, mul
for Wrapping
<$t
>, Wrapping
<$t
>,
176 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
178 #[stable(feature = "op_assign_traits", since = "1.8.0")]
179 impl MulAssign
for Wrapping
<$t
> {
181 fn mul_assign(&mut self, other
: Wrapping
<$t
>) {
182 *self = *self * other
;
186 #[stable(feature = "wrapping_div", since = "1.3.0")]
187 impl Div
for Wrapping
<$t
> {
188 type Output
= Wrapping
<$t
>;
191 fn div(self, other
: Wrapping
<$t
>) -> Wrapping
<$t
> {
192 Wrapping(self.0.wrapping_div(other
.0))
195 forward_ref_binop
! { impl Div
, div
for Wrapping
<$t
>, Wrapping
<$t
>,
196 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
198 #[stable(feature = "op_assign_traits", since = "1.8.0")]
199 impl DivAssign
for Wrapping
<$t
> {
201 fn div_assign(&mut self, other
: Wrapping
<$t
>) {
202 *self = *self / other
;
206 #[stable(feature = "wrapping_impls", since = "1.7.0")]
207 impl Rem
for Wrapping
<$t
> {
208 type Output
= Wrapping
<$t
>;
211 fn rem(self, other
: Wrapping
<$t
>) -> Wrapping
<$t
> {
212 Wrapping(self.0.wrapping_rem(other
.0))
215 forward_ref_binop
! { impl Rem
, rem
for Wrapping
<$t
>, Wrapping
<$t
>,
216 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
218 #[stable(feature = "op_assign_traits", since = "1.8.0")]
219 impl RemAssign
for Wrapping
<$t
> {
221 fn rem_assign(&mut self, other
: Wrapping
<$t
>) {
222 *self = *self % other
;
226 #[stable(feature = "rust1", since = "1.0.0")]
227 impl Not
for Wrapping
<$t
> {
228 type Output
= Wrapping
<$t
>;
231 fn not(self) -> Wrapping
<$t
> {
235 forward_ref_unop
! { impl Not
, not
for Wrapping
<$t
>,
236 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
238 #[stable(feature = "rust1", since = "1.0.0")]
239 impl BitXor
for Wrapping
<$t
> {
240 type Output
= Wrapping
<$t
>;
243 fn bitxor(self, other
: Wrapping
<$t
>) -> Wrapping
<$t
> {
244 Wrapping(self.0 ^ other
.0)
247 forward_ref_binop
! { impl BitXor
, bitxor
for Wrapping
<$t
>, Wrapping
<$t
>,
248 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
250 #[stable(feature = "op_assign_traits", since = "1.8.0")]
251 impl BitXorAssign
for Wrapping
<$t
> {
253 fn bitxor_assign(&mut self, other
: Wrapping
<$t
>) {
254 *self = *self ^ other
;
258 #[stable(feature = "rust1", since = "1.0.0")]
259 impl BitOr
for Wrapping
<$t
> {
260 type Output
= Wrapping
<$t
>;
263 fn bitor(self, other
: Wrapping
<$t
>) -> Wrapping
<$t
> {
264 Wrapping(self.0 | other
.0)
267 forward_ref_binop
! { impl BitOr
, bitor
for Wrapping
<$t
>, Wrapping
<$t
>,
268 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
270 #[stable(feature = "op_assign_traits", since = "1.8.0")]
271 impl BitOrAssign
for Wrapping
<$t
> {
273 fn bitor_assign(&mut self, other
: Wrapping
<$t
>) {
274 *self = *self | other
;
278 #[stable(feature = "rust1", since = "1.0.0")]
279 impl BitAnd
for Wrapping
<$t
> {
280 type Output
= Wrapping
<$t
>;
283 fn bitand(self, other
: Wrapping
<$t
>) -> Wrapping
<$t
> {
284 Wrapping(self.0 & other
.0)
287 forward_ref_binop
! { impl BitAnd
, bitand
for Wrapping
<$t
>, Wrapping
<$t
>,
288 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
290 #[stable(feature = "op_assign_traits", since = "1.8.0")]
291 impl BitAndAssign
for Wrapping
<$t
> {
293 fn bitand_assign(&mut self, other
: Wrapping
<$t
>) {
294 *self = *self & other
;
298 #[stable(feature = "wrapping_neg", since = "1.10.0")]
299 impl Neg
for Wrapping
<$t
> {
302 fn neg(self) -> Self {
306 forward_ref_unop
! { impl Neg
, neg
for Wrapping
<$t
>,
307 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
311 wrapping_impl
! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
314 #![allow(non_upper_case_globals)]
316 #[cfg(target_pointer_width = "16")]
318 pub const usize: u32 = super::u16;
319 pub const isize: u32 = super::i16;
322 #[cfg(target_pointer_width = "32")]
324 pub const usize: u32 = super::u32;
325 pub const isize: u32 = super::i32;
328 #[cfg(target_pointer_width = "64")]
330 pub const usize: u32 = super::u64;
331 pub const isize: u32 = super::i64;
334 pub const i8: u32 = (1 << 3) - 1;
335 pub const i16: u32 = (1 << 4) - 1;
336 pub const i32: u32 = (1 << 5) - 1;
337 pub const i64: u32 = (1 << 6) - 1;
338 pub use self::platform
::isize;
340 pub const u8: u32 = i8;
341 pub const u16: u32 = i16;
342 pub const u32: u32 = i32;
343 pub const u64: u32 = i64;
344 pub use self::platform
::usize;