make unwrapped_rem{,_euclid} const fn, remove const_rem

This commit is contained in:
Trevor Spiteri 2021-04-15 17:19:28 +02:00
parent 25e4543ed8
commit 89d5a9e8db
3 changed files with 15 additions and 56 deletions

View File

@ -109,13 +109,12 @@ The conversions supported cover the following cases.
[`unwrapped_rem_euclid`][f-ure-1-8]
* [`unwrapped_rem_int`][f-uri-1-8]
* The following methods are now `const` functions:
* [`checked_rem`][f-chr-1-8]
* [`checked_rem`][f-cr-1-8]
* [`rem_euclid`][f-re-1-8], [`checked_rem_euclid`][f-cre-1-8]
* [`checked_div_int`][f-cdi-1-8],
[`wrapping_div_int`][f-wdi-1-8],
[`overflowing_div_int`][f-odi-1-8]
* The following methods were added to all fixed-point numbers:
* [`const_rem`][f-cor-1-8]
* [`const_not`][f-cn-1-8]
* [`const_bitand`][f-cba-1-8], [`const_bitor`][f-cbo-1-8],
[`const_bitxor`][f-cbx-1-8]
@ -125,9 +124,8 @@ The conversions supported cover the following cases.
[f-cbo-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.const_bitor
[f-cbx-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.const_bitxor
[f-cdi-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.checked_div_int
[f-chr-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.checked_rem
[f-cn-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.const_not
[f-cor-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.const_rem
[f-cr-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.checked_rem
[f-cre-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.checked_rem_euclid
[f-d-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#associatedconstant.DELTA
[f-o-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#associatedconstant.ONE

View File

@ -22,13 +22,12 @@ Version 1.8.0 (unreleased)
[`unwrapped_rem_euclid`][f-ure-1-8]
* [`unwrapped_rem_int`][f-uri-1-8]
* The following methods are now `const` functions:
* [`checked_rem`][f-chr-1-8]
* [`checked_rem`][f-cr-1-8]
* [`rem_euclid`][f-re-1-8], [`checked_rem_euclid`][f-cre-1-8]
* [`checked_div_int`][f-cdi-1-8],
[`wrapping_div_int`][f-wdi-1-8],
[`overflowing_div_int`][f-odi-1-8]
* The following methods were added to all fixed-point numbers:
* [`const_rem`][f-cor-1-8]
* [`const_not`][f-cn-1-8]
* [`const_bitand`][f-cba-1-8], [`const_bitor`][f-cbo-1-8],
[`const_bitxor`][f-cbx-1-8]
@ -38,9 +37,8 @@ Version 1.8.0 (unreleased)
[f-cbo-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.const_bitor
[f-cbx-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.const_bitxor
[f-cdi-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.checked_div_int
[f-chr-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.checked_rem
[f-cn-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.const_not
[f-cor-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.const_rem
[f-cr-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.checked_rem
[f-cre-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.checked_rem_euclid
[f-d-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#associatedconstant.DELTA
[f-o-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#associatedconstant.ONE

View File

@ -977,50 +977,6 @@ assert_eq!(Fix::from_num(3).mean(Fix::from_num(4)), Fix::from_num(3.5));
}
}
comment! {
"Remainder. Usable in constant context.
This is equivalent to the `%` operator and
<code>[Rem][core::ops::Rem]::[rem][core::ops::Rem::rem]</code>, but
can also be used in constant context. Unless required in constant
context, use the operator or trait instead.
# Planned deprecation
This method will be deprecated when the `%` operator and the
[`Rem`][core::ops::Rem] trait are usable in constant context.
# Panics
Panics if the divisor is zero.
# Examples
```rust
use fixed::{const_fixed_from_int, types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
const_fixed_from_int! {
const THREE: Fix = 3;
const FIVE: Fix = 5;
}
const TWO: Fix = FIVE.const_rem(THREE);
assert_eq!(TWO, FIVE % THREE);
```
";
#[inline]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn const_rem(self, rhs: $Fixed<Frac>) -> $Fixed<Frac> {
let rhs_bits = rhs.to_bits();
if_signed! {
$Signedness;
if rhs_bits == -1 {
return Self::ZERO;
}
}
Self::from_bits(self.to_bits() % rhs_bits)
}
}
comment! {
"Bitwise NOT. Usable in constant context.
@ -2176,8 +2132,15 @@ let _divisor_is_zero = Fix::from_num(1.5).unwrapped_rem(Fix::ZERO);
#[inline]
#[track_caller]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub fn unwrapped_rem(self, rhs: $Fixed<Frac>) -> $Fixed<Frac> {
self.checked_rem(rhs).expect("division by zero")
pub const fn unwrapped_rem(self, rhs: $Fixed<Frac>) -> $Fixed<Frac> {
let rhs_bits = rhs.to_bits();
if_signed! {
$Signedness;
if rhs_bits == -1 {
return Self::ZERO;
}
}
Self::from_bits(self.to_bits() % rhs_bits)
}
}
@ -2352,8 +2315,8 @@ let _divisor_is_zero = Fix::from_num(3).unwrapped_rem_euclid(Fix::ZERO);
#[inline]
#[track_caller]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub fn unwrapped_rem_euclid(self, rhs: $Fixed<Frac>) -> $Fixed<Frac> {
self.checked_rem_euclid(rhs).expect("division by zero")
pub const fn unwrapped_rem_euclid(self, rhs: $Fixed<Frac>) -> $Fixed<Frac> {
self.rem_euclid(rhs)
}
}