make const functions: min_value, max_value, from_bits, to_bits
This commit is contained in:
parent
b46789da36
commit
2518b6b147
10
README.md
10
README.md
|
@ -49,6 +49,16 @@ Various conversion methods are available:
|
|||
|
||||
## What’s new
|
||||
|
||||
### Version 0.4.3 news (unreleased)
|
||||
|
||||
* The following methods are now `const` functions:
|
||||
* `min_value`, `max_value`, `from_bits`, `to_bits`
|
||||
|
||||
[`from_bits`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI32.html#method.from_bits
|
||||
[`max_value`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI32.html#method.max_value
|
||||
[`min_value`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI32.html#method.min_value
|
||||
[`to_bits`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI32.html#method.to_bits
|
||||
|
||||
### Version 0.4.2 news (2019-08-16)
|
||||
|
||||
* The new methods [`from_num`] and [`to_num`] together with their
|
||||
|
|
|
@ -5,6 +5,12 @@ modification, are permitted in any medium without royalty provided the
|
|||
copyright notice and this notice are preserved. This file is offered
|
||||
as-is, without any warranty. -->
|
||||
|
||||
Version 0.4.3 (unreleased)
|
||||
==========================
|
||||
|
||||
* The following methods are now `const` functions:
|
||||
* `min_value`, `max_value`, `from_bits`, `to_bits`
|
||||
|
||||
Version 0.4.2 (2019-08-16)
|
||||
==========================
|
||||
|
||||
|
|
|
@ -65,15 +65,6 @@ macro_rules! comment {
|
|||
}
|
||||
|
||||
macro_rules! delegate {
|
||||
($($comment:expr),*; $Fixed:ident($Inner:ty) => fn $method:ident()) => {
|
||||
doc_comment! {
|
||||
concat!($($comment),*);
|
||||
#[inline]
|
||||
pub fn $method() -> $Fixed<Frac> {
|
||||
Self::from_bits(<$Inner>::$method())
|
||||
}
|
||||
}
|
||||
};
|
||||
($($comment:expr),*; $Fixed:ident => fn $method:ident(self)) => {
|
||||
doc_comment! {
|
||||
concat!($($comment),*);
|
||||
|
|
|
@ -20,7 +20,7 @@ macro_rules! fixed_no_frac {
|
|||
$UInner:ty, $Signedness:tt
|
||||
) => {
|
||||
impl<Frac> $Fixed<Frac> {
|
||||
delegate!(
|
||||
comment!(
|
||||
"Returns the smallest value that can be represented.
|
||||
|
||||
# Examples
|
||||
|
@ -31,10 +31,13 @@ type Fix = ", $s_fixed, "<U4>;
|
|||
assert_eq!(Fix::min_value(), Fix::from_bits(", $s_inner, "::min_value()));
|
||||
```
|
||||
";
|
||||
$Fixed($Inner) => fn min_value()
|
||||
#[inline]
|
||||
pub const fn min_value() -> $Fixed<Frac> {
|
||||
Self::from_bits(<$Inner>::min_value())
|
||||
}
|
||||
);
|
||||
|
||||
delegate!(
|
||||
comment!(
|
||||
"Returns the largest value that can be represented.
|
||||
|
||||
# Examples
|
||||
|
@ -45,7 +48,10 @@ type Fix = ", $s_fixed, "<U4>;
|
|||
assert_eq!(Fix::max_value(), Fix::from_bits(", $s_inner, "::max_value()));
|
||||
```
|
||||
";
|
||||
$Fixed($Inner) => fn max_value()
|
||||
#[inline]
|
||||
pub const fn max_value() -> $Fixed<Frac> {
|
||||
Self::from_bits(<$Inner>::max_value())
|
||||
}
|
||||
);
|
||||
|
||||
comment!(
|
||||
|
@ -62,7 +68,7 @@ assert_eq!(Fix::from_bits(0b10_0000), 2);
|
|||
```
|
||||
";
|
||||
#[inline]
|
||||
pub fn from_bits(bits: $Inner) -> $Fixed<Frac> {
|
||||
pub const fn from_bits(bits: $Inner) -> $Fixed<Frac> {
|
||||
$Fixed {
|
||||
bits,
|
||||
phantom: PhantomData,
|
||||
|
@ -84,7 +90,7 @@ assert_eq!(Fix::from_num(2).to_bits(), 0b10_0000);
|
|||
```
|
||||
";
|
||||
#[inline]
|
||||
pub fn to_bits(self) -> $Inner {
|
||||
pub const fn to_bits(self) -> $Inner {
|
||||
self.bits
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue