doc updates
This commit is contained in:
parent
46049bb7ac
commit
fa271a4a9d
70
README.md
70
README.md
|
@ -36,16 +36,23 @@ fixed-point numbers.
|
|||
Various conversion methods are available:
|
||||
|
||||
* All lossless infallible conversions between fixed-point numbers
|
||||
and numeric primitives are implemented. That is, you can use
|
||||
[`From`] or [`Into`] for the conversions that always work without
|
||||
losing any bits.
|
||||
* For infallible conversions that are not lossless because the
|
||||
source type may have more fractional bits than the destination
|
||||
type, [`LossyFrom`] and [`LossyInto`] can be used; these will
|
||||
truncate any excess fractional bits in the source value.
|
||||
* Checked conversions are provided between all types using the
|
||||
[`FromFixed`] and [`ToFixed`] traits, or using the inherent methods
|
||||
in the fixed-point types themselves.
|
||||
and numeric primitives are implemented. You can use [`From`] or
|
||||
[`Into`] for conversions that always work without losing any bits.
|
||||
* For lossy infallible conversions between fixed-point numbers and
|
||||
numeric primitives, where the source type may have more fractional
|
||||
bits than the destination type, the [`LossyFrom`] and
|
||||
[`LossyInto`] traits can be used. Excess fractional bits are
|
||||
truncated.
|
||||
* Checked conversions are provided between fixed-point numbers and
|
||||
numeric primitives using the [`FromFixed`] and [`ToFixed`] traits,
|
||||
or using the [`from_num`] and [`to_num`] methods.
|
||||
* Fixed-point numbers can be parsed from decimal strings using
|
||||
[`FromStr`], or from binary, octal or hexadecimal using the
|
||||
[`from_str_binary`], [`from_str_octal`] or [`from_str_hex`]
|
||||
methods. The result is rounded to the nearest, ties to even.
|
||||
* Fixed-point numbers can be converted to strings using [`Display`],
|
||||
[`Binary`], [`Octal`], [`LowerHex`] and [`UpperHex`]. The output
|
||||
is rounded to the nearest, ties to even.
|
||||
|
||||
## What’s new
|
||||
|
||||
|
@ -76,7 +83,6 @@ Various conversion methods are available:
|
|||
|
||||
[`FRAC_NBITS`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI32.html#associatedconstant.FRAC_NBITS
|
||||
[`Fixed`]: https://docs.rs/fixed/0.4.2/fixed/traits/trait.Fixed.html
|
||||
[`FromStr`]: https://doc.rust-lang.org/nightly/std/str/trait.FromStr.html
|
||||
[`INT_NBITS`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI32.html#associatedconstant.INT_NBITS
|
||||
[`Wrapping`]: https://docs.rs/fixed/0.4.2/fixed/struct.Wrapping.html
|
||||
[`count_ones`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI32.html#method.count_ones
|
||||
|
@ -120,8 +126,6 @@ Various conversion methods are available:
|
|||
|
||||
[`Wrapping::from_num`]: https://docs.rs/fixed/0.4.2/fixed/struct.Wrapping.html#method.from_num
|
||||
[`Wrapping`]: https://docs.rs/fixed/0.4.2/fixed/struct.Wrapping.html
|
||||
[`from_num`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI32.html#method.from_num
|
||||
[`to_num`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI32.html#method.to_num
|
||||
|
||||
### Version 0.4.1 news (2019-08-12)
|
||||
|
||||
|
@ -129,11 +133,6 @@ Various conversion methods are available:
|
|||
* The methods [`from_str_binary`], [`from_str_octal`] and
|
||||
[`from_str_hex`] were added.
|
||||
|
||||
[`FromStr`]: https://doc.rust-lang.org/nightly/std/str/trait.FromStr.html
|
||||
[`from_str_binary`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI32.html#method.from_str_binary
|
||||
[`from_str_octal`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI32.html#method.from_str_octal
|
||||
[`from_str_hex`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI32.html#method.from_str_hex
|
||||
|
||||
### Version 0.4.0 news (2019-08-08)
|
||||
|
||||
* The [*fixed* crate] now requires rustc version 1.31.0 or later.
|
||||
|
@ -193,37 +192,37 @@ assert_eq!(six_and_third.ceil(), 7);
|
|||
|
||||
The type [`I20F12`] is a 32-bit fixed-point signed number with 20
|
||||
integer bits and 12 fractional bits. It is an alias to
|
||||
<code>[FixedI32][`FixedI32`]<[frac::U12][`frac::U12`]></code>.
|
||||
<code>[FixedI32][`FixedI32`]<[U12][`U12`]></code>.
|
||||
The unsigned counterpart would be [`U20F12`]. Aliases are provided for
|
||||
all combinations of integer and fractional bits adding up to a total
|
||||
of eight, 16, 32, 64 or 128 bits.
|
||||
|
||||
```rust
|
||||
// −8 ≤ I4F4 < 8 with steps of 1/16 (about 0.06)
|
||||
// −8 ≤ I4F4 < 8 with steps of 1/16 (~0.06)
|
||||
use fixed::types::I4F4;
|
||||
let a = I4F4::from_num(1);
|
||||
// multiplication and division by integers are possible
|
||||
let ans1 = a / 5 * 17;
|
||||
// 1 / 5 × 17 = 3 2/5 (3.4), but we get 3 3/16 (≈3.2)
|
||||
// 1 / 5 × 17 = 3 2/5 (3.4), but we get 3 3/16 (~3.2)
|
||||
assert_eq!(ans1, I4F4::from_bits((3 << 4) + 3));
|
||||
assert_eq!(ans1.to_string(), "3.2");
|
||||
|
||||
// −8 ≤ I4F12 < 8 with steps of 1/4096 (about 0.0002)
|
||||
// −8 ≤ I4F12 < 8 with steps of 1/4096 (~0.0002)
|
||||
use fixed::types::I4F12;
|
||||
let wider_a = I4F12::from(a);
|
||||
let wider_ans = wider_a / 5 * 17;
|
||||
let ans2 = I4F4::from_num(wider_ans);
|
||||
// now the answer is the much closer 3 6/16 (≈3.4)
|
||||
// now the answer is the much closer 3 6/16 (~3.4)
|
||||
assert_eq!(ans2, I4F4::from_bits((3 << 4) + 6));
|
||||
assert_eq!(ans2.to_string(), "3.4");
|
||||
```
|
||||
|
||||
The second example shows some precision and conversion issues. The low
|
||||
precision of `a` means that `a / 5` is 3⁄16 instead of 1⁄5, leading to
|
||||
an inaccurate result `ans1` = 3 3⁄16 (3.19). With a higher precision,
|
||||
an inaccurate result `ans1` = 3 3⁄16 (~3.2). With a higher precision,
|
||||
we get `wider_a / 5` equal to 819⁄4096, leading to a more accurate
|
||||
intermediate result `wider_ans` = 3 1635⁄4096. When we convert back to
|
||||
four fractional bits, we get `ans2` = 3 6⁄16 (3.38).
|
||||
four fractional bits, we get `ans2` = 3 6⁄16 (~3.4).
|
||||
|
||||
Note that we can convert from [`I4F4`] to [`I4F12`] using [`From`], as
|
||||
the target type has the same number of integer bits and a larger
|
||||
|
@ -241,13 +240,6 @@ it in your crate, add it as a dependency inside [*Cargo.toml*]:
|
|||
fixed = "0.4.2"
|
||||
```
|
||||
|
||||
If you are using the 2015 Rust edition, you also need to declare it by
|
||||
adding this to your crate root (usually *lib.rs* or *main.rs*):
|
||||
|
||||
```rust
|
||||
extern crate fixed;
|
||||
```
|
||||
|
||||
The *fixed* crate requires rustc version 1.34.0 or later.
|
||||
|
||||
## Optional features
|
||||
|
@ -293,6 +285,8 @@ additional terms or conditions.
|
|||
[*typenum* crate]: https://crates.io/crates/typenum
|
||||
[LICENSE-APACHE]: https://www.apache.org/licenses/LICENSE-2.0
|
||||
[LICENSE-MIT]: https://opensource.org/licenses/MIT
|
||||
[`Binary`]: https://doc.rust-lang.org/nightly/std/fmt/trait.Binary.html
|
||||
[`Display`]: https://doc.rust-lang.org/nightly/std/fmt/trait.Display.html
|
||||
[`FixedI128`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI128.html
|
||||
[`FixedI16`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI16.html
|
||||
[`FixedI32`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI32.html
|
||||
|
@ -304,6 +298,7 @@ additional terms or conditions.
|
|||
[`FixedU64`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedU64.html
|
||||
[`FixedU8`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedU8.html
|
||||
[`FromFixed`]: https://docs.rs/fixed/0.4.2/fixed/traits/trait.FromFixed.html
|
||||
[`FromStr`]: https://doc.rust-lang.org/nightly/std/str/trait.FromStr.html
|
||||
[`From`]: https://doc.rust-lang.org/nightly/std/convert/trait.From.html
|
||||
[`I20F12`]: https://docs.rs/fixed/0.4.2/fixed/types/type.I20F12.html
|
||||
[`I4F12`]: https://docs.rs/fixed/0.4.2/fixed/types/type.I4F12.html
|
||||
|
@ -311,9 +306,16 @@ additional terms or conditions.
|
|||
[`Into`]: https://doc.rust-lang.org/nightly/std/convert/trait.Into.html
|
||||
[`LossyFrom`]: https://docs.rs/fixed/0.4.2/fixed/traits/trait.LossyFrom.html
|
||||
[`LossyInto`]: https://docs.rs/fixed/0.4.2/fixed/traits/trait.LossyInto.html
|
||||
[`LowerHex`]: https://doc.rust-lang.org/nightly/std/fmt/trait.LowerHex.html
|
||||
[`Octal`]: https://doc.rust-lang.org/nightly/std/fmt/trait.Octal.html
|
||||
[`ToFixed`]: https://docs.rs/fixed/0.4.2/fixed/traits/trait.ToFixed.html
|
||||
[`U12`]: https://docs.rs/fixed/0.4.2/fixed/types/extra/type.U12.html
|
||||
[`U20F12`]: https://docs.rs/fixed/0.4.2/fixed/types/type.U20F12.html
|
||||
[`UpperHex`]: https://doc.rust-lang.org/nightly/std/fmt/trait.UpperHex.html
|
||||
[`f16`]: https://docs.rs/half/^1/half/struct.f16.html
|
||||
[`frac::U12`]: https://docs.rs/fixed/0.4.2/fixed/frac/type.U12.html
|
||||
[`from_fixed`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI8.html#method.from_fixed
|
||||
[`from_num`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI32.html#method.from_num
|
||||
[`from_str_binary`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI32.html#method.from_str_binary
|
||||
[`from_str_hex`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI32.html#method.from_str_hex
|
||||
[`from_str_octal`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI32.html#method.from_str_octal
|
||||
[`to_num`]: https://docs.rs/fixed/0.4.2/fixed/struct.FixedI32.html#method.to_num
|
||||
[const generics]: https://github.com/rust-lang/rust/issues/44580
|
||||
|
|
|
@ -18,9 +18,9 @@ This module reexports items from the [*typenum* crate].
|
|||
|
||||
[*typenum* crate]: https://crates.io/crates/typenum
|
||||
*/
|
||||
#![deprecated(since = "0.4.3", note = "replaced by fixed::types::extra")]
|
||||
#![deprecated(since = "0.4.3", note = "replaced by `fixed::types::extra`")]
|
||||
|
||||
#[deprecated(since = "0.4.3", note = "replaced by types in fixed::types::extra")]
|
||||
#[deprecated(since = "0.4.3")]
|
||||
pub use crate::types::extra::{
|
||||
Diff, IsLessOrEqual, True, Unsigned, U0, U1, U10, U100, U101, U102, U103, U104, U105, U106,
|
||||
U107, U108, U109, U11, U110, U111, U112, U113, U114, U115, U116, U117, U118, U119, U12, U120,
|
||||
|
@ -31,5 +31,5 @@ pub use crate::types::extra::{
|
|||
U73, U74, U75, U76, U77, U78, U79, U8, U80, U81, U82, U83, U84, U85, U86, U87, U88, U89, U9,
|
||||
U90, U91, U92, U93, U94, U95, U96, U97, U98, U99,
|
||||
};
|
||||
#[deprecated(since = "0.4.3", note = "replaced by types in fixed::types::extra")]
|
||||
#[deprecated(since = "0.4.3")]
|
||||
pub use typenum::IsGreaterOrEqual;
|
||||
|
|
62
src/lib.rs
62
src/lib.rs
|
@ -45,16 +45,23 @@ fixed-point numbers.
|
|||
Various conversion methods are available:
|
||||
|
||||
* All lossless infallible conversions between fixed-point numbers
|
||||
and numeric primitives are implemented. That is, you can use
|
||||
[`From`] or [`Into`] for the conversions that always work without
|
||||
losing any bits.
|
||||
* For infallible conversions that are not lossless because the
|
||||
source type may have more fractional bits than the destination
|
||||
type, [`LossyFrom`] and [`LossyInto`] can be used; these will
|
||||
truncate any excess fractional bits in the source value.
|
||||
* Checked conversions are provided between all types using the
|
||||
[`FromFixed`] and [`ToFixed`] traits, or using the inherent methods
|
||||
in the fixed-point types themselves.
|
||||
and numeric primitives are implemented. You can use [`From`] or
|
||||
[`Into`] for conversions that always work without losing any bits.
|
||||
* For lossy infallible conversions between fixed-point numbers and
|
||||
numeric primitives, where the source type may have more fractional
|
||||
bits than the destination type, the [`LossyFrom`] and
|
||||
[`LossyInto`] traits can be used. Excess fractional bits are
|
||||
truncated.
|
||||
* Checked conversions are provided between fixed-point numbers and
|
||||
numeric primitives using the [`FromFixed`] and [`ToFixed`] traits,
|
||||
or using the [`from_num`] and [`to_num`] methods.
|
||||
* Fixed-point numbers can be parsed from decimal strings using
|
||||
[`FromStr`], or from binary, octal or hexadecimal using the
|
||||
[`from_str_binary`], [`from_str_octal`] or [`from_str_hex`]
|
||||
methods. The result is rounded to the nearest, ties to even.
|
||||
* Fixed-point numbers can be converted to strings using [`Display`],
|
||||
[`Binary`], [`Octal`], [`LowerHex`] and [`UpperHex`]. The output
|
||||
is rounded to the nearest, ties to even.
|
||||
|
||||
## Quick examples
|
||||
|
||||
|
@ -80,31 +87,31 @@ all combinations of integer and fractional bits adding up to a total
|
|||
of eight, 16, 32, 64 or 128 bits.
|
||||
|
||||
```rust
|
||||
// −8 ≤ I4F4 < 8 with steps of 1/16 (about 0.06)
|
||||
// −8 ≤ I4F4 < 8 with steps of 1/16 (~0.06)
|
||||
use fixed::types::I4F4;
|
||||
let a = I4F4::from_num(1);
|
||||
// multiplication and division by integers are possible
|
||||
let ans1 = a / 5 * 17;
|
||||
// 1 / 5 × 17 = 3 2/5 (3.4), but we get 3 3/16 (≈3.2)
|
||||
// 1 / 5 × 17 = 3 2/5 (3.4), but we get 3 3/16 (~3.2)
|
||||
assert_eq!(ans1, I4F4::from_bits((3 << 4) + 3));
|
||||
assert_eq!(ans1.to_string(), "3.2");
|
||||
|
||||
// −8 ≤ I4F12 < 8 with steps of 1/4096 (about 0.0002)
|
||||
// −8 ≤ I4F12 < 8 with steps of 1/4096 (~0.0002)
|
||||
use fixed::types::I4F12;
|
||||
let wider_a = I4F12::from(a);
|
||||
let wider_ans = wider_a / 5 * 17;
|
||||
let ans2 = I4F4::from_num(wider_ans);
|
||||
// now the answer is the much closer 3 6/16 (≈3.4)
|
||||
// now the answer is the much closer 3 6/16 (~3.4)
|
||||
assert_eq!(ans2, I4F4::from_bits((3 << 4) + 6));
|
||||
assert_eq!(ans2.to_string(), "3.4");
|
||||
```
|
||||
|
||||
The second example shows some precision and conversion issues. The low
|
||||
precision of `a` means that `a / 5` is 3⁄16 instead of 1⁄5, leading to
|
||||
an inaccurate result `ans1` = 3 3⁄16 (3.19). With a higher precision,
|
||||
an inaccurate result `ans1` = 3 3⁄16 (~3.2). With a higher precision,
|
||||
we get `wider_a / 5` equal to 819⁄4096, leading to a more accurate
|
||||
intermediate result `wider_ans` = 3 1635⁄4096. When we convert back to
|
||||
four fractional bits, we get `ans2` = 3 6⁄16 (3.38).
|
||||
four fractional bits, we get `ans2` = 3 6⁄16 (~3.4).
|
||||
|
||||
Note that we can convert from [`I4F4`] to [`I4F12`] using [`From`], as
|
||||
the target type has the same number of integer bits and a larger
|
||||
|
@ -122,13 +129,6 @@ it in your crate, add it as a dependency inside [*Cargo.toml*]:
|
|||
fixed = "0.4.2"
|
||||
```
|
||||
|
||||
If you are using the 2015 Rust edition, you also need to declare it by
|
||||
adding this to your crate root (usually *lib.rs* or *main.rs*):
|
||||
|
||||
```rust
|
||||
extern crate fixed;
|
||||
```
|
||||
|
||||
The *fixed* crate requires rustc version 1.34.0 or later.
|
||||
|
||||
## Optional features
|
||||
|
@ -174,6 +174,8 @@ additional terms or conditions.
|
|||
[*typenum* crate]: https://crates.io/crates/typenum
|
||||
[LICENSE-APACHE]: https://www.apache.org/licenses/LICENSE-2.0
|
||||
[LICENSE-MIT]: https://opensource.org/licenses/MIT
|
||||
[`Binary`]: https://doc.rust-lang.org/nightly/std/fmt/trait.Binary.html
|
||||
[`Display`]: https://doc.rust-lang.org/nightly/std/fmt/trait.Display.html
|
||||
[`FixedI128`]: struct.FixedI128.html
|
||||
[`FixedI16`]: struct.FixedI16.html
|
||||
[`FixedI32`]: struct.FixedI32.html
|
||||
|
@ -185,6 +187,7 @@ additional terms or conditions.
|
|||
[`FixedU64`]: struct.FixedU64.html
|
||||
[`FixedU8`]: struct.FixedU8.html
|
||||
[`FromFixed`]: traits/trait.FromFixed.html
|
||||
[`FromStr`]: https://doc.rust-lang.org/nightly/std/str/trait.FromStr.html
|
||||
[`From`]: https://doc.rust-lang.org/nightly/std/convert/trait.From.html
|
||||
[`I20F12`]: types/type.I20F12.html
|
||||
[`I4F12`]: types/type.I4F12.html
|
||||
|
@ -192,11 +195,18 @@ additional terms or conditions.
|
|||
[`Into`]: https://doc.rust-lang.org/nightly/std/convert/trait.Into.html
|
||||
[`LossyFrom`]: traits/trait.LossyFrom.html
|
||||
[`LossyInto`]: traits/trait.LossyInto.html
|
||||
[`LowerHex`]: https://doc.rust-lang.org/nightly/std/fmt/trait.LowerHex.html
|
||||
[`Octal`]: https://doc.rust-lang.org/nightly/std/fmt/trait.Octal.html
|
||||
[`ToFixed`]: traits/trait.ToFixed.html
|
||||
[`U20F12`]: types/type.U20F12.html
|
||||
[`f16`]: https://docs.rs/half/^1/half/struct.f16.html
|
||||
[`U12`]: types/extra/type.U12.html
|
||||
[`from_num`]: struct.FixedI8.html#method.from_num
|
||||
[`U20F12`]: types/type.U20F12.html
|
||||
[`UpperHex`]: https://doc.rust-lang.org/nightly/std/fmt/trait.UpperHex.html
|
||||
[`f16`]: https://docs.rs/half/^1/half/struct.f16.html
|
||||
[`from_num`]: struct.FixedI32.html#method.from_num
|
||||
[`from_str_binary`]: struct.FixedI32.html#method.from_str_binary
|
||||
[`from_str_hex`]: struct.FixedI32.html#method.from_str_hex
|
||||
[`from_str_octal`]: struct.FixedI32.html#method.from_str_octal
|
||||
[`to_num`]: struct.FixedI32.html#method.to_num
|
||||
[const generics]: https://github.com/rust-lang/rust/issues/44580
|
||||
*/
|
||||
#![no_std]
|
||||
|
|
|
@ -17,182 +17,182 @@ macro_rules! fixed_deprecated {
|
|||
($Fixed:ident($Inner:ty)) => {
|
||||
/// Creates a fixed-point number from another number.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `from_num`")]
|
||||
pub fn from_fixed<Src: ToFixed>(src: Src) -> $Fixed<Frac> {
|
||||
Self::from_num(src)
|
||||
}
|
||||
|
||||
/// Converts a fixed-point number to another number.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by to_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `to_num`")]
|
||||
pub fn to_fixed<Dst: FromFixed>(self) -> Dst {
|
||||
self.to_num()
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `from_num`")]
|
||||
pub fn from_int<Src: ToFixed>(src: Src) -> $Fixed<Frac> {
|
||||
Self::from_num(src)
|
||||
}
|
||||
|
||||
/// Converts a fixed-point number to another number.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by to_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `to_num`")]
|
||||
pub fn to_int<Dst: FromFixed>(self) -> Dst {
|
||||
self.to_num()
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `from_num`")]
|
||||
pub fn from_float<Src: ToFixed>(src: Src) -> $Fixed<Frac> {
|
||||
Self::from_num(src)
|
||||
}
|
||||
|
||||
/// Converts a fixed-point number to another number.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by to_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `to_num`")]
|
||||
pub fn to_float<Dst: FromFixed>(self) -> Dst {
|
||||
self.to_num()
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number if it fits.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by checked_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `checked_from_num`")]
|
||||
pub fn checked_from_fixed<Src: ToFixed>(src: Src) -> Option<$Fixed<Frac>> {
|
||||
Self::checked_from_num(src)
|
||||
}
|
||||
|
||||
/// Converts a fixed-point number to another number if it fits.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by checked_to_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `checked_to_num`")]
|
||||
pub fn checked_to_fixed<Dst: FromFixed>(self) -> Option<Dst> {
|
||||
self.checked_to_num()
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number if it fits.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by checked_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `checked_from_num`")]
|
||||
pub fn checked_from_int<Src: ToFixed>(src: Src) -> Option<$Fixed<Frac>> {
|
||||
Self::checked_from_num(src)
|
||||
}
|
||||
|
||||
/// Converts a fixed-point number to another number if it fits.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by checked_to_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `checked_to_num`")]
|
||||
pub fn checked_to_int<Dst: FromFixed>(self) -> Option<Dst> {
|
||||
self.checked_to_num()
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number if it fits.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by checked_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `checked_from_num`")]
|
||||
pub fn checked_from_float<Src: ToFixed>(src: Src) -> Option<$Fixed<Frac>> {
|
||||
Self::checked_from_num(src)
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number if it fits.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by saturating_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `saturating_from_num`")]
|
||||
pub fn saturating_from_fixed<Src: ToFixed>(src: Src) -> $Fixed<Frac> {
|
||||
Self::saturating_from_num(src)
|
||||
}
|
||||
|
||||
/// Converts a fixed-point number to another number if it fits.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by saturating_to_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `saturating_to_num`")]
|
||||
pub fn saturating_to_fixed<Dst: FromFixed>(self) -> Dst {
|
||||
self.saturating_to_num()
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number if it fits.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by saturating_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `saturating_from_num`")]
|
||||
pub fn saturating_from_int<Src: ToFixed>(src: Src) -> $Fixed<Frac> {
|
||||
Self::saturating_from_num(src)
|
||||
}
|
||||
|
||||
/// Converts a fixed-point number to another number if it fits.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by saturating_to_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `saturating_to_num`")]
|
||||
pub fn saturating_to_int<Dst: FromFixed>(self) -> Dst {
|
||||
self.saturating_to_num()
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number if it fits.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by saturating_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `saturating_from_num`")]
|
||||
pub fn saturating_from_float<Src: ToFixed>(src: Src) -> $Fixed<Frac> {
|
||||
Self::saturating_from_num(src)
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number if it fits.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by wrapping_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `wrapping_from_num`")]
|
||||
pub fn wrapping_from_fixed<Src: ToFixed>(src: Src) -> $Fixed<Frac> {
|
||||
Self::wrapping_from_num(src)
|
||||
}
|
||||
|
||||
/// Converts a fixed-point number to another number if it fits.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by wrapping_to_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `wrapping_to_num`")]
|
||||
pub fn wrapping_to_fixed<Dst: FromFixed>(self) -> Dst {
|
||||
self.wrapping_to_num()
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number if it fits.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by wrapping_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `wrapping_from_num`")]
|
||||
pub fn wrapping_from_int<Src: ToFixed>(src: Src) -> $Fixed<Frac> {
|
||||
Self::wrapping_from_num(src)
|
||||
}
|
||||
|
||||
/// Converts a fixed-point number to another number if it fits.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by wrapping_to_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `wrapping_to_num`")]
|
||||
pub fn wrapping_to_int<Dst: FromFixed>(self) -> Dst {
|
||||
self.wrapping_to_num()
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number if it fits.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by wrapping_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `wrapping_from_num`")]
|
||||
pub fn wrapping_from_float<Src: ToFixed>(src: Src) -> $Fixed<Frac> {
|
||||
Self::wrapping_from_num(src)
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number if it fits.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by overflowing_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `overflowing_from_num`")]
|
||||
pub fn overflowing_from_fixed<Src: ToFixed>(src: Src) -> ($Fixed<Frac>, bool) {
|
||||
Self::overflowing_from_num(src)
|
||||
}
|
||||
|
||||
/// Converts a fixed-point number to another number if it fits.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by overflowing_to_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `overflowing_to_num`")]
|
||||
pub fn overflowing_to_fixed<Dst: FromFixed>(self) -> (Dst, bool) {
|
||||
self.overflowing_to_num()
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number if it fits.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by overflowing_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `overflowing_from_num`")]
|
||||
pub fn overflowing_from_int<Src: ToFixed>(src: Src) -> ($Fixed<Frac>, bool) {
|
||||
Self::overflowing_from_num(src)
|
||||
}
|
||||
|
||||
/// Converts a fixed-point number to another number if it fits.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by overflowing_to_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `overflowing_to_num`")]
|
||||
pub fn overflowing_to_int<Dst: FromFixed>(self) -> (Dst, bool) {
|
||||
self.overflowing_to_num()
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number if it fits.
|
||||
#[inline]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by overflowing_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `overflowing_from_num`")]
|
||||
pub fn overflowing_from_float<Src: ToFixed>(src: Src) -> ($Fixed<Frac>, bool) {
|
||||
Self::overflowing_from_num(src)
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ pub trait Int: Copy {}
|
|||
pub trait Float: Copy {}
|
||||
|
||||
/// This trait is implemented for all the fixed-point types.
|
||||
#[deprecated(since = "0.4.2", note = "use traits::Fixed instead")]
|
||||
#[deprecated(since = "0.4.2", note = "use `traits::Fixed` instead")]
|
||||
pub trait Fixed: TraitsFixed {}
|
||||
|
||||
impl Int for i8 {}
|
||||
|
|
|
@ -87,7 +87,7 @@ depending on the crate’s [optional features].
|
|||
"
|
||||
}
|
||||
|
||||
/// This trait provides common methods to all fixed-point numbers.
|
||||
/// This trait provides methods common to all fixed-point numbers.
|
||||
///
|
||||
/// It can be helpful when writing generic code that makes use of
|
||||
/// fixed-point numbers.
|
||||
|
@ -755,140 +755,149 @@ where
|
|||
fn overflowing_shr(self, rhs: u32) -> (Self, bool);
|
||||
|
||||
/// Multiplication by an integer.
|
||||
#[deprecated(since = "0.4.1", note = "use `Mul<Self::Bits>` trait instead")]
|
||||
#[deprecated(
|
||||
since = "0.4.1",
|
||||
note = "use `lhs * rhs` instead of `lhs.mul_int(rhs)`"
|
||||
)]
|
||||
#[inline]
|
||||
fn mul_int(self, rhs: Self::Bits) -> Self {
|
||||
self * rhs
|
||||
}
|
||||
|
||||
/// Division by an integer.
|
||||
#[deprecated(since = "0.4.1", note = "use `Div<Self::Bits>` trait instead")]
|
||||
#[deprecated(
|
||||
since = "0.4.1",
|
||||
note = "use `lhs / rhs` instead of `lhs.div_int(rhs)`"
|
||||
)]
|
||||
#[inline]
|
||||
fn div_int(self, rhs: Self::Bits) -> Self {
|
||||
self / rhs
|
||||
}
|
||||
|
||||
/// Remainder for division by an integer.
|
||||
#[deprecated(since = "0.4.1", note = "use `Rem<Self::Bits>` trait instead")]
|
||||
#[deprecated(
|
||||
since = "0.4.1",
|
||||
note = "use `lhs % rhs` instead of `lhs.rem_int(rhs)`"
|
||||
)]
|
||||
#[inline]
|
||||
fn rem_int(self, rhs: Self::Bits) -> Self {
|
||||
self % rhs
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number.
|
||||
#[deprecated(since = "0.4.2", note = "replaced by from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `from_num`")]
|
||||
#[inline]
|
||||
fn from_int<Src: ToFixed>(src: Src) -> Self {
|
||||
src.to_fixed()
|
||||
}
|
||||
|
||||
/// Converts a fixed-point number to another number.
|
||||
#[deprecated(since = "0.4.2", note = "replaced by from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `to_num`")]
|
||||
#[inline]
|
||||
fn to_int<Dst: FromFixed>(self) -> Dst {
|
||||
Dst::from_fixed(self)
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number.
|
||||
#[deprecated(since = "0.4.2", note = "replaced by from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `from_num`")]
|
||||
#[inline]
|
||||
fn from_float<Src: ToFixed>(src: Src) -> Self {
|
||||
src.to_fixed()
|
||||
}
|
||||
|
||||
/// Converts a fixed-point number to another number.
|
||||
#[deprecated(since = "0.4.2", note = "replaced by from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `to_num`")]
|
||||
#[inline]
|
||||
fn to_float<Dst: FromFixed>(self) -> Dst {
|
||||
Dst::from_fixed(self)
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number.
|
||||
#[deprecated(since = "0.4.2", note = "replaced by checked_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `checked_from_num`")]
|
||||
#[inline]
|
||||
fn checked_from_int<Src: ToFixed>(src: Src) -> Option<Self> {
|
||||
src.checked_to_fixed()
|
||||
}
|
||||
|
||||
/// Converts a fixed-point number to another number.
|
||||
#[deprecated(since = "0.4.2", note = "replaced by checked_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `checked_to_num`")]
|
||||
#[inline]
|
||||
fn checked_to_int<Dst: FromFixed>(self) -> Option<Dst> {
|
||||
Dst::checked_from_fixed(self)
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number.
|
||||
#[deprecated(since = "0.4.2", note = "replaced by checked_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `checked_from_num`")]
|
||||
#[inline]
|
||||
fn checked_from_float<Src: ToFixed>(src: Src) -> Option<Self> {
|
||||
src.checked_to_fixed()
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number.
|
||||
#[deprecated(since = "0.4.2", note = "replaced by saturating_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `saturating_from_num`")]
|
||||
#[inline]
|
||||
fn saturating_from_int<Src: ToFixed>(src: Src) -> Self {
|
||||
src.saturating_to_fixed()
|
||||
}
|
||||
|
||||
/// Converts a fixed-point number to another number.
|
||||
#[deprecated(since = "0.4.2", note = "replaced by saturating_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `saturating_to_num`")]
|
||||
#[inline]
|
||||
fn saturating_to_int<Dst: FromFixed>(self) -> Dst {
|
||||
Dst::saturating_from_fixed(self)
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number.
|
||||
#[deprecated(since = "0.4.2", note = "replaced by saturating_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `saturating_from_num`")]
|
||||
#[inline]
|
||||
fn saturating_from_float<Src: ToFixed>(src: Src) -> Self {
|
||||
src.saturating_to_fixed()
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number.
|
||||
#[deprecated(since = "0.4.2", note = "replaced by wrapping_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `wrapping_from_num`")]
|
||||
#[inline]
|
||||
fn wrapping_from_int<Src: ToFixed>(src: Src) -> Self {
|
||||
src.wrapping_to_fixed()
|
||||
}
|
||||
|
||||
/// Converts a fixed-point number to another number.
|
||||
#[deprecated(since = "0.4.2", note = "replaced by wrapping_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `wrapping_to_num`")]
|
||||
#[inline]
|
||||
fn wrapping_to_int<Dst: FromFixed>(self) -> Dst {
|
||||
Dst::wrapping_from_fixed(self)
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number.
|
||||
#[deprecated(since = "0.4.2", note = "replaced by wrapping_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `wrapping_from_num`")]
|
||||
#[inline]
|
||||
fn wrapping_from_float<Src: ToFixed>(src: Src) -> Self {
|
||||
src.wrapping_to_fixed()
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number.
|
||||
#[deprecated(since = "0.4.2", note = "replaced by overflowing_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `overflowing_from_num`")]
|
||||
#[inline]
|
||||
fn overflowing_from_int<Src: ToFixed>(src: Src) -> (Self, bool) {
|
||||
src.overflowing_to_fixed()
|
||||
}
|
||||
|
||||
/// Converts a fixed-point number to another number.
|
||||
#[deprecated(since = "0.4.2", note = "replaced by overflowing_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `overflowing_to_num`")]
|
||||
#[inline]
|
||||
fn overflowing_to_int<Dst: FromFixed>(self) -> (Dst, bool) {
|
||||
Dst::overflowing_from_fixed(self)
|
||||
}
|
||||
|
||||
/// Creates a fixed-point number from another number.
|
||||
#[deprecated(since = "0.4.2", note = "replaced by overflowing_from_num")]
|
||||
#[deprecated(since = "0.4.2", note = "replaced by `overflowing_from_num`")]
|
||||
#[inline]
|
||||
fn overflowing_from_float<Src: ToFixed>(src: Src) -> (Self, bool) {
|
||||
src.overflowing_to_fixed()
|
||||
}
|
||||
}
|
||||
|
||||
/// This trait provides common methods to all signed fixed-point numbers.
|
||||
/// This trait provides methods common to all signed fixed-point numbers.
|
||||
pub trait FixedSigned: Fixed + Neg<Output = Self> {
|
||||
/// Returns the absolute value.
|
||||
fn abs(self) -> Self;
|
||||
|
@ -950,7 +959,7 @@ pub trait FixedSigned: Fixed + Neg<Output = Self> {
|
|||
fn is_negative(self) -> bool;
|
||||
}
|
||||
|
||||
/// This trait provides common methods to all unsigned fixed-point numbers.
|
||||
/// This trait provides methods common to all unsigned fixed-point numbers.
|
||||
pub trait FixedUnsigned: Fixed {
|
||||
/// Returns [`true`][`bool`] if the fixed-point number is
|
||||
/// 2<sup><i>k</i></sup> for some integer <i>k</i>.
|
||||
|
|
|
@ -25,7 +25,7 @@ use crate::{
|
|||
|
||||
pub mod extra;
|
||||
|
||||
#[deprecated(since = "0.4.3", note = "replaced by types in fixed::types::extra")]
|
||||
#[deprecated(since = "0.4.3")]
|
||||
pub use crate::types::extra::{LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8};
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue