add ZERO, DELTA, ONE constants
This commit is contained in:
parent
92de6c24e6
commit
3794dec03d
11
README.md
11
README.md
|
@ -81,6 +81,12 @@ The conversions supported cover the following cases.
|
|||
|
||||
### Version 1.8.0 news (unreleased)
|
||||
|
||||
* The following constants were added to all fixed-point numbers, to
|
||||
the [`Fixed`][tf-1-8] trait, and to the [`Wrapping`][w-1-8] and
|
||||
[`Unwrapped`][u-1-8] wrappers:
|
||||
* [`ZERO`][f-z-1-8], [`DELTA`][f-d-1-8]
|
||||
* The [`ONE`][f-o-1-8] constant was added to all fixed-point numbers
|
||||
that can represent the value 1.
|
||||
* The following methods were added to all fixed-point numbers and to
|
||||
the [`Fixed`][tf-1-8] trait:
|
||||
* [`unwrapped_rem`][f-ur-1-8],
|
||||
|
@ -88,10 +94,15 @@ The conversions supported cover the following cases.
|
|||
* [`unwrapped_rem_int`][f-uri-1-8]
|
||||
* Many methods were marked with the `must_use` attribute.
|
||||
|
||||
[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
|
||||
[f-ur-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.unwrapped_rem
|
||||
[f-ure-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.unwrapped_rem_euclid
|
||||
[f-uri-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.unwrapped_rem_int
|
||||
[f-z-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#associatedconstant.ZERO
|
||||
[tf-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/traits/trait.Fixed.html
|
||||
[u-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.Unwrapped.html
|
||||
[w-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.Wrapping.html
|
||||
|
||||
### Version 1.7.0 news (2021-03-25)
|
||||
|
||||
|
|
11
RELEASES.md
11
RELEASES.md
|
@ -8,6 +8,12 @@ as-is, without any warranty. -->
|
|||
Version 1.8.0 (unreleased)
|
||||
==========================
|
||||
|
||||
* The following constants were added to all fixed-point numbers, to
|
||||
the [`Fixed`][tf-1-8] trait, and to the [`Wrapping`][w-1-8] and
|
||||
[`Unwrapped`][u-1-8] wrappers:
|
||||
* [`ZERO`][f-z-1-8], [`DELTA`][f-d-1-8]
|
||||
* The [`ONE`][f-o-1-8] constant was added to all fixed-point numbers
|
||||
that can represent the value 1.
|
||||
* The following methods were added to all fixed-point numbers and to
|
||||
the [`Fixed`][tf-1-8] trait:
|
||||
* [`unwrapped_rem`][f-ur-1-8],
|
||||
|
@ -15,10 +21,15 @@ Version 1.8.0 (unreleased)
|
|||
* [`unwrapped_rem_int`][f-uri-1-8]
|
||||
* Many methods were marked with the `must_use` attribute.
|
||||
|
||||
[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
|
||||
[f-ur-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.unwrapped_rem
|
||||
[f-ure-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.unwrapped_rem_euclid
|
||||
[f-uri-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.unwrapped_rem_int
|
||||
[f-z-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#associatedconstant.ZERO
|
||||
[tf-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/traits/trait.Fixed.html
|
||||
[u-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.Unwrapped.html
|
||||
[w-1-8]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.Wrapping.html
|
||||
|
||||
Version 1.7.0 (2021-03-25)
|
||||
==========================
|
||||
|
|
|
@ -193,6 +193,21 @@ let _ = Fix::LOG2_E;
|
|||
where
|
||||
Frac: IsLessOrEqual<$LeEqU_C1, Output = True>,
|
||||
{
|
||||
comment! {
|
||||
"One.
|
||||
|
||||
# Examples
|
||||
|
||||
```rust
|
||||
use fixed::{types::extra::U4, ", $s_fixed, "};
|
||||
type Fix = ", $s_fixed, "<U4>;
|
||||
assert_eq!(Fix::ONE, Fix::from_num(1));
|
||||
```
|
||||
";
|
||||
pub const ONE: $Fixed<Frac> =
|
||||
$Fixed::from_bits($Fixed::<Frac>::DELTA.to_bits() << Frac::U32);
|
||||
}
|
||||
|
||||
/// τ/4 = 1.57079…
|
||||
pub const FRAC_TAU_4: $Fixed<Frac> = shift!(FRAC_TAU_4, 127, $Fixed<Frac>);
|
||||
|
||||
|
|
|
@ -51,6 +51,36 @@ assert_eq!(Fix::MAX, Fix::from_bits(", $s_inner, "::MAX));
|
|||
pub const MAX: $Fixed<Frac> = Self::from_bits(<$Inner>::MAX);
|
||||
}
|
||||
|
||||
comment! {
|
||||
"Zero.
|
||||
|
||||
# Examples
|
||||
|
||||
```rust
|
||||
use fixed::{types::extra::U4, ", $s_fixed, "};
|
||||
type Fix = ", $s_fixed, "<U4>;
|
||||
assert_eq!(Fix::ZERO, Fix::from_bits(0));
|
||||
```
|
||||
";
|
||||
pub const ZERO: $Fixed<Frac> = Self::from_bits(0);
|
||||
}
|
||||
|
||||
comment! {
|
||||
"The smallest positive value that can be represented.
|
||||
|
||||
# Examples
|
||||
|
||||
```rust
|
||||
use fixed::{types::extra::U4, ", $s_fixed, "};
|
||||
type Fix = ", $s_fixed, "<U4>;
|
||||
assert_eq!(Fix::DELTA, Fix::from_bits(1));
|
||||
// binary 0.0001 is decimal 0.0625
|
||||
assert_eq!(Fix::DELTA, 0.0625);
|
||||
```
|
||||
";
|
||||
pub const DELTA: $Fixed<Frac> = Self::from_bits(1);
|
||||
}
|
||||
|
||||
comment! {
|
||||
if_signed_unsigned!($Signedness, "[`true`]", "[`false`]"),
|
||||
"[`bool`] because the [`", $s_fixed, "`] type is ",
|
||||
|
|
|
@ -307,6 +307,12 @@ where
|
|||
/// The largest value that can be represented.
|
||||
const MAX: Self;
|
||||
|
||||
/// Zero.
|
||||
const ZERO: Self;
|
||||
|
||||
/// The smallest positive value that can be represented.
|
||||
const DELTA: Self;
|
||||
|
||||
/// [`true`] if the type is signed.
|
||||
const IS_SIGNED: bool;
|
||||
|
||||
|
@ -2235,6 +2241,8 @@ macro_rules! impl_fixed {
|
|||
type Frac = Frac;
|
||||
const MIN: Self = Self::MIN;
|
||||
const MAX: Self = Self::MAX;
|
||||
const ZERO: Self = Self::ZERO;
|
||||
const DELTA: Self = Self::DELTA;
|
||||
const IS_SIGNED: bool = Self::IS_SIGNED;
|
||||
const INT_NBITS: u32 = Self::INT_NBITS;
|
||||
const FRAC_NBITS: u32 = Self::FRAC_NBITS;
|
||||
|
|
|
@ -72,6 +72,26 @@ impl<F: Fixed> Unwrapped<F> {
|
|||
/// ```
|
||||
pub const MAX: Unwrapped<F> = Unwrapped(F::MAX);
|
||||
|
||||
/// Zero.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// use fixed::{types::I16F16, Unwrapped};
|
||||
/// assert_eq!(Unwrapped::<I16F16>::ZERO, Unwrapped(I16F16::ZERO));
|
||||
/// ```
|
||||
pub const ZERO: Unwrapped<F> = Unwrapped(F::ZERO);
|
||||
|
||||
/// The smallest positive value that can be represented.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// use fixed::{types::I16F16, Unwrapped};
|
||||
/// assert_eq!(Unwrapped::<I16F16>::DELTA, Unwrapped(I16F16::DELTA));
|
||||
/// ```
|
||||
pub const DELTA: Unwrapped<F> = Unwrapped(F::DELTA);
|
||||
|
||||
/// [`true`] if the type is signed.
|
||||
///
|
||||
/// # Examples
|
||||
|
|
|
@ -69,6 +69,26 @@ impl<F: Fixed> Wrapping<F> {
|
|||
/// ```
|
||||
pub const MAX: Wrapping<F> = Wrapping(F::MAX);
|
||||
|
||||
/// Zero.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// use fixed::{types::I16F16, Wrapping};
|
||||
/// assert_eq!(Wrapping::<I16F16>::ZERO, Wrapping(I16F16::ZERO));
|
||||
/// ```
|
||||
pub const ZERO: Wrapping<F> = Wrapping(F::ZERO);
|
||||
|
||||
/// The smallest positive value that can be represented.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// use fixed::{types::I16F16, Wrapping};
|
||||
/// assert_eq!(Wrapping::<I16F16>::DELTA, Wrapping(I16F16::DELTA));
|
||||
/// ```
|
||||
pub const DELTA: Wrapping<F> = Wrapping(F::DELTA);
|
||||
|
||||
/// [`true`] if the type is signed.
|
||||
///
|
||||
/// # Examples
|
||||
|
|
Loading…
Reference in New Issue