rust/src/libcore/num
Mazdak Farrokhzad 13726cc444
Rollup merge of #63786 - tspiteri:const-abs, r=alexcrichton
Make `abs`, `wrapping_abs`, `overflowing_abs` const functions

This makes `abs`, `wrapping_abs` and `overflowing_abs` const functions like #58044 makes `wrapping_neg` and `overflowing_neg` const functions.

`abs` is made const by returning `(self ^ -1) - -1` = `!self + 1` = `-self` for negative numbers and `(self ^ 0) - 0` = `self` for non-negative numbers. The subexpression `self >> ($BITS - 1)` evaluates to `-1` for negative numbers and `0` otherwise. The subtraction overflows when `self` is `min_value()`, as we would be subtracting `max_value() - -1`; this is when `abs` should overflow.

`wrapping_abs` and `overflowing_abs` make use of `wrapping_sub` and `overflowing_sub` instead of the subtraction operator.
2019-09-10 17:19:19 +02:00
..
dec2flt libcore: deny more... 2019-04-19 01:37:12 +02:00
flt2dec Remove double trailing newlines 2019-04-22 16:57:01 +01:00
bignum.rs libcore: deny more... 2019-04-19 01:37:12 +02:00
diy_float.rs Remove licenses 2018-12-25 21:08:33 -07:00
f32.rs Change code formatting for readability. 2019-08-22 14:27:51 +02:00
f64.rs Change code formatting for readability. 2019-08-22 14:27:51 +02:00
i8.rs Remove licenses 2018-12-25 21:08:33 -07:00
i16.rs Remove licenses 2018-12-25 21:08:33 -07:00
i32.rs Remove licenses 2018-12-25 21:08:33 -07:00
i64.rs Remove licenses 2018-12-25 21:08:33 -07:00
i128.rs Remove licenses 2018-12-25 21:08:33 -07:00
int_macros.rs Remove licenses 2018-12-25 21:08:33 -07:00
isize.rs Remove licenses 2018-12-25 21:08:33 -07:00
mod.rs make abs, wrapping_abs, and overflowing_abs const functions 2019-08-21 14:10:40 +02:00
u8.rs Remove licenses 2018-12-25 21:08:33 -07:00
u16.rs Remove licenses 2018-12-25 21:08:33 -07:00
u32.rs Remove licenses 2018-12-25 21:08:33 -07:00
u64.rs Remove licenses 2018-12-25 21:08:33 -07:00
u128.rs Remove licenses 2018-12-25 21:08:33 -07:00
uint_macros.rs Remove licenses 2018-12-25 21:08:33 -07:00
usize.rs Remove licenses 2018-12-25 21:08:33 -07:00
wrapping.rs Test that Wrapping arithmetic ops are implemented for all int types 2019-08-20 23:13:08 +02:00