fixed/
traits.rs

1// Copyright © 2018–2026 Trevor Spiteri
2
3// This library is free software: you can redistribute it and/or
4// modify it under the terms of either
5//
6//   * the Apache License, Version 2.0 or
7//   * the MIT License
8//
9// at your option.
10//
11// You should have recieved copies of the Apache License and the MIT
12// License along with the library. If not, see
13// <https://www.apache.org/licenses/LICENSE-2.0> and
14// <https://opensource.org/licenses/MIT>.
15
16/*!
17Traits for conversions and for generic use of fixed-point numbers.
18*/
19
20#![allow(deprecated)]
21
22use crate::helpers::{Private, Sealed, Widest};
23pub use crate::traits_bits::{
24    FixedBits, FixedBitsCast, FixedBitsOptionalArbitrary, FixedBitsOptionalBorsh,
25    FixedBitsOptionalNum, FixedBitsOptionalSerde,
26};
27use crate::types::extra::{LeEqU8, LeEqU16, LeEqU32, LeEqU64, LeEqU128, Unsigned};
28use crate::{
29    F128, F128Bits, FixedI8, FixedI16, FixedI32, FixedI64, FixedI128, FixedU8, FixedU16, FixedU32,
30    FixedU64, FixedU128, ParseFixedError,
31};
32#[cfg(feature = "arbitrary")]
33use arbitrary::Arbitrary;
34#[cfg(feature = "borsh")]
35use borsh::{BorshDeserialize, BorshSerialize};
36use bytemuck::{Contiguous, Pod, TransparentWrapper};
37use core::fmt::{Binary, Debug, Display, LowerExp, LowerHex, Octal, UpperExp, UpperHex};
38use core::hash::Hash;
39use core::iter::{Product, Sum};
40use core::num::{NonZero, TryFromIntError};
41use core::ops::{
42    Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
43    Mul, MulAssign, Neg, Not, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign,
44};
45use core::str::FromStr;
46use half::{bf16 as half_bf16, f16 as half_f16};
47#[cfg(feature = "num-traits")]
48use num_traits::{
49    bounds::Bounded,
50    cast::{FromPrimitive, ToPrimitive},
51    float::FloatConst,
52    identities::Zero,
53    ops::checked::{
54        CheckedAdd, CheckedDiv, CheckedMul, CheckedNeg, CheckedRem, CheckedShl, CheckedShr,
55        CheckedSub,
56    },
57    ops::inv::Inv,
58    ops::overflowing::{OverflowingAdd, OverflowingMul, OverflowingSub},
59    ops::saturating::{SaturatingAdd, SaturatingMul, SaturatingSub},
60    ops::wrapping::{WrappingAdd, WrappingMul, WrappingNeg, WrappingShl, WrappingShr, WrappingSub},
61};
62#[cfg(feature = "serde")]
63use serde::{de::Deserialize, ser::Serialize};
64
65#[cfg(not(feature = "arbitrary"))]
66/// This trait is used to provide supertraits to the [`Fixed`] trait depending
67/// on the crate’s [optional features], and should not be used directly.
68///
69/// If the `arbitrary` feature is enabled, [`Arbitrary`] is a supertrait of
70/// [`Fixed`].
71///
72/// [optional features]: crate#optional-features
73pub trait FixedOptionalArbitrary: Sealed {}
74
75#[cfg(feature = "arbitrary")]
76/// This trait is used to provide supertraits to the [`Fixed`] trait depending
77/// on the crate’s [optional features], and should not be used directly.
78///
79/// If the `arbitrary` feature is enabled, [`Arbitrary`] is a supertrait of
80/// [`Fixed`].
81///
82/// [optional features]: crate#optional-features
83pub trait FixedOptionalArbitrary: Sealed
84where
85    Self: for<'a> Arbitrary<'a>,
86{
87}
88
89#[cfg(not(feature = "borsh"))]
90/// This trait is used to provide supertraits to the [`Fixed`] trait depending
91/// on the crate’s [optional features], and should not be used directly.
92///
93/// If the `borsh` experimental feature is enabled, [`BorshSerialize`] and
94/// [`BorshDeserialize`] are supertraits of [`Fixed`].
95///
96/// [optional features]: crate#optional-features
97pub trait FixedOptionalBorsh: Sealed {}
98
99#[cfg(feature = "borsh")]
100/// This trait is used to provide supertraits to the [`Fixed`] trait depending
101/// on the crate’s [optional features], and should not be used directly.
102///
103/// If the `borsh` experimental feature is enabled, [`BorshSerialize`] and
104/// [`BorshDeserialize`] are supertraits of [`Fixed`].
105///
106/// [optional features]: crate#optional-features
107pub trait FixedOptionalBorsh: Sealed
108where
109    Self: BorshSerialize + BorshDeserialize,
110{
111}
112
113#[cfg(not(feature = "num-traits"))]
114/// This trait is used to provide supertraits to the [`Fixed`] trait depending
115/// on the crate’s [optional features], and should not be used directly.
116///
117/// If the `num-traits` experimental feature is enabled, the following are
118/// supertraits of [`Fixed`]:
119///
120///   * [`Zero`]
121///   * [`Bounded`]
122///   * [`Inv`]
123///   * [`CheckedAdd`], [`CheckedSub`], [`CheckedNeg`],
124///     [`CheckedMul`], [`CheckedDiv`], [`CheckedRem`],
125///     [`CheckedShl`], [`CheckedShr`]
126///   * [`SaturatingAdd`], [`SaturatingSub`], [`SaturatingMul`]
127///   * [`WrappingAdd`], [`WrappingSub`], [`WrappingNeg`],
128///     [`WrappingMul`], [`WrappingShl`], [`WrappingShr`]
129///   * [`OverflowingAdd`], [`OverflowingSub`], [`OverflowingMul`]
130///   * [`ToPrimitive`], [`FromPrimitive`]
131///   * [`FloatConst`]
132///
133/// The following are *not* supertraits of [`Fixed`], even though they
134/// are implemented for fixed-point numbers where applicable:
135///
136///   * [`ConstZero`] because of conflicts with
137///     <code>[Fixed]::[ZERO][Fixed::ZERO]</code>
138///   * [`One`] and [`ConstOne`] because not all fixed-point numbers can
139///     represent the value 1
140///   * [`Num`] because it has [`One`] as a supertrait
141///   * [`MulAdd`], [`MulAddAssign`] because
142///     <code>[MulAdd][`MulAdd`]::[mul\_add][`mul_add`]</code>
143///     conflicts with
144///     <code>[Fixed]::[mul\_add][Fixed::mul_add]</code>
145///   * [`ToBytes`], [`FromBytes`] because of conflicts with
146///     <code>[Fixed]::[Bytes][Fixed::Bytes]</code> and [`Fixed`] methods
147///
148/// Similarly, [`Signed`] and [`Unsigned`] are *not* supertraits of
149/// [`FixedSigned`] and [`FixedUnsigned`] because they have [`Num`] as
150/// a supertrait.
151///
152/// [`ConstOne`]: num_traits::identities::ConstOne
153/// [`ConstZero`]: num_traits::identities::ConstZero
154/// [`FromBytes`]: num_traits::ops::bytes::FromBytes
155/// [`MulAddAssign`]: num_traits::ops::mul_add::MulAddAssign
156/// [`MulAdd`]: num_traits::ops::mul_add::MulAdd
157/// [`Num`]: num_traits::Num
158/// [`One`]: num_traits::identities::One
159/// [`Signed`]: num_traits::sign::Signed
160/// [`ToBytes`]: num_traits::ops::bytes::ToBytes
161/// [`Unsigned`]: num_traits::sign::Unsigned
162/// [`mul_add`]: num_traits::ops::mul_add::MulAdd::mul_add
163/// [optional features]: crate#optional-features
164pub trait FixedOptionalNum: Sealed {}
165
166#[cfg(feature = "num-traits")]
167/// This trait is used to provide supertraits to the [`Fixed`] trait depending
168/// on the crate’s [optional features], and should not be used directly.
169///
170/// If the `num-traits` experimental feature is enabled, the following are
171/// supertraits of [`Fixed`]:
172///
173///   * [`Zero`]
174///   * [`Bounded`]
175///   * [`Inv`]
176///   * [`CheckedAdd`], [`CheckedSub`], [`CheckedNeg`],
177///     [`CheckedMul`], [`CheckedDiv`], [`CheckedRem`],
178///     [`CheckedShl`], [`CheckedShr`]
179///   * [`SaturatingAdd`], [`SaturatingSub`], [`SaturatingMul`]
180///   * [`WrappingAdd`], [`WrappingSub`], [`WrappingNeg`],
181///     [`WrappingMul`], [`WrappingShl`], [`WrappingShr`]
182///   * [`OverflowingAdd`], [`OverflowingSub`], [`OverflowingMul`]
183///   * [`ToPrimitive`], [`FromPrimitive`]
184///   * [`FloatConst`]
185///
186/// The following are *not* supertraits of [`Fixed`], even though they
187/// are implemented for fixed-point numbers where applicable:
188///
189///   * [`ConstZero`] because of conflicts with
190///     <code>[Fixed]::[ZERO][Fixed::ZERO]</code>
191///   * [`One`] and [`ConstOne`] because not all fixed-point numbers can
192///     represent the value 1
193///   * [`Num`] because it has [`One`] as a supertrait
194///   * [`MulAdd`], [`MulAddAssign`] because
195///     <code>[MulAdd][`MulAdd`]::[mul\_add][`mul_add`]</code>
196///     conflicts with
197///     <code>[Fixed]::[mul\_add][Fixed::mul_add]</code>
198///   * [`ToBytes`], [`FromBytes`] because of conflicts with
199///     <code>[Fixed]::[Bytes][Fixed::Bytes]</code> and [`Fixed`] methods
200///
201/// Similarly, [`Signed`] and [`Unsigned`] are *not* supertraits of
202/// [`FixedSigned`] and [`FixedUnsigned`] because they have [`Num`] as
203/// a supertrait.
204///
205/// [`ConstOne`]: num_traits::identities::ConstOne
206/// [`ConstZero`]: num_traits::identities::ConstZero
207/// [`FromBytes`]: num_traits::ops::bytes::FromBytes
208/// [`MulAddAssign`]: num_traits::ops::mul_add::MulAddAssign
209/// [`MulAdd`]: num_traits::ops::mul_add::MulAdd
210/// [`Num`]: num_traits::Num
211/// [`One`]: num_traits::identities::One
212/// [`Signed`]: num_traits::sign::Signed
213/// [`ToBytes`]: num_traits::ops::bytes::ToBytes
214/// [`Unsigned`]: num_traits::sign::Unsigned
215/// [`mul_add`]: num_traits::ops::mul_add::MulAdd::mul_add
216/// [optional features]: crate#optional-features
217pub trait FixedOptionalNum: Sealed
218where
219    Self: Zero + Bounded + Inv,
220    Self: CheckedAdd + CheckedSub + CheckedNeg + CheckedMul,
221    Self: CheckedDiv + CheckedRem + CheckedShl + CheckedShr,
222    Self: SaturatingAdd + SaturatingSub + SaturatingMul,
223    Self: WrappingAdd + WrappingSub + WrappingNeg + WrappingMul,
224    Self: WrappingShl + WrappingShr,
225    Self: OverflowingAdd + OverflowingSub + OverflowingMul,
226    Self: ToPrimitive + FromPrimitive + FloatConst,
227{
228}
229
230#[cfg(not(feature = "serde"))]
231/// This trait is used to provide supertraits to the [`Fixed`] trait depending
232/// on the crate’s [optional features], and should not be used directly.
233///
234/// If the `serde` feature is enabled and the `serde-str` feature is disabled,
235/// [`Serialize`] and [`Deserialize`] are supertraits of [`Fixed`].
236///
237/// [optional features]: crate#optional-features
238pub trait FixedOptionalSerde: Sealed {}
239
240#[cfg(feature = "serde")]
241/// This trait is used to provide supertraits to the [`Fixed`] trait depending
242/// on the crate’s [optional features], and should not be used directly.
243///
244/// If the `serde` feature is enabled and the `serde-str` feature is disabled,
245/// [`Serialize`] and [`Deserialize`] are supertraits of [`Fixed`].
246///
247/// [optional features]: crate#optional-features
248pub trait FixedOptionalSerde: Sealed
249where
250    Self: Serialize + for<'de> Deserialize<'de>,
251{
252}
253
254#[cfg(not(feature = "nightly-float"))]
255/// This trait is used to provide supertraits to the [`Fixed`] trait depending
256/// on the crate’s [optional features], and should not be used directly.
257///
258/// If the `nightly-float` feature is enabled, [`PartialOrd<f16>`][PartialOrd]
259/// and [`PartialOrd<f128>`][PartialOrd] are supertraits of [`Fixed`].
260///
261/// [optional features]: crate#optional-features
262pub trait FixedOptionalNightlyFloat: Sealed {}
263
264#[cfg(feature = "nightly-float")]
265/// This trait is used to provide supertraits to the [`Fixed`] trait depending
266/// on the crate’s [optional features], and should not be used directly.
267///
268/// If the `nightly-float` feature is enabled, [`PartialOrd<f16>`][PartialOrd]
269/// and [`PartialOrd<f128>`][PartialOrd] are supertraits of [`Fixed`].
270///
271/// [optional features]: crate#optional-features
272pub trait FixedOptionalNightlyFloat: Sealed
273where
274    Self: PartialOrd<f16> + PartialOrd<f128>,
275{
276}
277
278/// This trait is used to provide supertraits to the [`Fixed`] trait depending
279/// on the crate’s [optional features], and should not be used directly.
280///
281/// [optional features]: crate#optional-features
282pub trait FixedOptionalFeatures: Sealed
283where
284    Self: FixedOptionalArbitrary,
285    Self: FixedOptionalBorsh,
286    Self: FixedOptionalNum,
287    Self: FixedOptionalSerde,
288    Self: FixedOptionalNightlyFloat,
289{
290}
291
292/// This trait provides methods common to all fixed-point numbers.
293///
294/// It can be helpful when writing generic code that makes use of
295/// fixed-point numbers. For methods only available on signed
296/// fixed-point numbers, use the [`FixedSigned`] trait instead, and
297/// for methods only available on unsigned fixed-point numbers, use
298/// [`FixedUnsigned`].
299///
300/// This trait is sealed and cannot be implemented for more types; it
301/// is implemented for [`FixedI8`], [`FixedI16`], [`FixedI32`],
302/// [`FixedI64`], [`FixedI128`], [`FixedU8`], [`FixedU16`],
303/// [`FixedU32`], [`FixedU64`], and [`FixedU128`].
304///
305/// # Examples
306///
307/// ```rust
308/// use fixed::traits::Fixed;
309/// use fixed::types::{I8F8, I16F16};
310///
311/// fn checked_add_twice<F: Fixed>(lhs: F, rhs: F) -> Option<F> {
312///     lhs.checked_add(rhs)?.checked_add(rhs)
313/// }
314///
315/// let val1 = checked_add_twice(I8F8::from_num(5), Fixed::from_num(1.75));
316/// assert_eq!(val1, Some(Fixed::from_num(8.5)));
317/// // can use with different fixed-point type
318/// let val2 = checked_add_twice(I16F16::from_num(5), Fixed::from_num(1.75));
319/// assert_eq!(val2, Some(Fixed::from_num(8.5)));
320/// ```
321///
322/// The following example fails to compile, since the compiler cannot
323/// infer that 500 in the `checked_mul_int` call is of type `F::Bits`.
324///
325/// ```rust,compile_fail
326/// use fixed::traits::Fixed;
327///
328/// fn checked_add_times_500<F: Fixed>(lhs: F, rhs: F) -> Option<F> {
329///     rhs.checked_mul_int(500)?.checked_add(lhs)
330/// }
331/// ```
332///
333/// One way to fix this is to add a trait bound indicating that any
334/// [`u16`] (which can represent 500) can be converted into `F::Bits`.
335///
336/// ```rust
337/// use fixed::traits::Fixed;
338/// use fixed::types::U12F4;
339///
340/// fn checked_add_times_500<F: Fixed>(lhs: F, rhs: F) -> Option<F>
341/// where
342///     u16: Into<F::Bits>,
343/// {
344///     rhs.checked_mul_int(500.into())?.checked_add(lhs)
345/// }
346///
347/// let val = checked_add_times_500(U12F4::from_num(0.25), Fixed::from_num(1.5));
348/// assert_eq!(val, Some(Fixed::from_num(750.25)));
349/// ```
350///
351/// While this works in most cases, [`u16`] cannot be converted to
352/// [`i16`], even if the value 500 does fit in [`i16`], so that the
353/// following example would fail to compile.
354///
355/// ```rust,compile_fail
356/// use fixed::traits::Fixed;
357/// use fixed::types::I12F4;
358///
359/// fn checked_add_times_500<F: Fixed>(lhs: F, rhs: F) -> Option<F>
360/// where
361///     u16: Into<F::Bits>,
362/// {
363///     rhs.checked_mul_int(500.into())?.checked_add(lhs)
364/// }
365///
366/// // I12F4::Bits is i16, and u16 does not implement Into<i16>
367/// let val = checked_add_times_500(I12F4::from_num(0.25), Fixed::from_num(1.5));
368/// # let _ = val;
369/// ```
370///
371/// We can use [`TryFrom`] to fix this, as we know that
372/// `F::Bits::try_from(500_u16)` will work for both [`u16`] and
373/// [`i16`]. (The function will always return [`None`] when `F::Bits`
374/// is [`u8`] or [`i8`].)
375///
376/// ```rust
377/// use fixed::traits::Fixed;
378/// use fixed::types::I12F4;
379///
380/// fn checked_add_times_500<F: Fixed>(lhs: F, rhs: F) -> Option<F>
381/// where
382///     u16: TryInto<F::Bits>,
383/// {
384///     rhs.checked_mul_int(500.try_into().ok()?)?.checked_add(lhs)
385/// }
386///
387/// let val = checked_add_times_500(I12F4::from_num(0.25), Fixed::from_num(1.5));
388/// assert_eq!(val, Some(Fixed::from_num(750.25)));
389/// ```
390///
391/// [`TryFrom`]: core::convert::TryFrom
392pub trait Fixed
393where
394    Self: Default + Hash + Ord,
395    Self: Contiguous + Pod + TransparentWrapper<<Self as Fixed>::Bits>,
396    Self: Debug + Display + LowerExp + UpperExp,
397    Self: Binary + Octal + LowerHex + UpperHex,
398    Self: FromStr<Err = ParseFixedError>,
399    Self: FromFixed + ToFixed,
400    Self: Add<Output = Self> + AddAssign,
401    Self: Sub<Output = Self> + SubAssign,
402    Self: Mul<Output = Self> + MulAssign,
403    Self: Div<Output = Self> + DivAssign,
404    Self: Rem<Output = Self> + RemAssign,
405    Self: Mul<<Self as Fixed>::Bits, Output = Self> + MulAssign<<Self as Fixed>::Bits>,
406    Self: Div<<Self as Fixed>::Bits, Output = Self> + DivAssign<<Self as Fixed>::Bits>,
407    Self: Rem<<Self as Fixed>::Bits, Output = Self> + RemAssign<<Self as Fixed>::Bits>,
408    Self: Rem<<Self as Fixed>::NonZeroBits, Output = Self>,
409    Self: RemAssign<<Self as Fixed>::NonZeroBits>,
410    Self: Not<Output = Self>,
411    Self: BitAnd<Output = Self> + BitAndAssign,
412    Self: BitOr<Output = Self> + BitOrAssign,
413    Self: BitXor<Output = Self> + BitXorAssign,
414    Self: Shl<u32, Output = Self> + ShlAssign<u32>,
415    Self: Shr<u32, Output = Self> + ShrAssign<u32>,
416    Self: Sum + Product,
417    Self: PartialOrd<i8> + PartialOrd<i16> + PartialOrd<i32>,
418    Self: PartialOrd<i64> + PartialOrd<i128> + PartialOrd<isize>,
419    Self: PartialOrd<u8> + PartialOrd<u16> + PartialOrd<u32>,
420    Self: PartialOrd<u64> + PartialOrd<u128> + PartialOrd<usize>,
421    Self: PartialOrd<half_f16> + PartialOrd<half_bf16>,
422    Self: PartialOrd<f32> + PartialOrd<f64>,
423    Self: PartialOrd<F128> + PartialOrd<F128Bits>,
424    Self: FixedOptionalFeatures,
425    Self: Sealed,
426{
427    /// The primitive integer underlying type.
428    ///
429    /// # Examples
430    ///
431    /// ```rust
432    /// use fixed::traits::Fixed;
433    /// use fixed::types::I16F16;
434    /// // 32-bit DELTA is 0x0000_0001_i32
435    /// const DELTA_BITS: <I16F16 as Fixed>::Bits = I16F16::DELTA.to_bits();
436    /// assert_eq!(DELTA_BITS, 1i32);
437    /// ```
438    type Bits: FixedBits + From<Self::NonZeroBits>;
439
440    /// The non-zero wrapped version of [`Bits`].
441    ///
442    /// # Examples
443    ///
444    /// ```rust
445    /// use fixed::traits::Fixed;
446    /// use fixed::types::I16F16;
447    /// let val = I16F16::from_num(31);
448    /// let non_zero_5 = <I16F16 as Fixed>::NonZeroBits::new(5).unwrap();
449    /// assert_eq!(val % non_zero_5, val % 5);
450    /// ```
451    ///
452    /// [`Bits`]: Fixed::Bits
453    type NonZeroBits: TryFrom<Self::Bits, Error = TryFromIntError>;
454
455    /// A byte array with the same size as the type.
456    ///
457    /// # Examples
458    ///
459    /// ```rust
460    /// use fixed::traits::Fixed;
461    /// use fixed::types::I16F16;
462    /// // 32-bit DELTA is 0x0000_0001_i32
463    /// const DELTA_LE_BYTES: <I16F16 as Fixed>::Bytes = I16F16::DELTA.to_le_bytes();
464    /// assert_eq!(DELTA_LE_BYTES, 1i32.to_le_bytes());
465    /// ```
466    type Bytes;
467
468    /// The number of fractional bits as a compile-time [`Unsigned`] as provided
469    /// by the [*typenum* crate].
470    ///
471    /// <code>\<F as [Fixed]>::Frac::[U32]</code> is equivalent to
472    /// <code>\<F as [Fixed]>::[FRAC\_NBITS]</code>.
473    ///
474    /// `Frac` can be used as the generic parameter of fixed-point number types.
475    ///
476    /// # Examples
477    ///
478    /// ```rust
479    /// use fixed::traits::Fixed;
480    /// use fixed::types::extra::U16;
481    /// use fixed::{FixedI32, FixedI64};
482    /// type Fix1 = FixedI32::<U16>;
483    /// assert_eq!(Fix1::FRAC_NBITS, 16);
484    /// assert_eq!(Fix1::INT_NBITS, 32 - 16);
485    /// type Fix2 = FixedI64::<<Fix1 as Fixed>::Frac>;
486    /// assert_eq!(Fix2::FRAC_NBITS, 16);
487    /// assert_eq!(Fix2::INT_NBITS, 64 - 16);
488    /// ```
489    ///
490    /// [*typenum* crate]: https://crates.io/crates/typenum
491    /// [U32]: crate::types::extra::Unsigned::U32
492    /// [FRAC\_NBITS]: Fixed::FRAC_NBITS
493    type Frac: Unsigned;
494
495    /// A signed fixed-point number type with the same number of integer and
496    /// fractional bits as `Self`.
497    ///
498    /// If `Self` is signed, then `Self::Signed` is the same as `Self`.
499    ///
500    /// # Examples
501    ///
502    /// ```rust
503    /// use fixed::traits::Fixed;
504    /// use fixed::types::{I16F16, U16F16};
505    /// // I16F16::Signed is I16F16
506    /// assert_eq!(<I16F16 as Fixed>::Signed::FRAC_NBITS, I16F16::FRAC_NBITS);
507    /// assert_eq!(<I16F16 as Fixed>::Signed::INT_NBITS, I16F16::INT_NBITS);
508    /// assert_eq!(<I16F16 as Fixed>::Signed::IS_SIGNED, I16F16::IS_SIGNED);
509    /// // U16F16::Signed is I16F16
510    /// assert_eq!(<U16F16 as Fixed>::Signed::FRAC_NBITS, I16F16::FRAC_NBITS);
511    /// assert_eq!(<U16F16 as Fixed>::Signed::INT_NBITS, I16F16::INT_NBITS);
512    /// assert_eq!(<U16F16 as Fixed>::Signed::IS_SIGNED, I16F16::IS_SIGNED);
513    /// ```
514    ///
515    /// [I16F16]: crate::types::I16F16
516    /// [U16F16]: crate::types::U16F16
517    /// [types]: crate::types
518    type Signed: FixedSigned;
519
520    /// An unsigned fixed-point number type with the same number of integer and
521    /// fractional bits as `Self`.
522    ///
523    /// If `Self` is unsigned, then `Self::Unsigned` is the same as `Self`.
524    ///
525    /// # Examples
526    ///
527    /// ```rust
528    /// use fixed::traits::Fixed;
529    /// use fixed::types::{I16F16, U16F16};
530    /// // I16F16::Unsigned is U16F16
531    /// assert_eq!(<I16F16 as Fixed>::Unsigned::FRAC_NBITS, U16F16::FRAC_NBITS);
532    /// assert_eq!(<I16F16 as Fixed>::Unsigned::INT_NBITS, U16F16::INT_NBITS);
533    /// assert_eq!(<I16F16 as Fixed>::Unsigned::IS_SIGNED, U16F16::IS_SIGNED);
534    /// // U16F16::Unsigned is U16F16
535    /// assert_eq!(<U16F16 as Fixed>::Unsigned::FRAC_NBITS, U16F16::FRAC_NBITS);
536    /// assert_eq!(<U16F16 as Fixed>::Unsigned::INT_NBITS, U16F16::INT_NBITS);
537    /// assert_eq!(<U16F16 as Fixed>::Unsigned::IS_SIGNED, U16F16::IS_SIGNED);
538    /// ```
539    ///
540    /// [I16F16]: crate::types::I16F16
541    /// [U16F16]: crate::types::U16F16
542    /// [types]: crate::types
543    type Unsigned: FixedUnsigned;
544
545    /// Returns the bit pattern of `self` reinterpreted as a signed fixed-point
546    /// number of the same size.
547    ///
548    /// For signed fixed-point numbers, the returned value is equal to `self`.
549    ///
550    /// See also <code>FixedU32::[cast\_signed][FixedU32::cast_signed]</code>.
551    ///
552    /// # Examples
553    ///
554    /// ```rust
555    /// use fixed::traits::Fixed;
556    /// use fixed::types::{I16F16, U16F16};
557    ///
558    /// let i = -I16F16::DELTA;
559    /// let u = U16F16::MAX;
560    /// assert_eq!(i.cast_signed(), i);
561    /// assert_eq!(u.cast_signed(), i);
562    /// ```
563    #[must_use]
564    #[inline]
565    fn cast_signed(self) -> Self::Signed {
566        bytemuck::cast(self)
567    }
568
569    /// Returns the bit pattern of `self` reinterpreted as an unsigned
570    /// fixed-point number of the same size.
571    ///
572    /// For unsigned fixed-point numbers, the returned value is equal to `self`.
573    ///
574    /// See also
575    /// <code>FixedI32::[cast\_unsigned][FixedI32::cast_unsigned]</code>.
576    ///
577    /// # Examples
578    ///
579    /// ```rust
580    /// use fixed::traits::Fixed;
581    /// use fixed::types::{I16F16, U16F16};
582    ///
583    /// let i = -I16F16::DELTA;
584    /// let u = U16F16::MAX;
585    /// assert_eq!(i.cast_unsigned(), u);
586    /// assert_eq!(u.cast_unsigned(), u);
587    /// ```
588    #[must_use]
589    #[inline]
590    fn cast_unsigned(self) -> Self::Unsigned {
591        bytemuck::cast(self)
592    }
593
594    /// Returns a reference to `self` as [`FixedSigned`] if the type is signed,
595    /// or [`None`] if it is unsigned.
596    ///
597    /// # Examples
598    ///
599    /// ```rust
600    /// use fixed::traits::Fixed;
601    /// use fixed::types::{I16F16, U16F16};
602    ///
603    /// let i = I16F16::from_num(-3.5);
604    /// match i.get_signed() {
605    ///     Some(signed) => assert_eq!(signed.signum(), -1),
606    ///     None => unreachable!(),
607    /// }
608    ///
609    /// let u = U16F16::from_num(3.5);
610    /// assert!(u.get_signed().is_none());
611    /// ```
612    #[inline]
613    fn get_signed(&self) -> Option<&Self::Signed> {
614        if Self::IS_SIGNED {
615            Some(bytemuck::cast_ref(self))
616        } else {
617            None
618        }
619    }
620
621    /// Returns a reference to `self` as [`FixedUnsigned`] if the type is
622    /// unsigned, or [`None`] if it is signed.
623    ///
624    /// # Examples
625    ///
626    /// ```rust
627    /// use fixed::traits::Fixed;
628    /// use fixed::types::{I16F16, U16F16};
629    ///
630    /// let u = U16F16::from_num(3.5);
631    /// match u.get_unsigned() {
632    ///     Some(unsigned) => assert_eq!(unsigned.next_power_of_two(), 4),
633    ///     None => unreachable!(),
634    /// }
635    ///
636    /// let i = I16F16::from_num(3.5);
637    /// assert!(i.get_unsigned().is_none());
638    /// ```
639    #[inline]
640    fn get_unsigned(&self) -> Option<&Self::Unsigned> {
641        if Self::IS_SIGNED {
642            None
643        } else {
644            Some(bytemuck::cast_ref(self))
645        }
646    }
647
648    /// Returns a mutable reference to `self` as [`FixedSigned`] if the type is
649    /// signed, or [`None`] if it is unsigned.
650    ///
651    /// # Examples
652    ///
653    /// ```rust
654    /// use fixed::traits::Fixed;
655    /// use fixed::types::{I16F16, U16F16};
656    ///
657    /// let mut i = I16F16::from_num(-3.5);
658    /// match i.get_signed_mut() {
659    ///     Some(signed) => *signed = signed.signum(),
660    ///     None => unreachable!(),
661    /// }
662    /// assert_eq!(i, -1);
663    ///
664    /// let mut u = U16F16::from_num(3.5);
665    /// assert!(u.get_signed_mut().is_none());
666    /// ```
667    #[inline]
668    fn get_signed_mut(&mut self) -> Option<&mut Self::Signed> {
669        if Self::IS_SIGNED {
670            Some(bytemuck::cast_mut(self))
671        } else {
672            None
673        }
674    }
675
676    /// Returns a mutable reference to `self` as [`FixedUnsigned`] if the type
677    /// is unsigned, or [`None`] if it is signed.
678    ///
679    /// # Examples
680    ///
681    /// ```rust
682    /// use fixed::traits::Fixed;
683    /// use fixed::types::{I16F16, U16F16};
684    ///
685    /// let mut u = U16F16::from_num(3.5);
686    /// match u.get_unsigned_mut() {
687    ///     Some(unsigned) => *unsigned = unsigned.next_power_of_two(),
688    ///     None => unreachable!(),
689    /// }
690    /// assert_eq!(u, 4);
691    ///
692    /// let mut i = I16F16::from_num(3.5);
693    /// assert!(i.get_unsigned_mut().is_none());
694    /// ```
695    #[inline]
696    fn get_unsigned_mut(&mut self) -> Option<&mut Self::Unsigned> {
697        if Self::IS_SIGNED {
698            None
699        } else {
700            Some(bytemuck::cast_mut(self))
701        }
702    }
703
704    /// Zero.
705    ///
706    /// See also <code>FixedI32::[ZERO][FixedI32::ZERO]</code> and
707    /// <code>FixedU32::[ZERO][FixedU32::ZERO]</code>.
708    const ZERO: Self;
709
710    /// One if the fixed-point number can represent it, otherwise [`None`].
711    const TRY_ONE: Option<Self>;
712
713    /// The difference between any two successive representable numbers, <i>Δ</i>.
714    ///
715    /// See also <code>FixedI32::[DELTA][FixedI32::DELTA]</code> and
716    /// <code>FixedU32::[DELTA][FixedU32::DELTA]</code>.
717    const DELTA: Self;
718
719    /// The smallest value that can be represented.
720    ///
721    /// See also <code>FixedI32::[MIN][FixedI32::MIN]</code> and
722    /// <code>FixedU32::[MIN][FixedU32::MIN]</code>.
723    const MIN: Self;
724
725    /// The largest value that can be represented.
726    ///
727    /// See also <code>FixedI32::[MAX][FixedI32::MAX]</code> and
728    /// <code>FixedU32::[MAX][FixedU32::MAX]</code>.
729    const MAX: Self;
730
731    /// [`true`] if the type is signed.
732    ///
733    /// See also <code>FixedI32::[IS\_SIGNED][FixedI32::IS_SIGNED]</code> and
734    /// <code>FixedU32::[IS\_SIGNED][FixedU32::IS_SIGNED]</code>.
735    const IS_SIGNED: bool;
736
737    /// The number of integer bits.
738    ///
739    /// See also <code>FixedI32::[INT\_NBITS][FixedI32::INT_NBITS]</code> and
740    /// <code>FixedU32::[INT\_NBITS][FixedU32::INT_NBITS]</code>.
741    const INT_NBITS: u32;
742
743    /// The number of fractional bits.
744    ///
745    /// See also <code>FixedI32::[FRAC\_NBITS][FixedI32::FRAC_NBITS]</code> and
746    /// <code>FixedU32::[FRAC\_NBITS][FixedU32::FRAC_NBITS]</code>.
747    const FRAC_NBITS: u32;
748
749    /// Creates a fixed-point number that has a bitwise representation
750    /// identical to the given integer.
751    ///
752    /// See also <code>FixedI32::[from\_bits][FixedI32::from_bits]</code> and
753    /// <code>FixedU32::[from\_bits][FixedU32::from_bits]</code>.
754    fn from_bits(bits: Self::Bits) -> Self;
755
756    /// Creates an integer that has a bitwise representation identical
757    /// to the given fixed-point number.
758    ///
759    /// See also <code>FixedI32::[to\_bits][FixedI32::to_bits]</code> and
760    /// <code>FixedU32::[to\_bits][FixedU32::to_bits]</code>.
761    fn to_bits(self) -> Self::Bits;
762
763    /// Converts a fixed-point number from big endian to the target’s endianness.
764    ///
765    /// See also <code>FixedI32::[from\_be][FixedI32::from_be]</code> and
766    /// <code>FixedU32::[from\_be][FixedU32::from_be]</code>.
767    fn from_be(fixed: Self) -> Self;
768
769    /// Converts a fixed-point number from little endian to the target’s endianness.
770    ///
771    /// See also <code>FixedI32::[from\_le][FixedI32::from_le]</code> and
772    /// <code>FixedU32::[from\_le][FixedU32::from_le]</code>.
773    fn from_le(fixed: Self) -> Self;
774
775    /// Converts this fixed-point number to big endian from the target’s endianness.
776    ///
777    /// See also <code>FixedI32::[to\_be][FixedI32::to_be]</code> and
778    /// <code>FixedU32::[to\_be][FixedU32::to_be]</code>.
779    #[must_use]
780    fn to_be(self) -> Self;
781
782    /// Converts this fixed-point number to little endian from the target’s endianness.
783    ///
784    /// See also <code>FixedI32::[to\_le][FixedI32::to_le]</code> and
785    /// <code>FixedU32::[to\_le][FixedU32::to_le]</code>.
786    #[must_use]
787    fn to_le(self) -> Self;
788
789    ///Reverses the byte order of the fixed-point number.
790    ///
791    /// See also <code>FixedI32::[swap\_bytes][FixedI32::swap_bytes]</code> and
792    /// <code>FixedU32::[swap\_bytes][FixedU32::swap_bytes]</code>.
793    #[must_use]
794    fn swap_bytes(self) -> Self;
795
796    /// Creates a fixed-point number from its representation as a byte
797    /// array in big endian.
798    ///
799    /// See also
800    /// <code>FixedI32::[from\_be\_bytes][FixedI32::from_be_bytes]</code> and
801    /// <code>FixedU32::[from\_be\_bytes][FixedU32::from_be_bytes]</code>.
802    fn from_be_bytes(bytes: Self::Bytes) -> Self;
803
804    /// Creates a fixed-point number from its representation as a byte
805    /// array in little endian.
806    ///
807    /// See also
808    /// <code>FixedI32::[from\_le\_bytes][FixedI32::from_le_bytes]</code> and
809    /// <code>FixedU32::[from\_le\_bytes][FixedU32::from_le_bytes]</code>.
810    fn from_le_bytes(bytes: Self::Bytes) -> Self;
811
812    /// Creates a fixed-point number from its representation as a byte
813    /// array in native endian.
814    ///
815    /// See also
816    /// <code>FixedI32::[from\_ne\_bytes][FixedI32::from_ne_bytes]</code> and
817    /// <code>FixedU32::[from\_ne\_bytes][FixedU32::from_ne_bytes]</code>.
818    fn from_ne_bytes(bytes: Self::Bytes) -> Self;
819
820    /// Returns the memory representation of this fixed-point number
821    /// as a byte array in big-endian byte order.
822    ///
823    /// See also <code>FixedI32::[to\_be\_bytes][FixedI32::to_be_bytes]</code>
824    /// and <code>FixedU32::[to\_be\_bytes][FixedU32::to_be_bytes]</code>.
825    fn to_be_bytes(self) -> Self::Bytes;
826
827    /// Returns the memory representation of this fixed-point number
828    /// as a byte array in little-endian byte order.
829    ///
830    /// See also <code>FixedI32::[to\_le\_bytes][FixedI32::to_le_bytes]</code>
831    /// and <code>FixedU32::[to\_le\_bytes][FixedU32::to_le_bytes]</code>.
832    fn to_le_bytes(self) -> Self::Bytes;
833
834    /// Returns the memory representation of this fixed-point number
835    /// as a byte array in native byte order.
836    ///
837    /// See also <code>FixedI32::[to\_ne\_bytes][FixedI32::to_ne_bytes]</code>
838    /// and <code>FixedU32::[to\_ne\_bytes][FixedU32::to_ne_bytes]</code>.
839    fn to_ne_bytes(self) -> Self::Bytes;
840
841    /// Creates a fixed-point number from another number.
842    ///
843    /// Returns the same value as
844    /// <code>src.[to\_fixed][ToFixed::to_fixed]\()</code>.
845    ///
846    /// See also <code>FixedI32::[from\_num][FixedI32::from_num]</code> and
847    /// <code>FixedU32::[from\_num][FixedU32::from_num]</code>.
848    fn from_num<Src: ToFixed>(src: Src) -> Self;
849
850    /// Converts a fixed-point number to another number.
851    ///
852    /// Returns the same value as
853    /// <code>Dst::[from\_fixed][FromFixed::from_fixed]\(self)</code>.
854    ///
855    /// See also <code>FixedI32::[to\_num][FixedI32::to_num]</code> and
856    /// <code>FixedU32::[to\_num][FixedU32::to_num]</code>.
857    fn to_num<Dst: FromFixed>(self) -> Dst;
858
859    /// Creates a fixed-point number from another number if it fits,
860    /// otherwise returns [`None`].
861    ///
862    /// Returns the same value as
863    /// <code>src.[checked\_to\_fixed][ToFixed::checked_to_fixed]\()</code>.
864    ///
865    /// See also
866    /// <code>FixedI32::[checked\_from\_num][FixedI32::checked_from_num]</code>
867    /// and
868    /// <code>FixedU32::[checked\_from\_num][FixedU32::checked_from_num]</code>.
869    fn checked_from_num<Src: ToFixed>(src: Src) -> Option<Self>;
870
871    /// Converts a fixed-point number to another number if it fits,
872    /// otherwise returns [`None`].
873    ///
874    /// Returns the same value as
875    /// <code>Dst::[checked\_from\_fixed][FromFixed::checked_from_fixed]\(self)</code>.
876    ///
877    /// See also
878    /// <code>FixedI32::[checked\_to\_num][FixedI32::checked_to_num]</code> and
879    /// <code>FixedU32::[checked\_to\_num][FixedU32::checked_to_num]</code>.
880    fn checked_to_num<Dst: FromFixed>(self) -> Option<Dst>;
881
882    /// Creates a fixed-point number from another number, saturating the
883    /// value if it does not fit.
884    ///
885    /// Returns the same value as
886    /// <code>src.[saturating\_to\_fixed][ToFixed::saturating_to_fixed]\()</code>.
887    ///
888    /// See also
889    /// <code>FixedI32::[saturating\_from\_num][FixedI32::saturating_from_num]</code>
890    /// and
891    /// <code>FixedU32::[saturating\_from\_num][FixedU32::saturating_from_num]</code>.
892    fn saturating_from_num<Src: ToFixed>(src: Src) -> Self;
893
894    /// Converts a fixed-point number to another number, saturating the
895    /// value if it does not fit.
896    ///
897    /// Returns the same value as
898    /// <code>Dst::[saturating\_from\_fixed][FromFixed::saturating_from_fixed]\(self)</code>.
899    ///
900    /// See also
901    /// <code>FixedI32::[saturating\_to\_num][FixedI32::saturating_to_num]</code>
902    /// and
903    /// <code>FixedU32::[saturating\_to\_num][FixedU32::saturating_to_num]</code>.
904    fn saturating_to_num<Dst: FromFixed>(self) -> Dst;
905
906    /// Creates a fixed-point number from another number, wrapping the
907    /// value on overflow.
908    ///
909    /// Returns the same value as
910    /// <code>src.[wrapping\_to\_fixed][ToFixed::wrapping_to_fixed]\()</code>.
911    ///
912    /// See also
913    /// <code>FixedI32::[wrapping\_from\_num][FixedI32::wrapping_from_num]</code>
914    /// and
915    /// <code>FixedU32::[wrapping\_from\_num][FixedU32::wrapping_from_num]</code>.
916    fn wrapping_from_num<Src: ToFixed>(src: Src) -> Self;
917
918    /// Converts a fixed-point number to another number, wrapping the
919    /// value on overflow.
920    ///
921    /// Returns the same value as
922    /// <code>Dst::[wrapping\_from\_fixed][FromFixed::wrapping_from_fixed]\(self)</code>.
923    ///
924    /// See also
925    /// <code>FixedI32::[wrapping\_to\_num][FixedI32::wrapping_to_num]</code>
926    /// and
927    /// <code>FixedU32::[wrapping\_to\_num][FixedU32::wrapping_to_num]</code>.
928    fn wrapping_to_num<Dst: FromFixed>(self) -> Dst;
929
930    /// Creates a fixed-point number from another number, panicking on overflow.
931    ///
932    /// Returns the same value as
933    /// <code>src.[strict\_to\_fixed][ToFixed::strict_to_fixed]\()</code>.
934    ///
935    /// See also
936    /// <code>FixedI32::[strict\_from\_num][FixedI32::strict_from_num]</code>
937    /// and
938    /// <code>FixedU32::[strict\_from\_num][FixedU32::strict_from_num]</code>.
939    ///
940    /// # Panics
941    ///
942    /// Panics if the value does not fit.
943    #[track_caller]
944    fn strict_from_num<Src: ToFixed>(src: Src) -> Self;
945
946    /// Converts a fixed-point number to another number, panicking on overflow.
947    ///
948    /// Returns the same value as
949    /// <code>Dst::[strict\_from\_fixed][FromFixed::strict_from_fixed]\(self)</code>.
950    ///
951    /// See also
952    /// <code>FixedI32::[strict\_to\_num][FixedI32::strict_to_num]</code> and
953    /// <code>FixedU32::[strict\_to\_num][FixedU32::strict_to_num]</code>.
954    ///
955    /// # Panics
956    ///
957    /// Panics if the value does not fit.
958    #[track_caller]
959    fn strict_to_num<Dst: FromFixed>(self) -> Dst;
960
961    /// Creates a fixed-point number from another number.
962    ///
963    /// Returns the same value as
964    /// <code>src.[overflowing\_to\_fixed][ToFixed::overflowing_to_fixed]\()</code>.
965    ///
966    /// See also
967    /// <code>FixedI32::[overflowing\_from\_num][FixedI32::overflowing_from_num]</code>
968    /// and
969    /// <code>FixedU32::[overflowing\_from\_num][FixedU32::overflowing_from_num]</code>.
970    fn overflowing_from_num<Src: ToFixed>(src: Src) -> (Self, bool);
971
972    /// Converts a fixed-point number to another number.
973    ///
974    /// Returns the same value as
975    /// <code>Dst::[overflowing\_from\_fixed][FromFixed::overflowing_from_fixed]\(self)</code>.
976    ///
977    /// See also
978    /// <code>FixedI32::[overflowing\_to\_num][FixedI32::overflowing_to_num]</code>
979    /// and
980    /// <code>FixedU32::[overflowing\_to\_num][FixedU32::overflowing_to_num]</code>.
981    fn overflowing_to_num<Dst: FromFixed>(self) -> (Dst, bool);
982
983    /// Parses a string slice containing binary digits to return a fixed-point number.
984    ///
985    /// Rounding is to the nearest, with ties rounded to even.
986    ///
987    /// See also
988    /// <code>FixedI32::[from\_str\_binary][FixedI32::from_str_binary]</code>
989    /// and
990    /// <code>FixedU32::[from\_str\_binary][FixedU32::from_str_binary]</code>.
991    fn from_str_binary(src: &str) -> Result<Self, ParseFixedError>;
992
993    /// Parses a string slice containing octal digits to return a fixed-point number.
994    ///
995    /// Rounding is to the nearest, with ties rounded to even.
996    ///
997    /// See also
998    /// <code>FixedI32::[from\_str\_octal][FixedI32::from_str_octal]</code> and
999    /// <code>FixedU32::[from\_str\_octal][FixedU32::from_str_octal]</code>.
1000    fn from_str_octal(src: &str) -> Result<Self, ParseFixedError>;
1001
1002    /// Parses a string slice containing hexadecimal digits to return a fixed-point number.
1003    ///
1004    /// Rounding is to the nearest, with ties rounded to even.
1005    ///
1006    /// See also <code>FixedI32::[from\_str\_hex][FixedI32::from_str_hex]</code>
1007    /// and <code>FixedU32::[from\_str\_hex][FixedU32::from_str_hex]</code>.
1008    fn from_str_hex(src: &str) -> Result<Self, ParseFixedError>;
1009
1010    /// Parses an ASCII-byte slice containing binary digits to return a fixed-point number.
1011    ///
1012    /// Rounding is to the nearest, with ties rounded to even.
1013    ///
1014    /// See also
1015    /// <code>FixedI32::[from\_ascii\_binary][FixedI32::from_ascii_binary]</code>
1016    /// and
1017    /// <code>FixedU32::[from\_ascii\_binary][FixedU32::from_ascii_binary]</code>.
1018    fn from_ascii(src: &[u8]) -> Result<Self, ParseFixedError>;
1019
1020    /// Parses an ASCII-byte slice containing binary digits to return a fixed-point number.
1021    ///
1022    /// Rounding is to the nearest, with ties rounded to even.
1023    ///
1024    /// See also
1025    /// <code>FixedI32::[from\_ascii\_binary][FixedI32::from_ascii_binary]</code>
1026    /// and
1027    /// <code>FixedU32::[from\_ascii\_binary][FixedU32::from_ascii_binary]</code>.
1028    fn from_ascii_binary(src: &[u8]) -> Result<Self, ParseFixedError>;
1029
1030    /// Parses an ASCII-byte slice containing octal digits to return a fixed-point number.
1031    ///
1032    /// Rounding is to the nearest, with ties rounded to even.
1033    ///
1034    /// See also
1035    /// <code>FixedI32::[from\_ascii\_octal][FixedI32::from_ascii_octal]</code> and
1036    /// <code>FixedU32::[from\_ascii\_octal][FixedU32::from_ascii_octal]</code>.
1037    fn from_ascii_octal(src: &[u8]) -> Result<Self, ParseFixedError>;
1038
1039    /// Parses an ASCII-byte slice containing hexadecimal digits to return a fixed-point number.
1040    ///
1041    /// Rounding is to the nearest, with ties rounded to even.
1042    ///
1043    /// See also <code>FixedI32::[from\_ascii\_hex][FixedI32::from_ascii_hex]</code>
1044    /// and <code>FixedU32::[from\_ascii\_hex][FixedU32::from_ascii_hex]</code>.
1045    fn from_ascii_hex(src: &[u8]) -> Result<Self, ParseFixedError>;
1046
1047    /// Parses a string slice containing decimal digits to return a
1048    /// fixed-point number, saturating on overflow.
1049    ///
1050    /// Rounding is to the nearest, with ties rounded to even.
1051    ///
1052    /// See also
1053    /// <code>FixedI32::[saturating\_from\_str][FixedI32::saturating_from_str]</code>
1054    /// and
1055    /// <code>FixedU32::[saturating\_from\_str][FixedU32::saturating_from_str]</code>.
1056    fn saturating_from_str(src: &str) -> Result<Self, ParseFixedError>;
1057
1058    /// Parses a string slice containing binary digits to return a
1059    /// fixed-point number, saturating on overflow.
1060    ///
1061    /// Rounding is to the nearest, with ties rounded to even.
1062    ///
1063    /// See also
1064    /// <code>FixedI32::[saturating\_from\_str\_binary][FixedI32::saturating_from_str_binary]</code>
1065    /// and
1066    /// <code>FixedU32::[saturating\_from\_str\_binary][FixedU32::saturating_from_str_binary]</code>.
1067    fn saturating_from_str_binary(src: &str) -> Result<Self, ParseFixedError>;
1068
1069    /// Parses a string slice containing octal digits to return a
1070    /// fixed-point number, saturating on overflow.
1071    ///
1072    /// Rounding is to the nearest, with ties rounded to even.
1073    ///
1074    /// See also
1075    /// <code>FixedI32::[saturating\_from\_str\_octal][FixedI32::saturating_from_str_octal]</code>
1076    /// and
1077    /// <code>FixedU32::[saturating\_from\_str\_octal][FixedU32::saturating_from_str_octal]</code>.
1078    fn saturating_from_str_octal(src: &str) -> Result<Self, ParseFixedError>;
1079
1080    /// Parses a string slice containing hexadecimal digits to return a
1081    /// fixed-point number, saturating on overflow.
1082    ///
1083    /// Rounding is to the nearest, with ties rounded to even.
1084    ///
1085    /// See also
1086    /// <code>FixedI32::[saturating\_from\_str\_hex][FixedI32::saturating_from_str_hex]</code>
1087    /// and
1088    /// <code>FixedU32::[saturating\_from\_str\_hex][FixedU32::saturating_from_str_hex]</code>.
1089    fn saturating_from_str_hex(src: &str) -> Result<Self, ParseFixedError>;
1090
1091    /// Parses an ASCII-byte slice containing decimal digits to return a
1092    /// fixed-point number, saturating on overflow.
1093    ///
1094    /// Rounding is to the nearest, with ties rounded to even.
1095    ///
1096    /// See also
1097    /// <code>FixedI32::[saturating\_from\_ascii][FixedI32::saturating_from_ascii]</code>
1098    /// and
1099    /// <code>FixedU32::[saturating\_from\_ascii][FixedU32::saturating_from_ascii]</code>.
1100    fn saturating_from_ascii(src: &[u8]) -> Result<Self, ParseFixedError>;
1101
1102    /// Parses an ASCII-byte slice containing binary digits to return a
1103    /// fixed-point number, saturating on overflow.
1104    ///
1105    /// Rounding is to the nearest, with ties rounded to even.
1106    ///
1107    /// See also
1108    /// <code>FixedI32::[saturating\_from\_ascii\_binary][FixedI32::saturating_from_ascii_binary]</code>
1109    /// and
1110    /// <code>FixedU32::[saturating\_from\_ascii\_binary][FixedU32::saturating_from_ascii_binary]</code>.
1111    fn saturating_from_ascii_binary(src: &[u8]) -> Result<Self, ParseFixedError>;
1112
1113    /// Parses an ASCII-byte slice containing octal digits to return a
1114    /// fixed-point number, saturating on overflow.
1115    ///
1116    /// Rounding is to the nearest, with ties rounded to even.
1117    ///
1118    /// See also
1119    /// <code>FixedI32::[saturating\_from\_ascii\_octal][FixedI32::saturating_from_ascii_octal]</code>
1120    /// and
1121    /// <code>FixedU32::[saturating\_from\_ascii\_octal][FixedU32::saturating_from_ascii_octal]</code>.
1122    fn saturating_from_ascii_octal(src: &[u8]) -> Result<Self, ParseFixedError>;
1123
1124    /// Parses an ASCII-byte slice containing hexadecimal digits to return a
1125    /// fixed-point number, saturating on overflow.
1126    ///
1127    /// Rounding is to the nearest, with ties rounded to even.
1128    ///
1129    /// See also
1130    /// <code>FixedI32::[saturating\_from\_ascii\_hex][FixedI32::saturating_from_ascii_hex]</code>
1131    /// and
1132    /// <code>FixedU32::[saturating\_from\_ascii\_hex][FixedU32::saturating_from_ascii_hex]</code>.
1133    fn saturating_from_ascii_hex(src: &[u8]) -> Result<Self, ParseFixedError>;
1134
1135    /// Parses a string slice containing decimal digits to return a
1136    /// fixed-point number, wrapping on overflow.
1137    ///
1138    /// Rounding is to the nearest, with ties rounded to even.
1139    ///
1140    /// See also
1141    /// <code>FixedI32::[wrapping\_from\_str][FixedI32::wrapping_from_str]</code>
1142    /// and
1143    /// <code>FixedU32::[wrapping\_from\_str][FixedU32::wrapping_from_str]</code>.
1144    fn wrapping_from_str(src: &str) -> Result<Self, ParseFixedError>;
1145
1146    /// Parses a string slice containing binary digits to return a
1147    /// fixed-point number, wrapping on overflow.
1148    ///
1149    /// Rounding is to the nearest, with ties rounded to even.
1150    ///
1151    /// See also
1152    /// <code>FixedI32::[wrapping\_from\_str\_binary][FixedI32::wrapping_from_str_binary]</code>
1153    /// and
1154    /// <code>FixedU32::[wrapping\_from\_str\_binary][FixedU32::wrapping_from_str_binary]</code>.
1155    fn wrapping_from_str_binary(src: &str) -> Result<Self, ParseFixedError>;
1156
1157    /// Parses a string slice containing octal digits to return a
1158    /// fixed-point number, wrapping on overflow.
1159    ///
1160    /// Rounding is to the nearest, with ties rounded to even.
1161    ///
1162    /// See also
1163    /// <code>FixedI32::[wrapping\_from\_str\_octal][FixedI32::wrapping_from_str_octal]</code>
1164    /// and
1165    /// <code>FixedU32::[wrapping\_from\_str\_octal][FixedU32::wrapping_from_str_octal]</code>.
1166    fn wrapping_from_str_octal(src: &str) -> Result<Self, ParseFixedError>;
1167
1168    /// Parses a string slice containing hexadecimal digits to return a
1169    /// fixed-point number, wrapping on overflow.
1170    ///
1171    /// Rounding is to the nearest, with ties rounded to even.
1172    ///
1173    /// See also
1174    /// <code>FixedI32::[wrapping\_from\_str\_hex][FixedI32::wrapping_from_str_hex]</code>
1175    /// and
1176    /// <code>FixedU32::[wrapping\_from\_str\_hex][FixedU32::wrapping_from_str_hex]</code>.
1177    fn wrapping_from_str_hex(src: &str) -> Result<Self, ParseFixedError>;
1178
1179    /// Parses an ASCII-byte slice containing decimal digits to return a
1180    /// fixed-point number, wrapping on overflow.
1181    ///
1182    /// Rounding is to the nearest, with ties rounded to even.
1183    ///
1184    /// See also
1185    /// <code>FixedI32::[wrapping\_from\_ascii][FixedI32::wrapping_from_ascii]</code>
1186    /// and
1187    /// <code>FixedU32::[wrapping\_from\_ascii][FixedU32::wrapping_from_ascii]</code>.
1188    fn wrapping_from_ascii(src: &[u8]) -> Result<Self, ParseFixedError>;
1189
1190    /// Parses an ASCII-byte slice containing binary digits to return a
1191    /// fixed-point number, wrapping on overflow.
1192    ///
1193    /// Rounding is to the nearest, with ties rounded to even.
1194    ///
1195    /// See also
1196    /// <code>FixedI32::[wrapping\_from\_ascii\_binary][FixedI32::wrapping_from_ascii_binary]</code>
1197    /// and
1198    /// <code>FixedU32::[wrapping\_from\_ascii\_binary][FixedU32::wrapping_from_ascii_binary]</code>.
1199    fn wrapping_from_ascii_binary(src: &[u8]) -> Result<Self, ParseFixedError>;
1200
1201    /// Parses an ASCII-byte slice containing octal digits to return a
1202    /// fixed-point number, wrapping on overflow.
1203    ///
1204    /// Rounding is to the nearest, with ties rounded to even.
1205    ///
1206    /// See also
1207    /// <code>FixedI32::[wrapping\_from\_ascii\_octal][FixedI32::wrapping_from_ascii_octal]</code>
1208    /// and
1209    /// <code>FixedU32::[wrapping\_from\_ascii\_octal][FixedU32::wrapping_from_ascii_octal]</code>.
1210    fn wrapping_from_ascii_octal(src: &[u8]) -> Result<Self, ParseFixedError>;
1211
1212    /// Parses an ASCII-byte slice containing hexadecimal digits to return a
1213    /// fixed-point number, wrapping on overflow.
1214    ///
1215    /// Rounding is to the nearest, with ties rounded to even.
1216    ///
1217    /// See also
1218    /// <code>FixedI32::[wrapping\_from\_ascii\_hex][FixedI32::wrapping_from_ascii_hex]</code>
1219    /// and
1220    /// <code>FixedU32::[wrapping\_from\_ascii\_hex][FixedU32::wrapping_from_ascii_hex]</code>.
1221    fn wrapping_from_ascii_hex(src: &[u8]) -> Result<Self, ParseFixedError>;
1222
1223    /// Parses a string slice containing decimal digits to return a
1224    /// fixed-point number, panicking on overflow.
1225    ///
1226    /// Rounding is to the nearest, with ties rounded to even.
1227    ///
1228    /// See also
1229    /// <code>FixedI32::[strict\_from\_str][FixedI32::strict_from_str]</code>
1230    /// and
1231    /// <code>FixedU32::[strict\_from\_str][FixedU32::strict_from_str]</code>.
1232    ///
1233    /// # Panics
1234    ///
1235    /// Panics if the value does not fit or if there is a parsing error.
1236    #[track_caller]
1237    fn strict_from_str(src: &str) -> Self;
1238
1239    /// Parses a string slice containing binary digits to return a
1240    /// fixed-point number, panicking on overflow.
1241    ///
1242    /// Rounding is to the nearest, with ties rounded to even.
1243    ///
1244    /// See also
1245    /// <code>FixedI32::[strict\_from\_str\_binary][FixedI32::strict_from_str_binary]</code>
1246    /// and
1247    /// <code>FixedU32::[strict\_from\_str\_binary][FixedU32::strict_from_str_binary]</code>.
1248    ///
1249    /// # Panics
1250    ///
1251    /// Panics if the value does not fit or if there is a parsing error.
1252    #[track_caller]
1253    fn strict_from_str_binary(src: &str) -> Self;
1254
1255    /// Parses a string slice containing octal digits to return a
1256    /// fixed-point number, panicking on overflow.
1257    ///
1258    /// Rounding is to the nearest, with ties rounded to even.
1259    ///
1260    /// See also
1261    /// <code>FixedI32::[strict\_from\_str\_octal][FixedI32::strict_from_str_octal]</code>
1262    /// and
1263    /// <code>FixedU32::[strict\_from\_str\_octal][FixedU32::strict_from_str_octal]</code>.
1264    ///
1265    /// # Panics
1266    ///
1267    /// Panics if the value does not fit or if there is a parsing error.
1268    #[track_caller]
1269    fn strict_from_str_octal(src: &str) -> Self;
1270
1271    /// Parses a string slice containing hexadecimal digits to return a
1272    /// fixed-point number, panicking on overflow.
1273    ///
1274    /// Rounding is to the nearest, with ties rounded to even.
1275    ///
1276    /// See also
1277    /// <code>FixedI32::[strict\_from\_str\_hex][FixedI32::strict_from_str_hex]</code>
1278    /// and
1279    /// <code>FixedU32::[strict\_from\_str\_hex][FixedU32::strict_from_str_hex]</code>.
1280    ///
1281    /// # Panics
1282    ///
1283    /// Panics if the value does not fit or if there is a parsing error.
1284    #[track_caller]
1285    fn strict_from_str_hex(src: &str) -> Self;
1286
1287    /// Parses an ASCII-byte slice containing decimal digits to return a
1288    /// fixed-point number, panicking on overflow.
1289    ///
1290    /// Rounding is to the nearest, with ties rounded to even.
1291    ///
1292    /// See also
1293    /// <code>FixedI32::[strict\_from\_ascii][FixedI32::strict_from_ascii]</code>
1294    /// and
1295    /// <code>FixedU32::[strict\_from\_ascii][FixedU32::strict_from_ascii]</code>.
1296    ///
1297    /// # Panics
1298    ///
1299    /// Panics if the value does not fit or if there is a parsing error.
1300    #[track_caller]
1301    fn strict_from_ascii(src: &[u8]) -> Self;
1302
1303    /// Parses an ASCII-byte slice containing binary digits to return a
1304    /// fixed-point number, panicking on overflow.
1305    ///
1306    /// Rounding is to the nearest, with ties rounded to even.
1307    ///
1308    /// See also
1309    /// <code>FixedI32::[strict\_from\_ascii\_binary][FixedI32::strict_from_ascii_binary]</code>
1310    /// and
1311    /// <code>FixedU32::[strict\_from\_ascii\_binary][FixedU32::strict_from_ascii_binary]</code>.
1312    ///
1313    /// # Panics
1314    ///
1315    /// Panics if the value does not fit or if there is a parsing error.
1316    #[track_caller]
1317    fn strict_from_ascii_binary(src: &[u8]) -> Self;
1318
1319    /// Parses an ASCII-byte slice containing octal digits to return a
1320    /// fixed-point number, panicking on overflow.
1321    ///
1322    /// Rounding is to the nearest, with ties rounded to even.
1323    ///
1324    /// See also
1325    /// <code>FixedI32::[strict\_from\_ascii\_octal][FixedI32::strict_from_ascii_octal]</code>
1326    /// and
1327    /// <code>FixedU32::[strict\_from\_ascii\_octal][FixedU32::strict_from_ascii_octal]</code>.
1328    ///
1329    /// # Panics
1330    ///
1331    /// Panics if the value does not fit or if there is a parsing error.
1332    #[track_caller]
1333    fn strict_from_ascii_octal(src: &[u8]) -> Self;
1334
1335    /// Parses an ASCII-byte slice containing hexadecimal digits to return a
1336    /// fixed-point number, panicking on overflow.
1337    ///
1338    /// Rounding is to the nearest, with ties rounded to even.
1339    ///
1340    /// See also
1341    /// <code>FixedI32::[strict\_from\_ascii\_hex][FixedI32::strict_from_ascii_hex]</code>
1342    /// and
1343    /// <code>FixedU32::[strict\_from\_ascii\_hex][FixedU32::strict_from_ascii_hex]</code>.
1344    ///
1345    /// # Panics
1346    ///
1347    /// Panics if the value does not fit or if there is a parsing error.
1348    #[track_caller]
1349    fn strict_from_ascii_hex(src: &[u8]) -> Self;
1350
1351    /// Parses a string slice containing decimal digits to return a
1352    /// fixed-point number.
1353    ///
1354    /// Returns a [tuple] of the fixed-point number and a [`bool`],
1355    /// indicating whether an overflow has occurred. On overflow, the
1356    /// wrapped value is returned.
1357    ///
1358    /// Rounding is to the nearest, with ties rounded to even.
1359    ///
1360    /// See also
1361    /// <code>FixedI32::[overflowing\_from\_str][FixedI32::overflowing_from_str]</code>
1362    /// and
1363    /// <code>FixedU32::[overflowing\_from\_str][FixedU32::overflowing_from_str]</code>.
1364    fn overflowing_from_str(src: &str) -> Result<(Self, bool), ParseFixedError>;
1365
1366    /// Parses a string slice containing binary digits to return a
1367    /// fixed-point number.
1368    ///
1369    /// Returns a [tuple] of the fixed-point number and a [`bool`],
1370    /// indicating whether an overflow has occurred. On overflow, the
1371    /// wrapped value is returned.
1372    ///
1373    /// Rounding is to the nearest, with ties rounded to even.
1374    ///
1375    /// See also
1376    /// <code>FixedI32::[overflowing\_from\_str\_binary][FixedI32::overflowing_from_str_binary]</code>
1377    /// and
1378    /// <code>FixedU32::[overflowing\_from\_str\_binary][FixedU32::overflowing_from_str_binary]</code>.
1379    fn overflowing_from_str_binary(src: &str) -> Result<(Self, bool), ParseFixedError>;
1380
1381    /// Parses a string slice containing octal digits to return a
1382    /// fixed-point number.
1383    ///
1384    /// Returns a [tuple] of the fixed-point number and a [`bool`],
1385    /// indicating whether an overflow has occurred. On overflow, the
1386    /// wrapped value is returned.
1387    ///
1388    /// Rounding is to the nearest, with ties rounded to even.
1389    ///
1390    /// See also
1391    /// <code>FixedI32::[overflowing\_from\_str\_octal][FixedI32::overflowing_from_str_octal]</code>
1392    /// and
1393    /// <code>FixedU32::[overflowing\_from\_str\_octal][FixedU32::overflowing_from_str_octal]</code>.
1394    fn overflowing_from_str_octal(src: &str) -> Result<(Self, bool), ParseFixedError>;
1395
1396    /// Parses a string slice containing hexadecimal digits to return a
1397    /// fixed-point number.
1398    ///
1399    /// Returns a [tuple] of the fixed-point number and a [`bool`],
1400    /// indicating whether an overflow has occurred. On overflow, the
1401    /// wrapped value is returned.
1402    ///
1403    /// Rounding is to the nearest, with ties rounded to even.
1404    ///
1405    /// See also
1406    /// <code>FixedI32::[overflowing\_from\_str\_hex][FixedI32::overflowing_from_str_hex]</code>
1407    /// and
1408    /// <code>FixedU32::[overflowing\_from\_str\_hex][FixedU32::overflowing_from_str_hex]</code>.
1409    fn overflowing_from_str_hex(src: &str) -> Result<(Self, bool), ParseFixedError>;
1410
1411    /// Parses an ASCII-byte slice containing decimal digits to return a
1412    /// fixed-point number.
1413    ///
1414    /// Returns a [tuple] of the fixed-point number and a [`bool`],
1415    /// indicating whether an overflow has occurred. On overflow, the
1416    /// wrapped value is returned.
1417    ///
1418    /// Rounding is to the nearest, with ties rounded to even.
1419    ///
1420    /// See also
1421    /// <code>FixedI32::[overflowing\_from\_ascii][FixedI32::overflowing_from_ascii]</code>
1422    /// and
1423    /// <code>FixedU32::[overflowing\_from\_ascii][FixedU32::overflowing_from_ascii]</code>.
1424    fn overflowing_from_ascii(src: &[u8]) -> Result<(Self, bool), ParseFixedError>;
1425
1426    /// Parses an ASCII-byte slice containing binary digits to return a
1427    /// fixed-point number.
1428    ///
1429    /// Returns a [tuple] of the fixed-point number and a [`bool`],
1430    /// indicating whether an overflow has occurred. On overflow, the
1431    /// wrapped value is returned.
1432    ///
1433    /// Rounding is to the nearest, with ties rounded to even.
1434    ///
1435    /// See also
1436    /// <code>FixedI32::[overflowing\_from\_ascii\_binary][FixedI32::overflowing_from_ascii_binary]</code>
1437    /// and
1438    /// <code>FixedU32::[overflowing\_from\_ascii\_binary][FixedU32::overflowing_from_ascii_binary]</code>.
1439    fn overflowing_from_ascii_binary(src: &[u8]) -> Result<(Self, bool), ParseFixedError>;
1440
1441    /// Parses an ASCII-byte slice containing octal digits to return a
1442    /// fixed-point number.
1443    ///
1444    /// Returns a [tuple] of the fixed-point number and a [`bool`],
1445    /// indicating whether an overflow has occurred. On overflow, the
1446    /// wrapped value is returned.
1447    ///
1448    /// Rounding is to the nearest, with ties rounded to even.
1449    ///
1450    /// See also
1451    /// <code>FixedI32::[overflowing\_from\_ascii\_octal][FixedI32::overflowing_from_ascii_octal]</code>
1452    /// and
1453    /// <code>FixedU32::[overflowing\_from\_ascii\_octal][FixedU32::overflowing_from_ascii_octal]</code>.
1454    fn overflowing_from_ascii_octal(src: &[u8]) -> Result<(Self, bool), ParseFixedError>;
1455
1456    /// Parses an ASCII-byte slice containing hexadecimal digits to return a
1457    /// fixed-point number.
1458    ///
1459    /// Returns a [tuple] of the fixed-point number and a [`bool`],
1460    /// indicating whether an overflow has occurred. On overflow, the
1461    /// wrapped value is returned.
1462    ///
1463    /// Rounding is to the nearest, with ties rounded to even.
1464    ///
1465    /// See also
1466    /// <code>FixedI32::[overflowing\_from\_ascii\_hex][FixedI32::overflowing_from_ascii_hex]</code>
1467    /// and
1468    /// <code>FixedU32::[overflowing\_from\_ascii\_hex][FixedU32::overflowing_from_ascii_hex]</code>.
1469    fn overflowing_from_ascii_hex(src: &[u8]) -> Result<(Self, bool), ParseFixedError>;
1470
1471    /// Returns the integer part.
1472    ///
1473    /// See also <code>FixedI32::[int][FixedI32::int]</code> and
1474    /// <code>FixedU32::[int][FixedU32::int]</code>.
1475    #[must_use]
1476    fn int(self) -> Self;
1477
1478    /// Returns the fractional part.
1479    ///
1480    /// See also <code>FixedI32::[frac][FixedI32::frac]</code> and
1481    /// <code>FixedU32::[frac][FixedU32::frac]</code>.
1482    #[must_use]
1483    fn frac(self) -> Self;
1484
1485    /// Rounds to the next integer towards 0.
1486    ///
1487    /// See also
1488    /// <code>FixedI32::[round\_to\_zero][FixedI32::round_to_zero]</code> and
1489    /// <code>FixedU32::[round\_to\_zero][FixedU32::round_to_zero]</code>.
1490    #[must_use]
1491    fn round_to_zero(self) -> Self;
1492
1493    /// Rounds to the next integer towards +∞.
1494    ///
1495    /// See also <code>FixedI32::[ceil][FixedI32::ceil]</code> and
1496    /// <code>FixedU32::[ceil][FixedU32::ceil]</code>.
1497    #[must_use]
1498    fn ceil(self) -> Self;
1499
1500    /// Rounds to the next integer towards &minus;∞.
1501    ///
1502    /// See also <code>FixedI32::[floor][FixedI32::floor]</code> and
1503    /// <code>FixedU32::[floor][FixedU32::floor]</code>.
1504    #[must_use]
1505    fn floor(self) -> Self;
1506
1507    /// Rounds to the nearest integer, with ties rounded away from zero.
1508    ///
1509    /// See also <code>FixedI32::[round][FixedI32::round]</code> and
1510    /// <code>FixedU32::[round][FixedU32::round]</code>.
1511    #[must_use]
1512    fn round(self) -> Self;
1513
1514    /// Rounds to the nearest integer, with ties rounded to even.
1515    ///
1516    /// See also
1517    /// <code>FixedI32::[round\_ties\_even][FixedI32::round_ties_even]</code>
1518    /// and
1519    /// <code>FixedU32::[round\_ties\_even][FixedU32::round_ties_even]</code>.
1520    #[must_use]
1521    fn round_ties_even(self) -> Self;
1522
1523    /// Checked ceil. Rounds to the next integer towards +∞, returning
1524    /// [`None`] on overflow.
1525    ///
1526    /// See also <code>FixedI32::[checked\_ceil][FixedI32::checked_ceil]</code>
1527    /// and <code>FixedU32::[checked\_ceil][FixedU32::checked_ceil]</code>.
1528    fn checked_ceil(self) -> Option<Self>;
1529
1530    /// Checked floor. Rounds to the next integer towards &minus;∞, returning
1531    /// [`None`] on overflow.
1532    ///
1533    /// See also
1534    /// <code>FixedI32::[checked\_floor][FixedI32::checked_floor]</code> and
1535    /// <code>FixedU32::[checked\_floor][FixedU32::checked_floor]</code>.
1536    fn checked_floor(self) -> Option<Self>;
1537
1538    /// Checked round. Rounds to the nearest integer, with ties
1539    /// rounded away from zero, returning [`None`] on overflow.
1540    ///
1541    /// See also
1542    /// <code>FixedI32::[checked\_round][FixedI32::checked_round]</code> and
1543    /// <code>FixedU32::[checked\_round][FixedU32::checked_round]</code>.
1544    fn checked_round(self) -> Option<Self>;
1545
1546    /// Checked round. Rounds to the nearest integer, with ties rounded to even,
1547    /// returning [`None`] on overflow.
1548    ///
1549    /// See also
1550    /// <code>FixedI32::[checked\_round\_ties\_even][FixedI32::checked_round_ties_even]</code>
1551    /// and
1552    /// <code>FixedU32::[checked\_round\_ties\_even][FixedU32::checked_round_ties_even]</code>.
1553    fn checked_round_ties_even(self) -> Option<Self>;
1554
1555    /// Saturating ceil. Rounds to the next integer towards +∞,
1556    /// saturating on overflow.
1557    ///
1558    /// See also
1559    /// <code>FixedI32::[saturating\_ceil][FixedI32::saturating_ceil]</code> and
1560    /// <code>FixedU32::[saturating\_ceil][FixedU32::saturating_ceil]</code>.
1561    #[must_use]
1562    fn saturating_ceil(self) -> Self;
1563
1564    /// Saturating floor. Rounds to the next integer towards &minus;∞,
1565    /// saturating on overflow.
1566    ///
1567    /// See also
1568    /// <code>FixedI32::[saturating\_floor][FixedI32::saturating_floor]</code>
1569    /// and
1570    /// <code>FixedU32::[saturating\_floor][FixedU32::saturating_floor]</code>.
1571    #[must_use]
1572    fn saturating_floor(self) -> Self;
1573
1574    /// Saturating round. Rounds to the nearest integer, with ties
1575    /// rounded away from zero, and saturating on overflow.
1576    ///
1577    /// See also
1578    /// <code>FixedI32::[saturating\_round][FixedI32::saturating_round]</code>
1579    /// and
1580    /// <code>FixedU32::[saturating\_round][FixedU32::saturating_round]</code>.
1581    #[must_use]
1582    fn saturating_round(self) -> Self;
1583
1584    /// Saturating round. Rounds to the nearest integer, with ties rounded
1585    /// to_even, and saturating on overflow.
1586    ///
1587    /// See also
1588    /// <code>FixedI32::[saturating\_round\_ties\_even][FixedI32::saturating_round_ties_even]</code>
1589    /// and
1590    /// <code>FixedU32::[saturating\_round\_ties\_even][FixedU32::saturating_round_ties_even]</code>.
1591    #[must_use]
1592    fn saturating_round_ties_even(self) -> Self;
1593
1594    /// Wrapping ceil. Rounds to the next integer towards +∞, wrapping
1595    /// on overflow.
1596    ///
1597    /// See also
1598    /// <code>FixedI32::[wrapping\_ceil][FixedI32::wrapping_ceil]</code> and
1599    /// <code>FixedU32::[wrapping\_ceil][FixedU32::wrapping_ceil]</code>.
1600    #[must_use]
1601    fn wrapping_ceil(self) -> Self;
1602
1603    /// Wrapping floor. Rounds to the next integer towards &minus;∞,
1604    /// wrapping on overflow.
1605    ///
1606    /// See also
1607    /// <code>FixedI32::[wrapping\_floor][FixedI32::wrapping_floor]</code> and
1608    /// <code>FixedU32::[wrapping\_floor][FixedU32::wrapping_floor]</code>.
1609    #[must_use]
1610    fn wrapping_floor(self) -> Self;
1611
1612    /// Wrapping round. Rounds to the next integer to the nearest,
1613    /// with ties rounded away from zero, and wrapping on overflow.
1614    ///
1615    /// See also
1616    /// <code>FixedI32::[wrapping\_round][FixedI32::wrapping_round]</code> and
1617    /// <code>FixedU32::[wrapping\_round][FixedU32::wrapping_round]</code>.
1618    #[must_use]
1619    fn wrapping_round(self) -> Self;
1620
1621    /// Wrapping round. Rounds to the next integer to the nearest, with ties
1622    /// rounded to even, and wrapping on overflow.
1623    ///
1624    /// See also
1625    /// <code>FixedI32::[wrapping\_round\_ties\_even][FixedI32::wrapping_round_ties_even]</code>
1626    /// and
1627    /// <code>FixedU32::[wrapping\_round\_ties\_even][FixedU32::wrapping_round_ties_even]</code>.
1628    #[must_use]
1629    fn wrapping_round_ties_even(self) -> Self;
1630
1631    /// Strict ceil. Rounds to the next integer towards +∞,
1632    /// panicking on overflow.
1633    ///
1634    /// See also <code>FixedI32::[strict\_ceil][FixedI32::strict_ceil]</code>
1635    /// and <code>FixedU32::[strict\_ceil][FixedU32::strict_ceil]</code>.
1636    ///
1637    /// # Panics
1638    ///
1639    /// Panics if the result does not fit.
1640    #[track_caller]
1641    #[must_use]
1642    fn strict_ceil(self) -> Self;
1643
1644    /// Strict floor. Rounds to the next integer towards &minus;∞,
1645    /// panicking on overflow.
1646    ///
1647    /// See also <code>FixedI32::[strict\_floor][FixedI32::strict_floor]</code>
1648    /// and <code>FixedU32::[strict\_floor][FixedU32::strict_floor]</code>.
1649    ///
1650    /// # Panics
1651    ///
1652    /// Panics if the result does not fit.
1653    #[track_caller]
1654    #[must_use]
1655    fn strict_floor(self) -> Self;
1656
1657    /// Strict round. Rounds to the next integer to the nearest,
1658    /// with ties rounded away from zero, and panicking on overflow.
1659    ///
1660    /// See also <code>FixedI32::[strict\_round][FixedI32::strict_round]</code>
1661    /// and <code>FixedU32::[strict\_round][FixedU32::strict_round]</code>.
1662    ///
1663    /// # Panics
1664    ///
1665    /// Panics if the result does not fit.
1666    #[track_caller]
1667    #[must_use]
1668    fn strict_round(self) -> Self;
1669
1670    /// Strict round. Rounds to the next integer to the nearest, with ties
1671    /// rounded to even, and panicking on overflow.
1672    ///
1673    /// See also
1674    /// <code>FixedI32::[strict\_round\_ties\_even][FixedI32::strict_round_ties_even]</code>
1675    /// and
1676    /// <code>FixedU32::[strict\_round\_ties\_even][FixedU32::strict_round_ties_even]</code>.
1677    ///
1678    /// # Panics
1679    ///
1680    /// Panics if the result does not fit.
1681    #[track_caller]
1682    #[must_use]
1683    fn strict_round_ties_even(self) -> Self;
1684
1685    /// Overflowing ceil. Rounds to the next integer towards +∞.
1686    ///
1687    /// Returns a [tuple] of the fixed-point number and a [`bool`],
1688    /// indicating whether an overflow has occurred. On overflow, the
1689    /// wrapped value is returned.
1690    ///
1691    /// See also
1692    /// <code>FixedI32::[overflowing\_ceil][FixedI32::overflowing_ceil]</code>
1693    /// and
1694    /// <code>FixedU32::[overflowing\_ceil][FixedU32::overflowing_ceil]</code>.
1695    fn overflowing_ceil(self) -> (Self, bool);
1696
1697    /// Overflowing floor. Rounds to the next integer towards &minus;∞.
1698    ///
1699    /// Returns a [tuple] of the fixed-point number and a [`bool`],
1700    /// indicating whether an overflow has occurred. On overflow, the
1701    /// wrapped value is returned.
1702    ///
1703    /// See also
1704    /// <code>FixedI32::[overflowing\_floor][FixedI32::overflowing_floor]</code>
1705    /// and
1706    /// <code>FixedU32::[overflowing\_floor][FixedU32::overflowing_floor]</code>.
1707    fn overflowing_floor(self) -> (Self, bool);
1708
1709    /// Overflowing round. Rounds to the next integer to the nearest,
1710    /// with ties rounded away from zero.
1711    ///
1712    /// Returns a [tuple] of the fixed-point number and a [`bool`],
1713    /// indicating whether an overflow has occurred. On overflow, the
1714    /// wrapped value is returned.
1715    ///
1716    /// See also
1717    /// <code>FixedI32::[overflowing\_round][FixedI32::overflowing_round]</code>
1718    /// and
1719    /// <code>FixedU32::[overflowing\_round][FixedU32::overflowing_round]</code>.
1720    fn overflowing_round(self) -> (Self, bool);
1721
1722    /// Overflowing round. Rounds to the next integer to the nearest, with ties
1723    /// rounded to even.
1724    ///
1725    /// Returns a [tuple] of the fixed-point number and a [`bool`],
1726    /// indicating whether an overflow has occurred. On overflow, the
1727    /// wrapped value is returned.
1728    ///
1729    /// See also
1730    /// <code>FixedI32::[overflowing\_round\_ties\_even][FixedI32::overflowing_round_ties_even]</code>
1731    /// and
1732    /// <code>FixedU32::[overflowing\_round\_ties\_even][FixedU32::overflowing_round_ties_even]</code>.
1733    fn overflowing_round_ties_even(self) -> (Self, bool);
1734
1735    /// Returns the number of ones in the binary representation.
1736    ///
1737    /// See also <code>FixedI32::[count\_ones][FixedI32::count_ones]</code> and
1738    /// <code>FixedU32::[count\_ones][FixedU32::count_ones]</code>.
1739    #[doc(alias("popcount", "popcnt"))]
1740    fn count_ones(self) -> u32;
1741
1742    /// Returns the number of zeros in the binary representation.
1743    ///
1744    /// See also <code>FixedI32::[count\_zeros][FixedI32::count_zeros]</code>
1745    /// and <code>FixedU32::[count\_zeros][FixedU32::count_zeros]</code>.
1746    fn count_zeros(self) -> u32;
1747
1748    /// Returns the number of leading ones in the binary representation.
1749    ///
1750    /// See also <code>FixedI32::[leading\_ones][FixedI32::leading_ones]</code>
1751    /// and <code>FixedU32::[leading\_ones][FixedU32::leading_ones]</code>.
1752    fn leading_ones(self) -> u32;
1753
1754    /// Returns the number of leading zeros in the binary representation.
1755    ///
1756    /// See also
1757    /// <code>FixedI32::[leading\_zeros][FixedI32::leading_zeros]</code> and
1758    /// <code>FixedU32::[leading\_zeros][FixedU32::leading_zeros]</code>.
1759    fn leading_zeros(self) -> u32;
1760
1761    /// Returns the number of trailing ones in the binary representation.
1762    ///
1763    /// See also
1764    /// <code>FixedI32::[trailing\_ones][FixedI32::trailing_ones]</code> and
1765    /// <code>FixedU32::[trailing\_ones][FixedU32::trailing_ones]</code>.
1766    fn trailing_ones(self) -> u32;
1767
1768    /// Returns the number of trailing zeros in the binary representation.
1769    ///
1770    /// See also
1771    /// <code>FixedI32::[trailing\_zeros][FixedI32::trailing_zeros]</code> and
1772    /// <code>FixedU32::[trailing\_zeros][FixedU32::trailing_zeros]</code>.
1773    fn trailing_zeros(self) -> u32;
1774
1775    /// Integer base-2 logarithm, rounded down.
1776    ///
1777    /// See also <code>FixedI32::[int\_log2][FixedI32::int_log2]</code> and
1778    /// <code>FixedU32::[int\_log2][FixedU32::int_log2]</code>.
1779    ///
1780    /// # Panics
1781    ///
1782    /// Panics if the fixed-point number is ≤&nbsp;0.
1783    #[doc(alias("ilog2"))]
1784    fn int_log2(self) -> i32;
1785
1786    /// Integer base-10 logarithm, rounded down.
1787    ///
1788    /// See also <code>FixedI32::[int\_log10][FixedI32::int_log10]</code> and
1789    /// <code>FixedU32::[int\_log10][FixedU32::int_log10]</code>.
1790    ///
1791    /// # Panics
1792    ///
1793    /// Panics if the fixed-point number is ≤&nbsp;0.
1794    #[doc(alias("ilog10"))]
1795    fn int_log10(self) -> i32;
1796
1797    /// Integer logarithm to the specified base, rounded down.
1798    ///
1799    /// See also <code>FixedI32::[int\_log][FixedI32::int_log]</code> and
1800    /// <code>FixedU32::[int\_log][FixedU32::int_log]</code>.
1801    ///
1802    /// # Panics
1803    ///
1804    /// Panics if the fixed-point number is ≤&nbsp;0 or if the base is <&nbsp;2.
1805    #[doc(alias("ilog"))]
1806    fn int_log(self, base: u32) -> i32;
1807
1808    /// Checked integer base-2 logarithm, rounded down. Returns the
1809    /// logarithm or [`None`] if the fixed-point number is ≤&nbsp;0.
1810    ///
1811    /// See also
1812    /// <code>FixedI32::[checked\_int\_log2][FixedI32::checked_int_log2]</code>
1813    /// and
1814    /// <code>FixedU32::[checked\_int\_log2][FixedU32::checked_int_log2]</code>.
1815    #[doc(alias("checked_ilog2"))]
1816    fn checked_int_log2(self) -> Option<i32>;
1817
1818    /// Checked integer base-10 logarithm, rounded down. Returns the
1819    /// logarithm or [`None`] if the fixed-point number is ≤&nbsp;0.
1820    ///
1821    /// See also
1822    /// <code>FixedI32::[checked\_int\_log10][FixedI32::checked_int_log10]</code>
1823    /// and
1824    /// <code>FixedU32::[checked\_int\_log10][FixedU32::checked_int_log10]</code>.
1825    #[doc(alias("checked_ilog10"))]
1826    fn checked_int_log10(self) -> Option<i32>;
1827
1828    /// Checked integer logarithm to the specified base, rounded down. Returns
1829    /// the logarithm, or [`None`] if the fixed-point number is ≤&nbsp;0 or if
1830    /// the base is <&nbsp;2.
1831    ///
1832    /// See also
1833    /// <code>FixedI32::[checked\_int\_log][FixedI32::checked_int_log]</code>
1834    /// and
1835    /// <code>FixedU32::[checked\_int\_log][FixedU32::checked_int_log]</code>.
1836    #[doc(alias("checked_ilog"))]
1837    fn checked_int_log(self, base: u32) -> Option<i32>;
1838
1839    /// Reverses the order of the bits of the fixed-point number.
1840    ///
1841    /// See also <code>FixedI32::[reverse\_bits][FixedI32::reverse_bits]</code>
1842    /// and <code>FixedU32::[reverse\_bits][FixedU32::reverse_bits]</code>.
1843    #[must_use = "this returns the result of the operation, without modifying the original"]
1844    fn reverse_bits(self) -> Self;
1845
1846    /// Shifts to the left by `n` bits, wrapping the truncated bits to the right end.
1847    ///
1848    /// See also <code>FixedI32::[rotate\_left][FixedI32::rotate_left]</code>
1849    /// and <code>FixedU32::[rotate\_left][FixedU32::rotate_left]</code>.
1850    #[must_use = "this returns the result of the operation, without modifying the original"]
1851    fn rotate_left(self, n: u32) -> Self;
1852
1853    /// Shifts to the right by `n` bits, wrapping the truncated bits to the left end.
1854    ///
1855    /// See also <code>FixedI32::[rotate\_right][FixedI32::rotate_right]</code>
1856    /// and <code>FixedU32::[rotate\_right][FixedU32::rotate_right]</code>.
1857    #[must_use = "this returns the result of the operation, without modifying the original"]
1858    fn rotate_right(self, n: u32) -> Self;
1859
1860    /// Returns [`true`] if the number is zero.
1861    ///
1862    /// See also <code>FixedI32::[is\_zero][FixedI32::is_zero]</code> and
1863    /// <code>FixedU32::[is\_zero][FixedU32::is_zero]</code>.
1864    fn is_zero(self) -> bool;
1865
1866    /// Returns the distance from `self` to `other`.
1867    ///
1868    /// See also <code>FixedI32::[dist][FixedI32::dist]</code> and
1869    /// <code>FixedU32::[dist][FixedU32::dist]</code>.
1870    #[must_use = "this returns the result of the operation, without modifying the original"]
1871    fn dist(self, other: Self) -> Self;
1872
1873    /// Returns the absolute value of the difference between `self` and `other`
1874    /// using an unsigned type without any wrapping or panicking.
1875    ///
1876    /// See also <code>FixedI32::[abs\_diff][FixedI32::abs_diff]</code> and
1877    /// <code>FixedU32::[abs\_diff][FixedU32::abs_diff]</code>.
1878    #[must_use = "this returns the result of the operation, without modifying the original"]
1879    fn abs_diff(self, other: Self) -> Self::Unsigned;
1880
1881    /// Returns the mean of `self` and `other`.
1882    ///
1883    /// See also <code>FixedI32::[mean][FixedI32::mean]</code> and
1884    /// <code>FixedU32::[mean][FixedU32::mean]</code>.
1885    #[must_use = "this returns the result of the operation, without modifying the original"]
1886    fn mean(self, other: Self) -> Self;
1887
1888    /// Compute the hypotenuse of a right triange.
1889    ///
1890    /// See also <code>FixedI32::[hypot][FixedI32::hypot]</code> and
1891    /// <code>FixedU32::[hypot][FixedU32::hypot]</code>.
1892    #[must_use = "this returns the result of the operation, without modifying the original"]
1893    fn hypot(self, other: Self) -> Self;
1894
1895    /// Returns the reciprocal.
1896    ///
1897    /// See also <code>FixedI32::[recip][FixedI32::recip]</code> and
1898    /// <code>FixedU32::[recip][FixedU32::recip]</code>.
1899    ///
1900    /// # Panics
1901    ///
1902    /// Panics if `self` is zero.
1903    #[must_use]
1904    fn recip(self) -> Self;
1905
1906    /// Returns the next multiple of `other`.
1907    ///
1908    /// See also
1909    /// <code>FixedI32::[next\_multiple\_of][FixedI32::next_multiple_of]</code>
1910    /// and
1911    /// <code>FixedU32::[next\_multiple\_of][FixedU32::next_multiple_of]</code>.
1912    ///
1913    /// # Panics
1914    ///
1915    /// Panics if `other` is zero.
1916    #[must_use]
1917    fn next_multiple_of(self, other: Self) -> Self;
1918
1919    /// Multiply and add. Returns `self` × `mul` + `add`.
1920    ///
1921    /// Note that the inherent [`mul_add`] method is more flexible
1922    /// than this method and allows the `mul` parameter to have a
1923    /// fixed-point type like `self` but with a different number of
1924    /// fractional bits.
1925    ///
1926    /// [`mul_add`]: FixedI32::mul_add
1927    ///
1928    /// See also <code>FixedI32::[mul\_add][FixedI32::mul_add]</code> and
1929    /// <code>FixedU32::[mul\_add][FixedU32::mul_add]</code>.
1930    #[must_use = "this returns the result of the operation, without modifying the original"]
1931    fn mul_add(self, mul: Self, add: Self) -> Self;
1932
1933    /// Adds `self` to the product `a`&nbsp;×&nbsp;`b`.
1934    ///
1935    /// Note that the inherent [`add_prod`] method is more flexible than this
1936    /// method and allows the `a` and `b` parameters to have a fixed-point type
1937    /// like `self` but with a different number of fractional bits.
1938    ///
1939    /// [`add_prod`]: FixedI32::add_prod
1940    ///
1941    /// See also <code>FixedI32::[add\_prod][FixedI32::add_prod]</code> and
1942    /// <code>FixedU32::[add\_prod][FixedU32::add_prod]</code>.
1943    #[must_use]
1944    fn add_prod(self, a: Self, b: Self) -> Self;
1945
1946    /// Multiply and accumulate. Adds (`a` × `b`) to `self`.
1947    ///
1948    /// Note that the inherent [`mul_acc`] method is more flexible than this
1949    /// method and allows the `a` and `b` parameters to have a fixed-point type
1950    /// like `self` but with a different number of fractional bits.
1951    ///
1952    /// [`mul_acc`]: FixedI32::mul_acc
1953    ///
1954    /// See also <code>FixedI32::[mul\_acc][FixedI32::mul_acc]</code> and
1955    /// <code>FixedU32::[mul\_acc][FixedU32::mul_acc]</code>.
1956    fn mul_acc(&mut self, a: Self, b: Self);
1957
1958    /// Euclidean division by an integer.
1959    ///
1960    /// See also <code>FixedI32::[div\_euclid][FixedI32::div_euclid]</code> and
1961    /// <code>FixedU32::[div\_euclid][FixedU32::div_euclid]</code>.
1962    ///
1963    /// # Panics
1964    ///
1965    /// Panics if the divisor is zero or if the division results in overflow.
1966    #[must_use = "this returns the result of the operation, without modifying the original"]
1967    fn div_euclid(self, rhs: Self) -> Self;
1968
1969    /// Remainder for Euclidean division.
1970    ///
1971    /// See also <code>FixedI32::[rem\_euclid][FixedI32::rem_euclid]</code> and
1972    /// <code>FixedU32::[rem\_euclid][FixedU32::rem_euclid]</code>.
1973    ///
1974    /// # Panics
1975    ///
1976    /// Panics if the divisor is zero.
1977    #[must_use = "this returns the result of the operation, without modifying the original"]
1978    fn rem_euclid(self, rhs: Self) -> Self;
1979
1980    /// Euclidean division by an integer.
1981    ///
1982    /// See also
1983    /// <code>FixedI32::[div\_euclid\_int][FixedI32::div_euclid_int]</code> and
1984    /// <code>FixedU32::[div\_euclid\_int][FixedU32::div_euclid_int]</code>.
1985    ///
1986    /// # Panics
1987    ///
1988    /// Panics if the divisor is zero or if the division results in overflow.
1989    #[must_use = "this returns the result of the operation, without modifying the original"]
1990    fn div_euclid_int(self, rhs: Self::Bits) -> Self;
1991
1992    /// Remainder for Euclidean division by an integer.
1993    ///
1994    /// See also
1995    /// <code>FixedI32::[rem\_euclid\_int][FixedI32::rem_euclid_int]</code> and
1996    /// <code>FixedU32::[rem\_euclid\_int][FixedU32::rem_euclid_int]</code>.
1997    ///
1998    /// # Panics
1999    ///
2000    /// Panics if the divisor is zero or if the division results in overflow.
2001    #[must_use = "this returns the result of the operation, without modifying the original"]
2002    fn rem_euclid_int(self, rhs: Self::Bits) -> Self;
2003
2004    /// Unbounded shift left. Computes `self << rhs`, without bounding the value
2005    /// of `rhs`.
2006    ///
2007    /// See also
2008    /// <code>FixedI32::[unbounded\_shl][FixedI32::unbounded_shl]</code> and
2009    /// <code>FixedU32::[unbounded\_shl][FixedU32::unbounded_shl]</code>.
2010    #[must_use = "this returns the result of the operation, without modifying the original"]
2011    fn unbounded_shl(self, rhs: u32) -> Self;
2012
2013    /// Unbounded shift right. Computes `self >> rhs`, without bounding the
2014    /// value of `rhs`.
2015    ///
2016    /// See also
2017    /// <code>FixedI32::[unbounded\_shr][FixedI32::unbounded_shr]</code> and
2018    /// <code>FixedU32::[unbounded\_shr][FixedU32::unbounded_shr]</code>.
2019    #[must_use = "this returns the result of the operation, without modifying the original"]
2020    fn unbounded_shr(self, rhs: u32) -> Self;
2021
2022    /// Returns the square root.
2023    ///
2024    /// See also <code>FixedI32::[sqrt][FixedI32::sqrt]</code> and
2025    /// <code>FixedU32::[sqrt][FixedU32::sqrt]</code>.
2026    ///
2027    /// # Panics
2028    ///
2029    /// Panics if the number is negative.
2030    fn sqrt(self) -> Self;
2031
2032    /// Linear interpolation between `start` and `end`.
2033    ///
2034    /// See also <code>FixedI32::[lerp][FixedI32::lerp]</code> and
2035    /// <code>FixedU32::[lerp][FixedU32::lerp]</code>.
2036    #[must_use]
2037    fn lerp(self, start: Self, end: Self) -> Self;
2038
2039    /// Inverse linear interpolation between `start` and `end`.
2040    ///
2041    /// See also <code>FixedI32::[inv\_lerp][FixedI32::inv_lerp]</code> and
2042    /// <code>FixedU32::[inv\_lerp][FixedU32::inv_lerp]</code>.
2043    #[must_use]
2044    fn inv_lerp(self, start: Self, end: Self) -> Self;
2045
2046    /// Checked negation. Returns the negated value, or [`None`] on overflow.
2047    ///
2048    /// See also <code>FixedI32::[checked\_neg][FixedI32::checked_neg]</code>
2049    /// and <code>FixedU32::[checked\_neg][FixedU32::checked_neg]</code>.
2050    fn checked_neg(self) -> Option<Self>;
2051
2052    /// Checked addition. Returns the sum, or [`None`] on overflow.
2053    ///
2054    /// See also <code>FixedI32::[checked\_add][FixedI32::checked_add]</code>
2055    /// and <code>FixedU32::[checked\_add][FixedU32::checked_add]</code>.
2056    #[must_use = "this returns the result of the operation, without modifying the original"]
2057    fn checked_add(self, rhs: Self) -> Option<Self>;
2058
2059    /// Checked subtraction. Returns the difference, or [`None`] on overflow.
2060    ///
2061    /// See also <code>FixedI32::[checked\_sub][FixedI32::checked_sub]</code>
2062    /// and <code>FixedU32::[checked\_sub][FixedU32::checked_sub]</code>.
2063    #[must_use = "this returns the result of the operation, without modifying the original"]
2064    fn checked_sub(self, rhs: Self) -> Option<Self>;
2065
2066    /// Checked multiplication. Returns the product, or [`None`] on overflow.
2067    ///
2068    /// See also <code>FixedI32::[checked\_mul][FixedI32::checked_mul]</code>
2069    /// and <code>FixedU32::[checked\_mul][FixedU32::checked_mul]</code>.
2070    #[must_use = "this returns the result of the operation, without modifying the original"]
2071    fn checked_mul(self, rhs: Self) -> Option<Self>;
2072
2073    /// Checked division. Returns the quotient, or [`None`] if the
2074    /// divisor is zero or on overflow.
2075    ///
2076    /// See also <code>FixedI32::[checked\_div][FixedI32::checked_div]</code>
2077    /// and <code>FixedU32::[checked\_div][FixedU32::checked_div]</code>.
2078    #[must_use = "this returns the result of the operation, without modifying the original"]
2079    fn checked_div(self, rhs: Self) -> Option<Self>;
2080
2081    /// Checked remainder. Returns the remainder, or [`None`] if the
2082    /// divisor is zero.
2083    ///
2084    /// See also <code>FixedI32::[checked\_rem][FixedI32::checked_rem]</code>
2085    /// and <code>FixedU32::[checked\_rem][FixedU32::checked_rem]</code>.
2086    #[must_use = "this returns the result of the operation, without modifying the original"]
2087    fn checked_rem(self, rhs: Self) -> Option<Self>;
2088
2089    /// Checked reciprocal. Returns the reciprocal, or [`None`] if
2090    /// `self` is zero or on overflow.
2091    ///
2092    /// See also
2093    /// <code>FixedI32::[checked\_recip][FixedI32::checked_recip]</code> and
2094    /// <code>FixedU32::[checked\_recip][FixedU32::checked_recip]</code>.
2095    fn checked_recip(self) -> Option<Self>;
2096
2097    /// Checked next multiple of `other`. Returns the next multiple, or [`None`]
2098    /// if `other` is zero or on overflow.
2099    ///
2100    /// See also
2101    /// <code>FixedI32::[checked\_next\_multiple\_of][FixedI32::checked_next_multiple_of]</code>
2102    /// and
2103    /// <code>FixedU32::[checked\_next\_multiple\_of][FixedU32::checked_next_multiple_of]</code>.
2104    #[must_use]
2105    fn checked_next_multiple_of(self, other: Self) -> Option<Self>;
2106
2107    /// Checked multiply and add. Returns `self` × `mul` + `add`, or [`None`] on overflow.
2108    ///
2109    /// See also
2110    /// <code>FixedI32::[checked\_mul\_add][FixedI32::checked_mul_add]</code>
2111    /// and
2112    /// <code>FixedU32::[checked\_mul\_add][FixedU32::checked_mul_add]</code>.
2113    #[must_use = "this returns the result of the operation, without modifying the original"]
2114    fn checked_mul_add(self, mul: Self, add: Self) -> Option<Self>;
2115
2116    /// Adds `self` to the product `a`&nbsp;×&nbsp;`b`, returning [`None`] on overflow.
2117    ///
2118    /// See also
2119    /// <code>FixedI32::[checked\_add\_prod][FixedI32::checked_add_prod]</code>
2120    /// and
2121    /// <code>FixedU32::[checked\_add\_prod][FixedU32::checked_add_prod]</code>.
2122    #[must_use = "this `Option` may be a `None` variant indicating overflow, which should be handled"]
2123    fn checked_add_prod(self, a: Self, b: Self) -> Option<Self>;
2124
2125    /// Checked multiply and accumulate. Adds (`a` × `b`) to `self`, or returns
2126    /// [`None`] on overflow.
2127    ///
2128    /// See also
2129    /// <code>FixedI32::[checked\_mul\_acc][FixedI32::checked_mul_acc]</code>
2130    /// and
2131    /// <code>FixedU32::[checked\_mul\_acc][FixedU32::checked_mul_acc]</code>.
2132    #[must_use = "this `Option` may be a `None` variant indicating overflow, which should be handled"]
2133    fn checked_mul_acc(&mut self, a: Self, b: Self) -> Option<()>;
2134
2135    /// Checked remainder for Euclidean division. Returns the
2136    /// remainder, or [`None`] if the divisor is zero or the division
2137    /// results in overflow.
2138    ///
2139    /// See also
2140    /// <code>FixedI32::[checked\_div\_euclid][FixedI32::checked_div_euclid]</code>
2141    /// and
2142    /// <code>FixedU32::[checked\_div\_euclid][FixedU32::checked_div_euclid]</code>.
2143    #[must_use = "this returns the result of the operation, without modifying the original"]
2144    fn checked_div_euclid(self, rhs: Self) -> Option<Self>;
2145
2146    /// Checked remainder for Euclidean division. Returns the
2147    /// remainder, or [`None`] if the divisor is zero.
2148    ///
2149    /// See also
2150    /// <code>FixedI32::[checked\_rem\_euclid][FixedI32::checked_rem_euclid]</code>
2151    /// and
2152    /// <code>FixedU32::[checked\_rem\_euclid][FixedU32::checked_rem_euclid]</code>.
2153    #[must_use = "this returns the result of the operation, without modifying the original"]
2154    fn checked_rem_euclid(self, rhs: Self) -> Option<Self>;
2155
2156    /// Checked multiplication by an integer. Returns the product, or
2157    /// [`None`] on overflow.
2158    ///
2159    /// See also
2160    /// <code>FixedI32::[checked\_mul\_int][FixedI32::checked_mul_int]</code>
2161    /// and
2162    /// <code>FixedU32::[checked\_mul\_int][FixedU32::checked_mul_int]</code>.
2163    #[must_use = "this returns the result of the operation, without modifying the original"]
2164    fn checked_mul_int(self, rhs: Self::Bits) -> Option<Self>;
2165
2166    /// Checked division by an integer. Returns the quotient, or
2167    /// [`None`] if the divisor is zero or if the division results in
2168    /// overflow.
2169    ///
2170    /// See also
2171    /// <code>FixedI32::[checked\_div\_int][FixedI32::checked_div_int]</code>
2172    /// and
2173    /// <code>FixedU32::[checked\_div\_int][FixedU32::checked_div_int]</code>.
2174    #[must_use = "this returns the result of the operation, without modifying the original"]
2175    fn checked_div_int(self, rhs: Self::Bits) -> Option<Self>;
2176
2177    /// Checked fixed-point remainder for division by an integer.
2178    /// Returns the remainder, or [`None`] if the divisor is zero or
2179    /// if the division results in overflow.
2180    ///
2181    /// See also
2182    /// <code>FixedI32::[checked\_rem\_int][FixedI32::checked_rem_int]</code>
2183    /// and
2184    /// <code>FixedU32::[checked\_rem\_int][FixedU32::checked_rem_int]</code>.
2185    #[must_use = "this returns the result of the operation, without modifying the original"]
2186    fn checked_rem_int(self, rhs: Self::Bits) -> Option<Self>;
2187
2188    /// Checked Euclidean division by an integer. Returns the
2189    /// quotient, or [`None`] if the divisor is zero or if the
2190    /// division results in overflow.
2191    ///
2192    /// See also
2193    /// <code>FixedI32::[checked\_div\_euclid\_int][FixedI32::checked_div_euclid_int]</code>
2194    /// and
2195    /// <code>FixedU32::[checked\_div\_euclid\_int][FixedU32::checked_div_euclid_int]</code>.
2196    #[must_use = "this returns the result of the operation, without modifying the original"]
2197    fn checked_div_euclid_int(self, rhs: Self::Bits) -> Option<Self>;
2198
2199    /// Checked remainder for Euclidean division by an integer.
2200    /// Returns the remainder, or [`None`] if the divisor is zero or
2201    /// if the remainder results in overflow.
2202    ///
2203    /// See also
2204    /// <code>FixedI32::[checked\_rem\_euclid\_int][FixedI32::checked_rem_euclid_int]</code>
2205    /// and
2206    /// <code>FixedU32::[checked\_rem\_euclid\_int][FixedU32::checked_rem_euclid_int]</code>.
2207    #[must_use = "this returns the result of the operation, without modifying the original"]
2208    fn checked_rem_euclid_int(self, rhs: Self::Bits) -> Option<Self>;
2209
2210    /// Checked shift left. Returns the shifted number, or [`None`] if
2211    /// `rhs`&nbsp;≥ the number of bits.
2212    ///
2213    /// See also <code>FixedI32::[checked\_shl][FixedI32::checked_shl]</code>
2214    /// and <code>FixedU32::[checked\_shl][FixedU32::checked_shl]</code>.
2215    #[must_use = "this returns the result of the operation, without modifying the original"]
2216    fn checked_shl(self, rhs: u32) -> Option<Self>;
2217
2218    /// Checked shift right. Returns the shifted number, or [`None`]
2219    /// if `rhs`&nbsp;≥ the number of bits.
2220    ///
2221    /// See also <code>FixedI32::[checked\_shr][FixedI32::checked_shr]</code>
2222    /// and <code>FixedU32::[checked\_shr][FixedU32::checked_shr]</code>.
2223    #[must_use = "this returns the result of the operation, without modifying the original"]
2224    fn checked_shr(self, rhs: u32) -> Option<Self>;
2225
2226    /// Checked distance. Returns the distance from `self` to `other`, or
2227    /// [`None`] on overflow.
2228    ///
2229    /// See also <code>FixedI32::[checked\_dist][FixedI32::checked_dist]</code>
2230    /// and <code>FixedU32::[checked\_dist][FixedU32::checked_dist]</code>.
2231    #[must_use = "this returns the result of the operation, without modifying the original"]
2232    fn checked_dist(self, other: Self) -> Option<Self>;
2233
2234    /// Compute the hypotenuse of a right triange, returning [`None`] on
2235    /// overflow.
2236    ///
2237    /// See also
2238    /// <code>FixedI32::[checked\_hypot][FixedI32::checked_hypot]</code> and
2239    /// <code>FixedU32::[checked\_hypot][FixedU32::checked_hypot]</code>.
2240    #[must_use = "this returns the result of the operation, without modifying the original"]
2241    fn checked_hypot(self, other: Self) -> Option<Self>;
2242
2243    /// Checked square root. Returns [`None`] for negative numbers or on overflow.
2244    ///
2245    /// See also <code>FixedI32::[checked\_sqrt][FixedI32::checked_sqrt]</code>
2246    /// and <code>FixedU32::[checked\_sqrt][FixedU32::checked_sqrt]</code>.
2247    fn checked_sqrt(self) -> Option<Self>;
2248
2249    /// Checked linear interpolation between `start` and `end`. Returns [`None`]
2250    /// on overflow.
2251    ///
2252    /// See also <code>FixedI32::[checked\_lerp][FixedI32::checked_lerp]</code>
2253    /// and <code>FixedU32::[checked\_lerp][FixedU32::checked_lerp]</code>.
2254    fn checked_lerp(self, start: Self, end: Self) -> Option<Self>;
2255
2256    /// Checked inverse linear interpolation between `start` and `end`. Returns
2257    /// [`None`] when `start`&nbsp;=&nbsp;`end` or on overflow.
2258    ///
2259    /// See also
2260    /// <code>FixedI32::[checked\_inv\_lerp][FixedI32::checked_inv_lerp]</code>
2261    /// and
2262    /// <code>FixedU32::[checked\_inv\_lerp][FixedU32::checked_inv_lerp]</code>.
2263    fn checked_inv_lerp(self, start: Self, end: Self) -> Option<Self>;
2264
2265    /// Saturated negation. Returns the negated value, saturating on overflow.
2266    ///
2267    /// See also
2268    /// <code>FixedI32::[saturating\_neg][FixedI32::saturating_neg]</code> and
2269    /// <code>FixedU32::[saturating\_neg][FixedU32::saturating_neg]</code>.
2270    #[must_use]
2271    fn saturating_neg(self) -> Self;
2272
2273    /// Saturating addition. Returns the sum, saturating on overflow.
2274    ///
2275    /// See also
2276    /// <code>FixedI32::[saturating\_add][FixedI32::saturating_add]</code> and
2277    /// <code>FixedU32::[saturating\_add][FixedU32::saturating_add]</code>.
2278    #[must_use = "this returns the result of the operation, without modifying the original"]
2279    fn saturating_add(self, rhs: Self) -> Self;
2280
2281    /// Saturating subtraction. Returns the difference, saturating on overflow.
2282    ///
2283    /// See also
2284    /// <code>FixedI32::[saturating\_sub][FixedI32::saturating_sub]</code> and
2285    /// <code>FixedU32::[saturating\_sub][FixedU32::saturating_sub]</code>.
2286    #[must_use = "this returns the result of the operation, without modifying the original"]
2287    fn saturating_sub(self, rhs: Self) -> Self;
2288
2289    /// Saturating multiplication. Returns the product, saturating on overflow.
2290    ///
2291    /// See also
2292    /// <code>FixedI32::[saturating\_mul][FixedI32::saturating_mul]</code> and
2293    /// <code>FixedU32::[saturating\_mul][FixedU32::saturating_mul]</code>.
2294    #[must_use = "this returns the result of the operation, without modifying the original"]
2295    fn saturating_mul(self, rhs: Self) -> Self;
2296
2297    /// Saturating division. Returns the quotient, saturating on overflow.
2298    ///
2299    /// See also
2300    /// <code>FixedI32::[saturating\_div][FixedI32::saturating_div]</code> and
2301    /// <code>FixedU32::[saturating\_div][FixedU32::saturating_div]</code>.
2302    ///
2303    /// # Panics
2304    ///
2305    /// Panics if the divisor is zero.
2306    #[must_use = "this returns the result of the operation, without modifying the original"]
2307    fn saturating_div(self, rhs: Self) -> Self;
2308
2309    /// Saturating reciprocal.
2310    ///
2311    /// See also
2312    /// <code>FixedI32::[saturating\_recip][FixedI32::saturating_recip]</code>
2313    /// and
2314    /// <code>FixedU32::[saturating\_recip][FixedU32::saturating_recip]</code>.
2315    ///
2316    /// # Panics
2317    ///
2318    /// Panics if `self` is zero.
2319    #[must_use]
2320    fn saturating_recip(self) -> Self;
2321
2322    /// Saturating next multiple of `other`.
2323    ///
2324    /// See also
2325    /// <code>FixedI32::[saturating\_next\_multiple\_of][FixedI32::saturating_next_multiple_of]</code>
2326    /// and
2327    /// <code>FixedU32::[saturating\_next\_multiple\_of][FixedU32::saturating_next_multiple_of]</code>.
2328    ///
2329    /// # Panics
2330    ///
2331    /// Panics if `other` is zero.
2332    #[must_use]
2333    fn saturating_next_multiple_of(self, other: Self) -> Self;
2334
2335    /// Saturating multiply and add. Returns `self` × `mul` + `add`, saturating on overflow.
2336    ///
2337    /// See also
2338    /// <code>FixedI32::[saturating\_mul\_add][FixedI32::saturating_mul_add]</code>
2339    /// and
2340    /// <code>FixedU32::[saturating\_mul\_add][FixedU32::saturating_mul_add]</code>.
2341    #[must_use = "this returns the result of the operation, without modifying the original"]
2342    fn saturating_mul_add(self, mul: Self, add: Self) -> Self;
2343
2344    /// Adds `self` to the product `a`&nbsp;×&nbsp;`b`, saturating on overflow.
2345    ///
2346    /// See also
2347    /// <code>FixedI32::[saturating\_add\_prod][FixedI32::saturating_add_prod]</code>
2348    /// and
2349    /// <code>FixedU32::[saturating\_add\_prod][FixedU32::saturating_add_prod]</code>.
2350    #[must_use]
2351    fn saturating_add_prod(self, a: Self, b: Self) -> Self;
2352
2353    /// Saturating multiply and add. Adds (`a` × `b`) to `self`, saturating on overflow.
2354    ///
2355    /// See also
2356    /// <code>FixedI32::[saturating\_mul\_acc][FixedI32::saturating_mul_acc]</code>
2357    /// and
2358    /// <code>FixedU32::[saturating\_mul\_acc][FixedU32::saturating_mul_acc]</code>.
2359    fn saturating_mul_acc(&mut self, a: Self, b: Self);
2360
2361    /// Saturating Euclidean division. Returns the quotient, saturating on overflow.
2362    ///
2363    /// See also
2364    /// <code>FixedI32::[saturating\_div\_euclid][FixedI32::saturating_div_euclid]</code>
2365    /// and
2366    /// <code>FixedU32::[saturating\_div\_euclid][FixedU32::saturating_div_euclid]</code>.
2367    ///
2368    /// # Panics
2369    ///
2370    /// Panics if the divisor is zero.
2371    #[must_use = "this returns the result of the operation, without modifying the original"]
2372    fn saturating_div_euclid(self, rhs: Self) -> Self;
2373
2374    /// Saturating multiplication by an integer. Returns the product, saturating on overflow.
2375    ///
2376    /// See also
2377    /// <code>FixedI32::[saturating\_mul\_int][FixedI32::saturating_mul_int]</code>
2378    /// and
2379    /// <code>FixedU32::[saturating\_mul\_int][FixedU32::saturating_mul_int]</code>.
2380    #[must_use = "this returns the result of the operation, without modifying the original"]
2381    fn saturating_mul_int(self, rhs: Self::Bits) -> Self;
2382
2383    /// Saturating division by an integer. Returns the quotient, saturating on overflow.
2384    ///
2385    /// Overflow can only occur when dividing the minimum value by &minus;1.
2386    ///
2387    /// See also
2388    /// <code>FixedI32::[saturating\_div\_int][FixedI32::saturating_div_int]</code>
2389    /// and
2390    /// <code>FixedU32::[saturating\_div\_int][FixedU32::saturating_div_int]</code>.
2391    ///
2392    /// # Panics
2393    ///
2394    /// Panics if the divisor is zero.
2395    #[must_use = "this returns the result of the operation, without modifying the original"]
2396    fn saturating_div_int(self, rhs: Self::Bits) -> Self;
2397
2398    /// Saturating Euclidean division by an integer. Returns the
2399    /// quotient, saturating on overflow.
2400    ///
2401    /// See also
2402    /// <code>FixedI32::[saturating\_div\_euclid\_int][FixedI32::saturating_div_euclid_int]</code>
2403    /// and
2404    /// <code>FixedU32::[saturating\_div\_euclid\_int][FixedU32::saturating_div_euclid_int]</code>.
2405    ///
2406    /// # Panics
2407    ///
2408    /// Panics if the divisor is zero.
2409    #[must_use = "this returns the result of the operation, without modifying the original"]
2410    fn saturating_div_euclid_int(self, rhs: Self::Bits) -> Self;
2411
2412    /// Saturating remainder for Euclidean division by an integer.
2413    /// Returns the remainder, saturating on overflow.
2414    ///
2415    /// See also
2416    /// <code>FixedI32::[saturating\_rem\_euclid\_int][FixedI32::saturating_rem_euclid_int]</code>
2417    /// and
2418    /// <code>FixedU32::[saturating\_rem\_euclid\_int][FixedU32::saturating_rem_euclid_int]</code>.
2419    ///
2420    /// # Panics
2421    ///
2422    /// Panics if the divisor is zero.
2423    #[must_use = "this returns the result of the operation, without modifying the original"]
2424    fn saturating_rem_euclid_int(self, rhs: Self::Bits) -> Self;
2425
2426    /// Saturating distance. Returns the distance from `self` to `other`,
2427    /// saturating on overflow.
2428    ///
2429    /// See also
2430    /// <code>FixedI32::[saturating\_dist][FixedI32::saturating_dist]</code> and
2431    /// <code>FixedU32::[saturating\_dist][FixedU32::saturating_dist]</code>.
2432    #[must_use = "this returns the result of the operation, without modifying the original"]
2433    fn saturating_dist(self, other: Self) -> Self;
2434
2435    /// Compute the hypotenuse of a right triange, saturating on overflow.
2436    ///
2437    /// See also
2438    /// <code>FixedI32::[saturating\_hypot][FixedI32::saturating_hypot]</code>
2439    /// and
2440    /// <code>FixedU32::[saturating\_hypot][FixedU32::saturating_hypot]</code>.
2441    #[must_use = "this returns the result of the operation, without modifying the original"]
2442    fn saturating_hypot(self, other: Self) -> Self;
2443
2444    /// Returns the square root, saturating on overflow.
2445    ///
2446    /// See also
2447    /// <code>FixedI32::[saturating\_sqrt][FixedI32::saturating_sqrt]</code> and
2448    /// <code>FixedU32::[saturating\_sqrt][FixedU32::saturating_sqrt]</code>.
2449    ///
2450    /// # Panics
2451    ///
2452    /// Panics if the number is negative.
2453    fn saturating_sqrt(self) -> Self;
2454
2455    /// Linear interpolation between `start` and `end`, saturating on overflow.
2456    ///
2457    /// See also
2458    /// <code>FixedI32::[saturating\_lerp][FixedI32::saturating_lerp]</code> and
2459    /// <code>FixedU32::[saturating\_lerp][FixedU32::saturating_lerp]</code>.
2460    #[must_use]
2461    fn saturating_lerp(self, start: Self, end: Self) -> Self;
2462
2463    /// Inverse linear interpolation between `start` and `end`, saturating on overflow.
2464    ///
2465    /// See also
2466    /// <code>FixedI32::[saturating\_inv\_lerp][FixedI32::saturating_inv_lerp]</code>
2467    /// and
2468    /// <code>FixedU32::[saturating\_inv\_lerp][FixedU32::saturating_inv_lerp]</code>.
2469    #[must_use]
2470    fn saturating_inv_lerp(self, start: Self, end: Self) -> Self;
2471
2472    /// Wrapping negation. Returns the negated value, wrapping on overflow.
2473    ///
2474    /// See also <code>FixedI32::[wrapping\_neg][FixedI32::wrapping_neg]</code>
2475    /// and <code>FixedU32::[wrapping\_neg][FixedU32::wrapping_neg]</code>.
2476    #[must_use]
2477    fn wrapping_neg(self) -> Self;
2478
2479    /// Wrapping addition. Returns the sum, wrapping on overflow.
2480    ///
2481    /// See also <code>FixedI32::[wrapping\_add][FixedI32::wrapping_add]</code>
2482    /// and <code>FixedU32::[wrapping\_add][FixedU32::wrapping_add]</code>.
2483    #[must_use = "this returns the result of the operation, without modifying the original"]
2484    fn wrapping_add(self, rhs: Self) -> Self;
2485
2486    /// Wrapping subtraction. Returns the difference, wrapping on overflow.
2487    ///
2488    /// See also <code>FixedI32::[wrapping\_sub][FixedI32::wrapping_sub]</code>
2489    /// and <code>FixedU32::[wrapping\_sub][FixedU32::wrapping_sub]</code>.
2490    #[must_use = "this returns the result of the operation, without modifying the original"]
2491    fn wrapping_sub(self, rhs: Self) -> Self;
2492
2493    /// Wrapping multiplication. Returns the product, wrapping on overflow.
2494    ///
2495    /// See also <code>FixedI32::[wrapping\_mul][FixedI32::wrapping_mul]</code>
2496    /// and <code>FixedU32::[wrapping\_mul][FixedU32::wrapping_mul]</code>.
2497    #[must_use = "this returns the result of the operation, without modifying the original"]
2498    fn wrapping_mul(self, rhs: Self) -> Self;
2499
2500    /// Wrapping division. Returns the quotient, wrapping on overflow.
2501    ///
2502    /// See also <code>FixedI32::[wrapping\_div][FixedI32::wrapping_div]</code>
2503    /// and <code>FixedU32::[wrapping\_div][FixedU32::wrapping_div]</code>.
2504    ///
2505    /// # Panics
2506    ///
2507    /// Panics if the divisor is zero.
2508    #[must_use = "this returns the result of the operation, without modifying the original"]
2509    fn wrapping_div(self, rhs: Self) -> Self;
2510
2511    /// Wrapping reciprocal.
2512    ///
2513    /// See also
2514    /// <code>FixedI32::[wrapping\_recip][FixedI32::wrapping_recip]</code> and
2515    /// <code>FixedU32::[wrapping\_recip][FixedU32::wrapping_recip]</code>.
2516    ///
2517    /// # Panics
2518    ///
2519    /// Panics if `self` is zero.
2520    #[must_use]
2521    fn wrapping_recip(self) -> Self;
2522
2523    /// Wrapping next multiple of `other`.
2524    ///
2525    /// See also
2526    /// <code>FixedI32::[wrapping\_next\_multiple\_of][FixedI32::wrapping_next_multiple_of]</code>
2527    /// and
2528    /// <code>FixedU32::[wrapping\_next\_multiple\_of][FixedU32::wrapping_next_multiple_of]</code>.
2529    ///
2530    /// # Panics
2531    ///
2532    /// Panics if `other` is zero.
2533    #[must_use]
2534    fn wrapping_next_multiple_of(self, other: Self) -> Self;
2535
2536    /// Wrapping multiply and add. Returns `self` × `mul` + `add`, wrapping on overflow.
2537    ///
2538    /// See also
2539    /// <code>FixedI32::[wrapping\_mul\_add][FixedI32::wrapping_mul_add]</code>
2540    /// and
2541    /// <code>FixedU32::[wrapping\_mul\_add][FixedU32::wrapping_mul_add]</code>.
2542    #[must_use = "this returns the result of the operation, without modifying the original"]
2543    fn wrapping_mul_add(self, mul: Self, add: Self) -> Self;
2544
2545    /// Adds `self` to the product `a`&nbsp;×&nbsp;`b`, wrapping on overflow.
2546    ///
2547    /// See also
2548    /// <code>FixedI32::[wrapping\_add\_prod][FixedI32::wrapping_add_prod]</code>
2549    /// and
2550    /// <code>FixedU32::[wrapping\_add\_prod][FixedU32::wrapping_add_prod]</code>.
2551    #[must_use]
2552    fn wrapping_add_prod(self, a: Self, b: Self) -> Self;
2553
2554    /// Wrapping multiply and accumulate. Adds (`a` × `b`) to `self`, wrapping on overflow.
2555    ///
2556    /// See also
2557    /// <code>FixedI32::[wrapping\_mul\_acc][FixedI32::wrapping_mul_acc]</code>
2558    /// and
2559    /// <code>FixedU32::[wrapping\_mul\_acc][FixedU32::wrapping_mul_acc]</code>.
2560    fn wrapping_mul_acc(&mut self, a: Self, b: Self);
2561
2562    /// Wrapping Euclidean division. Returns the quotient, wrapping on overflow.
2563    ///
2564    /// See also
2565    /// <code>FixedI32::[wrapping\_div\_euclid][FixedI32::wrapping_div_euclid]</code>
2566    /// and
2567    /// <code>FixedU32::[wrapping\_div\_euclid][FixedU32::wrapping_div_euclid]</code>.
2568    ///
2569    /// # Panics
2570    ///
2571    /// Panics if the divisor is zero.
2572    #[must_use = "this returns the result of the operation, without modifying the original"]
2573    fn wrapping_div_euclid(self, rhs: Self) -> Self;
2574
2575    /// Wrapping multiplication by an integer. Returns the product, wrapping on overflow.
2576    ///
2577    /// See also
2578    /// <code>FixedI32::[wrapping\_mul\_int][FixedI32::wrapping_mul_int]</code>
2579    /// and
2580    /// <code>FixedU32::[wrapping\_mul\_int][FixedU32::wrapping_mul_int]</code>.
2581    #[must_use = "this returns the result of the operation, without modifying the original"]
2582    fn wrapping_mul_int(self, rhs: Self::Bits) -> Self;
2583
2584    /// Wrapping division by an integer. Returns the quotient, wrapping on overflow.
2585    ///
2586    /// Overflow can only occur when dividing the minimum value by &minus;1.
2587    ///
2588    /// See also
2589    /// <code>FixedI32::[wrapping\_div\_int][FixedI32::wrapping_div_int]</code>
2590    /// and
2591    /// <code>FixedU32::[wrapping\_div\_int][FixedU32::wrapping_div_int]</code>.
2592    ///
2593    /// # Panics
2594    ///
2595    /// Panics if the divisor is zero.
2596    #[must_use = "this returns the result of the operation, without modifying the original"]
2597    fn wrapping_div_int(self, rhs: Self::Bits) -> Self;
2598
2599    /// Wrapping Euclidean division by an integer. Returns the
2600    /// quotient, wrapping on overflow.
2601    ///
2602    /// Overflow can only occur when dividing the minimum value by &minus;1.
2603    ///
2604    /// See also
2605    /// <code>FixedI32::[wrapping\_div\_euclid\_int][FixedI32::wrapping_div_euclid_int]</code>
2606    /// and
2607    /// <code>FixedU32::[wrapping\_div\_euclid\_int][FixedU32::wrapping_div_euclid_int]</code>.
2608    ///
2609    /// # Panics
2610    ///
2611    /// Panics if the divisor is zero.
2612    #[must_use = "this returns the result of the operation, without modifying the original"]
2613    fn wrapping_div_euclid_int(self, rhs: Self::Bits) -> Self;
2614
2615    /// Wrapping remainder for Euclidean division by an integer.
2616    /// Returns the remainder, wrapping on overflow.
2617    ///
2618    /// See also
2619    /// <code>FixedI32::[wrapping\_rem\_euclid\_int][FixedI32::wrapping_rem_euclid_int]</code>
2620    /// and
2621    /// <code>FixedU32::[wrapping\_rem\_euclid\_int][FixedU32::wrapping_rem_euclid_int]</code>.
2622    ///
2623    /// # Panics
2624    ///
2625    /// Panics if the divisor is zero.
2626    #[must_use = "this returns the result of the operation, without modifying the original"]
2627    fn wrapping_rem_euclid_int(self, rhs: Self::Bits) -> Self;
2628
2629    /// Wrapping shift left. Wraps `rhs` if `rhs`&nbsp;≥ the number of
2630    /// bits, then shifts and returns the number.
2631    ///
2632    /// See also <code>FixedI32::[wrapping\_shl][FixedI32::wrapping_shl]</code>
2633    /// and <code>FixedU32::[wrapping\_shl][FixedU32::wrapping_shl]</code>.
2634    #[must_use = "this returns the result of the operation, without modifying the original"]
2635    fn wrapping_shl(self, rhs: u32) -> Self;
2636
2637    /// Wrapping shift right. Wraps `rhs` if `rhs`&nbsp;≥ the number of
2638    /// bits, then shifts and returns the number.
2639    ///
2640    /// See also <code>FixedI32::[wrapping\_shr][FixedI32::wrapping_shr]</code>
2641    /// and <code>FixedU32::[wrapping\_shr][FixedU32::wrapping_shr]</code>.
2642    #[must_use = "this returns the result of the operation, without modifying the original"]
2643    fn wrapping_shr(self, rhs: u32) -> Self;
2644
2645    /// Wrapping distance. Returns the distance from `self` to `other`, wrapping
2646    /// on overflow.
2647    ///
2648    /// See also
2649    /// <code>FixedI32::[wrapping\_dist][FixedI32::wrapping_dist]</code> and
2650    /// <code>FixedU32::[wrapping\_dist][FixedU32::wrapping_dist]</code>.
2651    #[must_use = "this returns the result of the operation, without modifying the original"]
2652    fn wrapping_dist(self, other: Self) -> Self;
2653
2654    /// Compute the hypotenuse of a right triange, wrapping on overflow.
2655    ///
2656    /// See also
2657    /// <code>FixedI32::[wrapping\_hypot][FixedI32::wrapping_hypot]</code> and
2658    /// <code>FixedU32::[wrapping\_hypot][FixedU32::wrapping_hypot]</code>.
2659    #[must_use = "this returns the result of the operation, without modifying the original"]
2660    fn wrapping_hypot(self, other: Self) -> Self;
2661
2662    /// Returns the square root, wrapping on overflow.
2663    ///
2664    /// See also
2665    /// <code>FixedI32::[wrapping\_sqrt][FixedI32::wrapping_sqrt]</code> and
2666    /// <code>FixedU32::[wrapping\_sqrt][FixedU32::wrapping_sqrt]</code>.
2667    ///
2668    /// # Panics
2669    ///
2670    /// Panics if the number is negative.
2671    fn wrapping_sqrt(self) -> Self;
2672
2673    /// Linear interpolation between `start` and `end`, wrapping on overflow.
2674    ///
2675    /// See also
2676    /// <code>FixedI32::[wrapping\_lerp][FixedI32::wrapping_lerp]</code> and
2677    /// <code>FixedU32::[wrapping\_lerp][FixedU32::wrapping_lerp]</code>.
2678    #[must_use]
2679    fn wrapping_lerp(self, start: Self, end: Self) -> Self;
2680
2681    /// Inverse linear interpolation between `start` and `end`, wrapping on
2682    /// overflow.
2683    ///
2684    /// See also
2685    /// <code>FixedI32::[wrapping\_inv\_lerp][FixedI32::wrapping_inv_lerp]</code>
2686    /// and
2687    /// <code>FixedU32::[wrapping\_inv\_lerp][FixedU32::wrapping_inv_lerp]</code>.
2688    #[must_use]
2689    fn wrapping_inv_lerp(self, start: Self, end: Self) -> Self;
2690
2691    /// Strict negation. Returns the negated value, panicking on overflow.
2692    ///
2693    /// See also <code>FixedI32::[strict\_neg][FixedI32::strict_neg]</code> and
2694    /// <code>FixedU32::[strict\_neg][FixedU32::strict_neg]</code>.
2695    ///
2696    /// # Panics
2697    ///
2698    /// Panics if the result does not fit.
2699    #[track_caller]
2700    #[must_use]
2701    fn strict_neg(self) -> Self;
2702
2703    /// Strict addition. Returns the sum, panicking on overflow.
2704    ///
2705    /// See also <code>FixedI32::[strict\_add][FixedI32::strict_add]</code> and
2706    /// <code>FixedU32::[strict\_add][FixedU32::strict_add]</code>.
2707    ///
2708    /// # Panics
2709    ///
2710    /// Panics if the result does not fit.
2711    #[track_caller]
2712    #[must_use = "this returns the result of the operation, without modifying the original"]
2713    fn strict_add(self, rhs: Self) -> Self;
2714
2715    /// Strict subtraction. Returns the difference, panicking on overflow.
2716    ///
2717    /// See also <code>FixedI32::[strict\_sub][FixedI32::strict_sub]</code> and
2718    /// <code>FixedU32::[strict\_sub][FixedU32::strict_sub]</code>.
2719    ///
2720    /// # Panics
2721    ///
2722    /// Panics if the result does not fit.
2723    #[track_caller]
2724    #[must_use = "this returns the result of the operation, without modifying the original"]
2725    fn strict_sub(self, rhs: Self) -> Self;
2726
2727    /// Strict multiplication. Returns the product, panicking on overflow.
2728    ///
2729    /// See also <code>FixedI32::[strict\_mul][FixedI32::strict_mul]</code> and
2730    /// <code>FixedU32::[strict\_mul][FixedU32::strict_mul]</code>.
2731    ///
2732    /// # Panics
2733    ///
2734    /// Panics if the result does not fit.
2735    #[track_caller]
2736    #[must_use = "this returns the result of the operation, without modifying the original"]
2737    fn strict_mul(self, rhs: Self) -> Self;
2738
2739    /// Strict division. Returns the quotient, panicking on overflow.
2740    ///
2741    /// See also <code>FixedI32::[strict\_div][FixedI32::strict_div]</code> and
2742    /// <code>FixedU32::[strict\_div][FixedU32::strict_div]</code>.
2743    ///
2744    /// # Panics
2745    ///
2746    /// Panics if the divisor is zero or if the result does not fit.
2747    #[track_caller]
2748    #[must_use = "this returns the result of the operation, without modifying the original"]
2749    fn strict_div(self, rhs: Self) -> Self;
2750
2751    /// Strict remainder. Returns the quotient, panicking if the divisor is zero.
2752    ///
2753    /// See also <code>FixedI32::[strict\_rem][FixedI32::strict_rem]</code> and
2754    /// <code>FixedU32::[strict\_rem][FixedU32::strict_rem]</code>.
2755    ///
2756    /// # Panics
2757    ///
2758    /// Panics if the divisor is zero.
2759    #[track_caller]
2760    #[must_use = "this returns the result of the operation, without modifying the original"]
2761    fn strict_rem(self, rhs: Self) -> Self;
2762
2763    /// Strict reciprocal. Returns reciprocal, panicking on overflow.
2764    ///
2765    /// See also <code>FixedI32::[strict\_recip][FixedI32::strict_recip]</code>
2766    /// and <code>FixedU32::[strict\_recip][FixedU32::strict_recip]</code>.
2767    ///
2768    /// # Panics
2769    ///
2770    /// Panics if `self` is zero or on overflow.
2771    #[track_caller]
2772    #[must_use]
2773    fn strict_recip(self) -> Self;
2774
2775    /// Strict next multiple of `other`. Returns the next multiple, panicking
2776    /// on overflow.
2777    ///
2778    /// See also
2779    /// <code>FixedI32::[strict\_next\_multiple\_of][FixedI32::strict_next_multiple_of]</code>
2780    /// and
2781    /// <code>FixedU32::[strict\_next\_multiple\_of][FixedU32::strict_next_multiple_of]</code>.
2782    ///
2783    /// # Panics
2784    ///
2785    /// Panics if `other` is zero or on overflow.
2786    #[track_caller]
2787    #[must_use]
2788    fn strict_next_multiple_of(self, other: Self) -> Self;
2789
2790    /// Strict multiply and add. Returns `self` × `mul` + `add`, panicking on overflow.
2791    ///
2792    /// See also
2793    /// <code>FixedI32::[strict\_mul\_add][FixedI32::strict_mul_add]</code> and
2794    /// <code>FixedU32::[strict\_mul\_add][FixedU32::strict_mul_add]</code>.
2795    ///
2796    /// # Panics
2797    ///
2798    /// Panics if the result does not fit.
2799    #[track_caller]
2800    #[must_use = "this returns the result of the operation, without modifying the original"]
2801    fn strict_mul_add(self, mul: Self, add: Self) -> Self;
2802
2803    /// Adds `self` to the product `a`&nbsp;×&nbsp;`b`, panicking on overflow.
2804    ///
2805    /// See also
2806    /// <code>FixedI32::[strict\_add\_prod][FixedI32::strict_add_prod]</code>
2807    /// and
2808    /// <code>FixedU32::[strict\_add\_prod][FixedU32::strict_add_prod]</code>.
2809    ///
2810    /// # Panics
2811    ///
2812    /// Panics if the result does not fit.
2813    #[track_caller]
2814    #[must_use]
2815    fn strict_add_prod(self, a: Self, b: Self) -> Self;
2816
2817    /// Strict multiply and accumulate. Adds (`a` × `b`) to `self`, panicking on overflow.
2818    ///
2819    /// See also
2820    /// <code>FixedI32::[strict\_mul\_acc][FixedI32::strict_mul_acc]</code> and
2821    /// <code>FixedU32::[strict\_mul\_acc][FixedU32::strict_mul_acc]</code>.
2822    ///
2823    /// # Panics
2824    ///
2825    /// Panics if the result does not fit.
2826    #[track_caller]
2827    fn strict_mul_acc(&mut self, a: Self, b: Self);
2828
2829    /// Strict Euclidean division. Returns the quotient, panicking on overflow.
2830    ///
2831    /// See also
2832    /// <code>FixedI32::[strict\_div\_euclid][FixedI32::strict_div_euclid]</code>
2833    /// and
2834    /// <code>FixedU32::[strict\_div\_euclid][FixedU32::strict_div_euclid]</code>.
2835    ///
2836    /// # Panics
2837    ///
2838    /// Panics if the divisor is zero or if the result does not fit.
2839    #[track_caller]
2840    #[must_use = "this returns the result of the operation, without modifying the original"]
2841    fn strict_div_euclid(self, rhs: Self) -> Self;
2842
2843    /// Strict remainder for Euclidean division. Returns the
2844    /// remainder, panicking if the divisor is zero.
2845    ///
2846    /// See also
2847    /// <code>FixedI32::[strict\_rem\_euclid][FixedI32::strict_rem_euclid]</code>
2848    /// and
2849    /// <code>FixedU32::[strict\_rem\_euclid][FixedU32::strict_rem_euclid]</code>.
2850    ///
2851    /// # Panics
2852    ///
2853    /// Panics if the divisor is zero.
2854    #[track_caller]
2855    #[must_use = "this returns the result of the operation, without modifying the original"]
2856    fn strict_rem_euclid(self, rhs: Self) -> Self;
2857
2858    /// Strict multiplication by an integer. Returns the product, panicking on overflow.
2859    ///
2860    /// See also
2861    /// <code>FixedI32::[strict\_mul\_int][FixedI32::strict_mul_int]</code> and
2862    /// <code>FixedU32::[strict\_mul\_int][FixedU32::strict_mul_int]</code>.
2863    ///
2864    /// # Panics
2865    ///
2866    /// Panics if the result does not fit.
2867    #[track_caller]
2868    #[must_use = "this returns the result of the operation, without modifying the original"]
2869    fn strict_mul_int(self, rhs: Self::Bits) -> Self;
2870
2871    /// Strict division by an integer. Returns the quotient, panicking on overflow.
2872    ///
2873    /// Overflow can only occur when dividing the minimum value by &minus;1.
2874    ///
2875    /// See also
2876    /// <code>FixedI32::[strict\_div\_int][FixedI32::strict_div_int]</code> and
2877    /// <code>FixedU32::[strict\_div\_int][FixedU32::strict_div_int]</code>.
2878    ///
2879    /// # Panics
2880    ///
2881    /// Panics if the divisor is zero or if the result does not fit.
2882    #[track_caller]
2883    #[must_use = "this returns the result of the operation, without modifying the original"]
2884    fn strict_div_int(self, rhs: Self::Bits) -> Self;
2885
2886    /// Strict remainder for division by an integer. Returns the
2887    /// remainder, panicking if the divisor is zero.
2888    ///
2889    /// See also
2890    /// <code>FixedI32::[strict\_rem\_int][FixedI32::strict_rem_int]</code> and
2891    /// <code>FixedU32::[strict\_rem\_int][FixedU32::strict_rem_int]</code>.
2892    ///
2893    /// # Panics
2894    ///
2895    /// Panics if the divisor is zero.
2896    #[track_caller]
2897    #[must_use = "this returns the result of the operation, without modifying the original"]
2898    fn strict_rem_int(self, rhs: Self::Bits) -> Self;
2899
2900    /// Strict Euclidean division by an integer. Returns the
2901    /// quotient, panicking on overflow.
2902    ///
2903    /// Overflow can only occur when dividing the minimum value by &minus;1.
2904    ///
2905    /// See also
2906    /// <code>FixedI32::[strict\_div\_euclid\_int][FixedI32::strict_div_euclid_int]</code>
2907    /// and
2908    /// <code>FixedU32::[strict\_div\_euclid\_int][FixedU32::strict_div_euclid_int]</code>.
2909    ///
2910    /// # Panics
2911    ///
2912    /// Panics if the divisor is zero or if the result does not fit.
2913    #[track_caller]
2914    #[must_use = "this returns the result of the operation, without modifying the original"]
2915    fn strict_div_euclid_int(self, rhs: Self::Bits) -> Self;
2916
2917    /// Strict remainder for Euclidean division by an integer.
2918    /// Returns the remainder, panicking on overflow.
2919    ///
2920    /// See also
2921    /// <code>FixedI32::[strict\_rem\_euclid\_int][FixedI32::strict_rem_euclid_int]</code>
2922    /// and
2923    /// <code>FixedU32::[strict\_rem\_euclid\_int][FixedU32::strict_rem_euclid_int]</code>.
2924    ///
2925    /// # Panics
2926    ///
2927    /// Panics if the divisor is zero or if the result does not fit.
2928    #[track_caller]
2929    #[must_use = "this returns the result of the operation, without modifying the original"]
2930    fn strict_rem_euclid_int(self, rhs: Self::Bits) -> Self;
2931
2932    /// Strict shift left. Panics if `rhs`&nbsp;≥ the number of bits.
2933    ///
2934    /// See also <code>FixedI32::[strict\_shl][FixedI32::strict_shl]</code> and
2935    /// <code>FixedU32::[strict\_shl][FixedU32::strict_shl]</code>.
2936    ///
2937    /// # Panics
2938    ///
2939    /// Panics if `rhs`&nbsp;≥ the number of bits.
2940    #[track_caller]
2941    #[must_use = "this returns the result of the operation, without modifying the original"]
2942    fn strict_shl(self, rhs: u32) -> Self;
2943
2944    /// Strict shift right. Panics if `rhs`&nbsp;≥ the number of bits.
2945    ///
2946    /// See also <code>FixedI32::[strict\_shr][FixedI32::strict_shr]</code> and
2947    /// <code>FixedU32::[strict\_shr][FixedU32::strict_shr]</code>.
2948    ///
2949    /// # Panics
2950    ///
2951    /// Panics if `rhs`&nbsp;≥ the number of bits.
2952    #[track_caller]
2953    #[must_use = "this returns the result of the operation, without modifying the original"]
2954    fn strict_shr(self, rhs: u32) -> Self;
2955
2956    /// Strict distance. Returns the distance from `self` to `other`,
2957    /// panicking on overflow.
2958    ///
2959    /// # Panics
2960    ///
2961    /// Panics if the result does not fit.
2962    ///
2963    /// See also <code>FixedI32::[strict\_dist][FixedI32::strict_dist]</code>
2964    /// and <code>FixedU32::[strict\_dist][FixedU32::strict_dist]</code>.
2965    #[track_caller]
2966    #[must_use = "this returns the result of the operation, without modifying the original"]
2967    fn strict_dist(self, other: Self) -> Self;
2968
2969    /// Compute the hypotenuse of a right triange, panicking on overflow.
2970    ///
2971    /// # Panics
2972    ///
2973    /// Panics if the result does not fit.
2974    ///
2975    /// See also <code>FixedI32::[strict\_hypot][FixedI32::strict_hypot]</code>
2976    /// and <code>FixedU32::[strict\_hypot][FixedU32::strict_hypot]</code>.
2977    #[track_caller]
2978    #[must_use = "this returns the result of the operation, without modifying the original"]
2979    fn strict_hypot(self, other: Self) -> Self;
2980
2981    /// Returns the square root, panicking if the number is negative or on overflow.
2982    ///
2983    /// See also <code>FixedI32::[strict\_sqrt][FixedI32::strict_sqrt]</code>
2984    /// and <code>FixedU32::[strict\_sqrt][FixedU32::strict_sqrt]</code>.
2985    ///
2986    /// # Panics
2987    ///
2988    /// Panics if the number is negative or on overflow.
2989    fn strict_sqrt(self) -> Self;
2990
2991    /// Linear interpolation between `start` and `end`, panicking on overflow.
2992    ///
2993    /// # Panics
2994    ///
2995    /// Panics if the result does not fit.
2996    ///
2997    /// See also <code>FixedI32::[strict\_lerp][FixedI32::strict_lerp]</code>
2998    /// and <code>FixedU32::[strict\_lerp][FixedU32::strict_lerp]</code>.
2999    #[track_caller]
3000    #[must_use]
3001    fn strict_lerp(self, start: Self, end: Self) -> Self;
3002
3003    /// Inverse linear interpolation between `start` and `end`, panicking on overflow.
3004    ///
3005    /// # Panics
3006    ///
3007    /// Panics when `start`&nbsp;=&nbsp;`end` or when the results overflows.
3008    ///
3009    /// See also
3010    /// <code>FixedI32::[strict\_inv\_lerp][FixedI32::strict_inv_lerp]</code>
3011    /// and
3012    /// <code>FixedU32::[strict\_inv\_lerp][FixedU32::strict_inv_lerp]</code>.
3013    #[track_caller]
3014    #[must_use]
3015    fn strict_inv_lerp(self, start: Self, end: Self) -> Self;
3016
3017    /// Overflowing negation.
3018    ///
3019    /// Returns a [tuple] of the negated value and a [`bool`],
3020    /// indicating whether an overflow has occurred. On overflow, the
3021    /// wrapped value is returned.
3022    ///
3023    /// See also
3024    /// <code>FixedI32::[overflowing\_neg][FixedI32::overflowing_neg]</code> and
3025    /// <code>FixedU32::[overflowing\_neg][FixedU32::overflowing_neg]</code>.
3026    fn overflowing_neg(self) -> (Self, bool);
3027
3028    /// Overflowing addition.
3029    ///
3030    /// Returns a [tuple] of the sum and a [`bool`], indicating whether
3031    /// an overflow has occurred. On overflow, the wrapped value is
3032    /// returned.
3033    ///
3034    /// See also
3035    /// <code>FixedI32::[overflowing\_add][FixedI32::overflowing_add]</code> and
3036    /// <code>FixedU32::[overflowing\_add][FixedU32::overflowing_add]</code>.
3037    #[must_use = "this returns the result of the operation, without modifying the original"]
3038    fn overflowing_add(self, rhs: Self) -> (Self, bool);
3039
3040    /// Overflowing subtraction.
3041    ///
3042    /// Returns a [tuple] of the difference and a [`bool`], indicating
3043    /// whether an overflow has occurred. On overflow, the wrapped
3044    /// value is returned.
3045    ///
3046    /// See also
3047    /// <code>FixedI32::[overflowing\_sub][FixedI32::overflowing_sub]</code> and
3048    /// <code>FixedU32::[overflowing\_sub][FixedU32::overflowing_sub]</code>.
3049    #[must_use = "this returns the result of the operation, without modifying the original"]
3050    fn overflowing_sub(self, rhs: Self) -> (Self, bool);
3051
3052    /// Overflowing multiplication.
3053    ///
3054    /// Returns a [tuple] of the product and a [`bool`], indicating
3055    /// whether an overflow has occurred. On overflow, the wrapped
3056    /// value is returned.
3057    ///
3058    /// See also
3059    /// <code>FixedI32::[overflowing\_mul][FixedI32::overflowing_mul]</code> and
3060    /// <code>FixedU32::[overflowing\_mul][FixedU32::overflowing_mul]</code>.
3061    #[must_use = "this returns the result of the operation, without modifying the original"]
3062    fn overflowing_mul(self, rhs: Self) -> (Self, bool);
3063
3064    /// Overflowing division.
3065    ///
3066    /// Returns a [tuple] of the quotient and a [`bool`], indicating
3067    /// whether an overflow has occurred. On overflow, the wrapped
3068    /// value is returned.
3069    ///
3070    /// See also
3071    /// <code>FixedI32::[overflowing\_div][FixedI32::overflowing_div]</code> and
3072    /// <code>FixedU32::[overflowing\_div][FixedU32::overflowing_div]</code>.
3073    ///
3074    /// # Panics
3075    ///
3076    /// Panics if the divisor is zero.
3077    #[must_use = "this returns the result of the operation, without modifying the original"]
3078    fn overflowing_div(self, rhs: Self) -> (Self, bool);
3079
3080    /// Overflowing reciprocal.
3081    ///
3082    /// Returns a [tuple] of the reciprocal of `self` and a [`bool`],
3083    /// indicating whether an overflow has occurred. On overflow, the
3084    /// wrapped value is returned.
3085    ///
3086    /// See also
3087    /// <code>FixedI32::[overflowing\_recip][FixedI32::overflowing_recip]</code>
3088    /// and
3089    /// <code>FixedU32::[overflowing\_recip][FixedU32::overflowing_recip]</code>.
3090    ///
3091    /// # Panics
3092    ///
3093    /// Panics if `self` is zero.
3094    fn overflowing_recip(self) -> (Self, bool);
3095
3096    /// Overflowing next multiple of `other`.
3097    ///
3098    /// Returns a [tuple] of the next multiple and a [`bool`], indicating
3099    /// whether an overflow has occurred. On overflow, the wrapped value is
3100    /// returned.
3101    ///
3102    /// See also
3103    /// <code>FixedI32::[overflowing\_next\_multiple\_of][FixedI32::overflowing_next_multiple_of]</code>
3104    /// and
3105    /// <code>FixedU32::[overflowing\_next\_multiple\_of][FixedU32::overflowing_next_multiple_of]</code>.
3106    ///
3107    /// # Panics
3108    ///
3109    /// Panics if `other` is zero.
3110    fn overflowing_next_multiple_of(self, other: Self) -> (Self, bool);
3111
3112    /// Overflowing multiply  and add.
3113    ///
3114    /// Returns a [tuple] of `self` × `mul` + `add` and a [`bool`],
3115    /// indicating whether an overflow has occurred. On overflow, the
3116    /// wrapped value is returned.
3117    ///
3118    /// See also
3119    /// <code>FixedI32::[overflowing\_mul\_add][FixedI32::overflowing_mul_add]</code>
3120    /// and
3121    /// <code>FixedU32::[overflowing\_mul\_add][FixedU32::overflowing_mul_add]</code>.
3122    #[must_use = "this returns the result of the operation, without modifying the original"]
3123    fn overflowing_mul_add(self, mul: Self, add: Self) -> (Self, bool);
3124
3125    /// Adds `self` to the product `a`&nbsp;×&nbsp;`b`.
3126    ///
3127    /// Returns a [tuple] of the result and a [`bool`] indicating whether an
3128    /// overflow has occurred. On overflow, the wrapped value is returned.
3129    ///
3130    /// See also
3131    /// <code>FixedI32::[overflowing\_add\_prod][FixedI32::overflowing_add_prod]</code>
3132    /// and
3133    /// <code>FixedU32::[overflowing\_add\_prod][FixedU32::overflowing_add_prod]</code>.
3134    #[must_use = "this returns the result of the operation, without modifying the original"]
3135    fn overflowing_add_prod(self, a: Self, b: Self) -> (Self, bool);
3136
3137    /// Overflowing multiply and accumulate. Adds (`a` × `b`) to `self`,
3138    /// wrapping and returning [`true`] if overflow occurs.
3139    ///
3140    /// See also
3141    /// <code>FixedI32::[overflowing\_mul\_acc][FixedI32::overflowing_mul_acc]</code>
3142    /// and
3143    /// <code>FixedU32::[overflowing\_mul\_acc][FixedU32::overflowing_mul_acc]</code>.
3144    #[must_use = "this returns whether overflow occurs; use `wrapping_mul_acc` if the flag is not needed"]
3145    fn overflowing_mul_acc(&mut self, a: Self, b: Self) -> bool;
3146
3147    /// Overflowing Euclidean division.
3148    ///
3149    /// Returns a [tuple] of the quotient and a [`bool`], indicating
3150    /// whether an overflow has occurred. On overflow, the wrapped
3151    /// value is returned.
3152    ///
3153    /// See also
3154    /// <code>FixedI32::[overflowing\_div\_euclid][FixedI32::overflowing_div_euclid]</code>
3155    /// and
3156    /// <code>FixedU32::[overflowing\_div\_euclid][FixedU32::overflowing_div_euclid]</code>.
3157    ///
3158    /// # Panics
3159    ///
3160    /// Panics if the divisor is zero.
3161    #[must_use = "this returns the result of the operation, without modifying the original"]
3162    fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool);
3163
3164    /// Overflowing multiplication by an integer.
3165    ///
3166    /// Returns a [tuple] of the product and a [`bool`], indicating
3167    /// whether an overflow has occurred. On overflow, the wrapped
3168    /// value is returned.
3169    ///
3170    /// See also
3171    /// <code>FixedI32::[overflowing\_mul\_int][FixedI32::overflowing_mul_int]</code>
3172    /// and
3173    /// <code>FixedU32::[overflowing\_mul\_int][FixedU32::overflowing_mul_int]</code>.
3174    #[must_use = "this returns the result of the operation, without modifying the original"]
3175    fn overflowing_mul_int(self, rhs: Self::Bits) -> (Self, bool);
3176
3177    /// Overflowing division by an integer.
3178    ///
3179    /// Returns a [tuple] of the quotient and a [`bool`], indicating
3180    /// whether an overflow has occurred. On overflow, the wrapped
3181    /// value is returned.
3182    ///
3183    /// See also
3184    /// <code>FixedI32::[overflowing\_div\_int][FixedI32::overflowing_div_int]</code>
3185    /// and
3186    /// <code>FixedU32::[overflowing\_div\_int][FixedU32::overflowing_div_int]</code>.
3187    ///
3188    /// # Panics
3189    ///
3190    /// Panics if the divisor is zero.
3191    #[must_use = "this returns the result of the operation, without modifying the original"]
3192    fn overflowing_div_int(self, rhs: Self::Bits) -> (Self, bool);
3193
3194    /// Overflowing Euclidean division by an integer.
3195    ///
3196    /// Returns a [tuple] of the quotient and a [`bool`], indicating
3197    /// whether an overflow has occurred. On overflow, the wrapped
3198    /// value is returned.
3199    ///
3200    /// See also
3201    /// <code>FixedI32::[overflowing\_div\_euclid\_int][FixedI32::overflowing_div_euclid_int]</code>
3202    /// and
3203    /// <code>FixedU32::[overflowing\_div\_euclid\_int][FixedU32::overflowing_div_euclid_int]</code>.
3204    ///
3205    /// # Panics
3206    ///
3207    /// Panics if the divisor is zero.
3208    #[must_use = "this returns the result of the operation, without modifying the original"]
3209    fn overflowing_div_euclid_int(self, rhs: Self::Bits) -> (Self, bool);
3210
3211    /// Overflowing remainder for Euclidean division by an integer.
3212    ///
3213    /// Returns a [tuple] of the remainder and a [`bool`], indicating
3214    /// whether an overflow has occurred. On overflow, the wrapped
3215    /// value is returned.
3216    ///
3217    /// See also
3218    /// <code>FixedI32::[overflowing\_rem\_euclid\_int][FixedI32::overflowing_rem_euclid_int]</code>
3219    /// and
3220    /// <code>FixedU32::[overflowing\_rem\_euclid\_int][FixedU32::overflowing_rem_euclid_int]</code>.
3221    ///
3222    /// # Panics
3223    ///
3224    /// Panics if the divisor is zero.
3225    #[must_use = "this returns the result of the operation, without modifying the original"]
3226    fn overflowing_rem_euclid_int(self, rhs: Self::Bits) -> (Self, bool);
3227
3228    /// Overflowing shift left.
3229    ///
3230    /// Returns a [tuple] of the shifted value and a [`bool`],
3231    /// indicating whether an overflow has occurred. On overflow, the
3232    /// wrapped value is returned.
3233    ///
3234    /// See also
3235    /// <code>FixedI32::[overflowing\_shl][FixedI32::overflowing_shl]</code> and
3236    /// <code>FixedU32::[overflowing\_shl][FixedU32::overflowing_shl]</code>.
3237    #[must_use = "this returns the result of the operation, without modifying the original"]
3238    fn overflowing_shl(self, rhs: u32) -> (Self, bool);
3239
3240    /// Overflowing shift right.
3241    ///
3242    /// Returns a [tuple] of the shifted value and a [`bool`],
3243    /// indicating whether an overflow has occurred. On overflow, the
3244    /// wrapped value is returned.
3245    ///
3246    /// See also
3247    /// <code>FixedI32::[overflowing\_shr][FixedI32::overflowing_shr]</code> and
3248    /// <code>FixedU32::[overflowing\_shr][FixedU32::overflowing_shr]</code>.
3249    #[must_use = "this returns the result of the operation, without modifying the original"]
3250    fn overflowing_shr(self, rhs: u32) -> (Self, bool);
3251
3252    /// Overflowing distance.
3253    ///
3254    /// Returns a [tuple] of the distance from `self` to `other` and a [`bool`],
3255    /// indicating whether an overflow has occurred. On overflow, the wrapped
3256    /// value is returned.
3257    ///
3258    /// See also
3259    /// <code>FixedI32::[overflowing\_dist][FixedI32::overflowing_dist]</code>
3260    /// and
3261    /// <code>FixedU32::[overflowing\_dist][FixedU32::overflowing_dist]</code>.
3262    #[must_use = "this returns the result of the operation, without modifying the original"]
3263    fn overflowing_dist(self, other: Self) -> (Self, bool);
3264
3265    /// Compute the hypotenuse of a right triange.
3266    ///
3267    /// Returns a [tuple] of the hypotenuse and a [`bool`], indicating whether
3268    /// an overflow has occurred. On overflow, the wrapped value is returned.
3269    ///
3270    /// See also
3271    /// <code>FixedI32::[overflowing\_hypot][FixedI32::overflowing_hypot]</code>
3272    /// and
3273    /// <code>FixedU32::[overflowing\_hypot][FixedU32::overflowing_hypot]</code>.
3274    #[must_use = "this returns the result of the operation, without modifying the original"]
3275    fn overflowing_hypot(self, other: Self) -> (Self, bool);
3276
3277    /// Compute the square root.
3278    ///
3279    /// Returns a [tuple] of the square root and a [`bool`], indicating whether
3280    /// an overflow has occurred. On overflow, the wrapped value is returned.
3281    ///
3282    /// See also
3283    /// <code>FixedI32::[overflowing\_sqrt][FixedI32::overflowing_sqrt]</code>
3284    /// and
3285    /// <code>FixedU32::[overflowing\_sqrt][FixedU32::overflowing_sqrt]</code>.
3286    ///
3287    /// # Panics
3288    ///
3289    /// Panics if the number is negative.
3290    fn overflowing_sqrt(self) -> (Self, bool);
3291
3292    /// Overflowing linear interpolation between `start` and `end`.
3293    ///
3294    /// Returns a [tuple] of the interpolated value and a [`bool`], indicating
3295    /// whether an overflow has occurred. On overflow, the wrapped value is
3296    /// returned.
3297    ///
3298    /// See also
3299    /// <code>FixedI32::[overflowing\_lerp][FixedI32::overflowing_lerp]</code>
3300    /// and
3301    /// <code>FixedU32::[overflowing\_lerp][FixedU32::overflowing_lerp]</code>.
3302    fn overflowing_lerp(self, start: Self, end: Self) -> (Self, bool);
3303
3304    /// Overflowing inverse linear interpolation between `start` and `end`.
3305    ///
3306    /// Returns a [tuple] of the computed value and a [`bool`], indicating
3307    /// whether an overflow has occurred. On overflow, the wrapped value is
3308    /// returned.
3309    ///
3310    /// See also
3311    /// <code>FixedI32::[overflowing\_inv\_lerp][FixedI32::overflowing_inv_lerp]</code>
3312    /// and
3313    /// <code>FixedU32::[overflowing\_inv\_lerp][FixedU32::overflowing_inv_lerp]</code>.
3314    fn overflowing_inv_lerp(self, start: Self, end: Self) -> (Self, bool);
3315
3316    /// Unchecked addition. Computes `self`&nbsp;+&nbsp;`rhs`, assuming
3317    /// overflow cannot occur.
3318    ///
3319    /// See also
3320    /// <code>FixedI32::[unchecked\_add][FixedI32::unchecked_add]</code> and
3321    /// <code>FixedU32::[unchecked\_add][FixedU32::unchecked_add]</code>.
3322    ///
3323    /// # Safety
3324    ///
3325    /// This results in undefined behavior when
3326    /// `self`&nbsp;+&nbsp;`rhs`&nbsp;\>&nbsp;[`MAX`][Self::MAX] or
3327    /// `self`&nbsp;+&nbsp;`rhs`&nbsp;\<&nbsp;[`MIN`][Self::MIN].
3328    unsafe fn unchecked_add(self, rhs: Self) -> Self;
3329
3330    /// Unchecked subtraction. Computes `self`&nbsp;&minus;&nbsp;`rhs`, assuming
3331    /// overflow cannot occur.
3332    ///
3333    /// See also
3334    /// <code>FixedI32::[unchecked\_sub][FixedI32::unchecked_sub]</code> and
3335    /// <code>FixedU32::[unchecked\_sub][FixedU32::unchecked_sub]</code>.
3336    ///
3337    /// # Safety
3338    ///
3339    /// This results in undefined behavior when
3340    /// `self`&nbsp;&minus;&nbsp;`rhs`&nbsp;\>&nbsp;[`MAX`][Self::MAX] or
3341    /// `self`&nbsp;&minus;&nbsp;`rhs`&nbsp;\<&nbsp;[`MIN`][Self::MIN].
3342    unsafe fn unchecked_sub(self, rhs: Self) -> Self;
3343
3344    /// Unchecked multiplication by an integer. Computes
3345    /// `self`&nbsp;×&nbsp;`rhs`, assuming overflow cannot occur.
3346    ///
3347    /// See also
3348    /// <code>FixedI32::[unchecked\_mul\_int][FixedI32::unchecked_mul_int]</code>
3349    /// and
3350    /// <code>FixedU32::[unchecked\_mul\_int][FixedU32::unchecked_mul_int]</code>.
3351    ///
3352    /// # Safety
3353    ///
3354    /// This results in undefined behavior when
3355    /// `self`&nbsp;×&nbsp;`rhs`&nbsp;\>&nbsp;[`MAX`][Self::MAX] or
3356    /// `self`&nbsp;×&nbsp;`rhs`&nbsp;\<&nbsp;[`MIN`][Self::MIN].
3357    unsafe fn unchecked_mul_int(self, rhs: Self::Bits) -> Self;
3358
3359    /// Rounds to the nearest integer, with ties rounded to even.
3360    #[must_use]
3361    #[deprecated(since = "1.28.0", note = "renamed to `round_ties_even`")]
3362    fn round_ties_to_even(self) -> Self {
3363        self.round_ties_even()
3364    }
3365
3366    /// Checked round. Rounds to the nearest integer, with ties rounded to even,
3367    /// returning [`None`] on overflow.
3368    #[deprecated(since = "1.28.0", note = "renamed to `checked_round_ties_even`")]
3369    fn checked_round_ties_to_even(self) -> Option<Self> {
3370        self.checked_round_ties_even()
3371    }
3372
3373    /// Saturating round. Rounds to the nearest integer, with ties rounded
3374    /// to_even, and saturating on overflow.
3375    #[must_use]
3376    #[deprecated(since = "1.28.0", note = "renamed to `saturating_round_ties_even`")]
3377    fn saturating_round_ties_to_even(self) -> Self {
3378        self.saturating_round_ties_even()
3379    }
3380
3381    /// Wrapping round. Rounds to the next integer to the nearest, with ties
3382    /// rounded to even, and wrapping on overflow.
3383    #[must_use]
3384    #[deprecated(since = "1.28.0", note = "renamed to `wrapping_round_ties_even`")]
3385    fn wrapping_round_ties_to_even(self) -> Self {
3386        self.wrapping_round_ties_even()
3387    }
3388
3389    /// Strict round. Rounds to the next integer to the nearest, with ties
3390    /// rounded to even, and panicking on overflow.
3391    ///
3392    /// # Panics
3393    ///
3394    /// Panics if the result does not fit.
3395    #[track_caller]
3396    #[must_use]
3397    #[deprecated(since = "1.28.0", note = "renamed to `unwrapped_round_ties_even`")]
3398    fn unwrapped_round_ties_to_even(self) -> Self {
3399        self.strict_round_ties_even()
3400    }
3401
3402    /// Overflowing round. Rounds to the next integer to the nearest, with ties
3403    /// rounded to even.
3404    ///
3405    /// Returns a [tuple] of the fixed-point number and a [`bool`], indicating
3406    /// whether an overflow has occurred. On overflow, the wrapped value is
3407    /// returned.
3408    #[deprecated(since = "1.28.0", note = "renamed to `overflowing_round_ties_even`")]
3409    fn overflowing_round_ties_to_even(self) -> (Self, bool) {
3410        self.overflowing_round_ties_even()
3411    }
3412
3413    /// Creates a fixed-point number from another number, panicking on overflow.
3414    ///
3415    /// # Panics
3416    ///
3417    /// Panics if the value does not fit.
3418    #[deprecated(since = "1.30.0", note = "renamed to `strict_from_num`")]
3419    #[track_caller]
3420    fn unwrapped_from_num<Src: ToFixed>(src: Src) -> Self {
3421        Self::strict_from_num(src)
3422    }
3423
3424    /// Converts a fixed-point number to another number, panicking on overflow.
3425    ///
3426    /// # Panics
3427    ///
3428    /// Panics if the value does not fit.
3429    #[deprecated(since = "1.30.0", note = "renamed to `strict_to_num`")]
3430    #[track_caller]
3431    fn unwrapped_to_num<Dst: FromFixed>(self) -> Dst {
3432        self.strict_to_num()
3433    }
3434
3435    /// Parses a string slice containing decimal digits to return a
3436    /// fixed-point number, panicking on overflow.
3437    ///
3438    /// # Panics
3439    ///
3440    /// Panics if the value does not fit or if there is a parsing error.
3441    #[deprecated(since = "1.30.0", note = "renamed to `strict_from_str`")]
3442    #[track_caller]
3443    fn unwrapped_from_str(src: &str) -> Self {
3444        Self::strict_from_str(src)
3445    }
3446
3447    /// Parses a string slice containing binary digits to return a
3448    /// fixed-point number, panicking on overflow.
3449    ///
3450    /// # Panics
3451    ///
3452    /// Panics if the value does not fit or if there is a parsing error.
3453    #[deprecated(since = "1.30.0", note = "renamed to `strict_from_str_binary`")]
3454    #[track_caller]
3455    fn unwrapped_from_str_binary(src: &str) -> Self {
3456        Self::strict_from_str_binary(src)
3457    }
3458
3459    /// Parses a string slice containing octal digits to return a
3460    /// fixed-point number, panicking on overflow.
3461    ///
3462    /// # Panics
3463    ///
3464    /// Panics if the value does not fit or if there is a parsing error.
3465    #[deprecated(since = "1.30.0", note = "renamed to `strict_from_str_octal`")]
3466    #[track_caller]
3467    fn unwrapped_from_str_octal(src: &str) -> Self {
3468        Self::strict_from_str_octal(src)
3469    }
3470
3471    /// Parses a string slice containing hexadecimal digits to return a
3472    /// fixed-point number, panicking on overflow.
3473    ///
3474    /// # Panics
3475    ///
3476    /// Panics if the value does not fit or if there is a parsing error.
3477    #[deprecated(since = "1.30.0", note = "renamed to `strict_from_str_hex`")]
3478    #[track_caller]
3479    fn unwrapped_from_str_hex(src: &str) -> Self {
3480        Self::strict_from_str_hex(src)
3481    }
3482
3483    /// Parses an ASCII-byte slice containing decimal digits to return a
3484    /// fixed-point number, panicking on overflow.
3485    ///
3486    /// # Panics
3487    ///
3488    /// Panics if the value does not fit or if there is a parsing error.
3489    #[deprecated(since = "1.30.0", note = "renamed to `strict_from_ascii`")]
3490    #[track_caller]
3491    fn unwrapped_from_ascii(src: &[u8]) -> Self {
3492        Self::strict_from_ascii(src)
3493    }
3494
3495    /// Parses an ASCII-byte slice containing binary digits to return a
3496    /// fixed-point number, panicking on overflow.
3497    ///
3498    /// # Panics
3499    ///
3500    /// Panics if the value does not fit or if there is a parsing error.
3501    #[deprecated(since = "1.30.0", note = "renamed to `strict_from_ascii_binary`")]
3502    #[track_caller]
3503    fn unwrapped_from_ascii_binary(src: &[u8]) -> Self {
3504        Self::strict_from_ascii_binary(src)
3505    }
3506
3507    /// Parses an ASCII-byte slice containing octal digits to return a
3508    /// fixed-point number, panicking on overflow.
3509    ///
3510    /// # Panics
3511    ///
3512    /// Panics if the value does not fit or if there is a parsing error.
3513    #[deprecated(since = "1.30.0", note = "renamed to `strict_from_ascii_octal`")]
3514    #[track_caller]
3515    fn unwrapped_from_ascii_octal(src: &[u8]) -> Self {
3516        Self::strict_from_ascii_octal(src)
3517    }
3518
3519    /// Parses an ASCII-byte slice containing hexadecimal digits to return a
3520    /// fixed-point number, panicking on overflow.
3521    ///
3522    /// # Panics
3523    ///
3524    /// Panics if the value does not fit or if there is a parsing error.
3525    #[deprecated(since = "1.30.0", note = "renamed to `strict_from_ascii_hex`")]
3526    #[track_caller]
3527    fn unwrapped_from_ascii_hex(src: &[u8]) -> Self {
3528        Self::strict_from_ascii_hex(src)
3529    }
3530
3531    /// Strict ceil. Rounds to the next integer towards +∞,
3532    /// panicking on overflow.
3533    ///
3534    /// # Panics
3535    ///
3536    /// Panics if the result does not fit.
3537    #[deprecated(since = "1.30.0", note = "renamed to `strict_ceil`")]
3538    #[track_caller]
3539    #[must_use]
3540    fn unwrapped_ceil(self) -> Self {
3541        self.strict_ceil()
3542    }
3543
3544    /// Strict floor. Rounds to the next integer towards &minus;∞,
3545    /// panicking on overflow.
3546    ///
3547    /// # Panics
3548    ///
3549    /// Panics if the result does not fit.
3550    #[deprecated(since = "1.30.0", note = "renamed to `strict_floor`")]
3551    #[track_caller]
3552    #[must_use]
3553    fn unwrapped_floor(self) -> Self {
3554        self.strict_floor()
3555    }
3556
3557    /// Strict round. Rounds to the next integer to the nearest,
3558    /// with ties rounded away from zero, and panicking on overflow.
3559    ///
3560    /// # Panics
3561    ///
3562    /// Panics if the result does not fit.
3563    #[deprecated(since = "1.30.0", note = "renamed to `strict_round`")]
3564    #[track_caller]
3565    #[must_use]
3566    fn unwrapped_round(self) -> Self {
3567        self.strict_round()
3568    }
3569
3570    /// Strict round. Rounds to the next integer to the nearest, with ties
3571    /// rounded to even, and panicking on overflow.
3572    ///
3573    /// # Panics
3574    ///
3575    /// Panics if the result does not fit.
3576    #[deprecated(since = "1.30.0", note = "renamed to `strict_round_ties_even`")]
3577    #[track_caller]
3578    #[must_use]
3579    fn unwrapped_round_ties_even(self) -> Self {
3580        self.strict_round_ties_even()
3581    }
3582
3583    /// Strict negation. Returns the negated value, panicking on overflow.
3584    ///
3585    /// # Panics
3586    ///
3587    /// Panics if the result does not fit.
3588    #[deprecated(since = "1.30.0", note = "renamed to `strict_neg`")]
3589    #[track_caller]
3590    #[must_use]
3591    fn unwrapped_neg(self) -> Self {
3592        self.strict_neg()
3593    }
3594
3595    /// Strict addition. Returns the sum, panicking on overflow.
3596    ///
3597    /// # Panics
3598    ///
3599    /// Panics if the result does not fit.
3600    #[deprecated(since = "1.30.0", note = "renamed to `strict_add`")]
3601    #[track_caller]
3602    #[must_use = "this returns the result of the operation, without modifying the original"]
3603    fn unwrapped_add(self, rhs: Self) -> Self {
3604        self.strict_add(rhs)
3605    }
3606
3607    /// Strict subtraction. Returns the difference, panicking on overflow.
3608    ///
3609    /// # Panics
3610    ///
3611    /// Panics if the result does not fit.
3612    #[deprecated(since = "1.30.0", note = "renamed to `strict_sub`")]
3613    #[track_caller]
3614    #[must_use = "this returns the result of the operation, without modifying the original"]
3615    fn unwrapped_sub(self, rhs: Self) -> Self {
3616        self.strict_sub(rhs)
3617    }
3618
3619    /// Strict multiplication. Returns the product, panicking on overflow.
3620    ///
3621    /// # Panics
3622    ///
3623    /// Panics if the result does not fit.
3624    #[deprecated(since = "1.30.0", note = "renamed to `strict_mul`")]
3625    #[track_caller]
3626    #[must_use = "this returns the result of the operation, without modifying the original"]
3627    fn unwrapped_mul(self, rhs: Self) -> Self {
3628        self.strict_mul(rhs)
3629    }
3630
3631    /// Strict division. Returns the quotient, panicking on overflow.
3632    ///
3633    /// # Panics
3634    ///
3635    /// Panics if the divisor is zero or if the result does not fit.
3636    #[deprecated(since = "1.30.0", note = "renamed to `strict_div`")]
3637    #[track_caller]
3638    #[must_use = "this returns the result of the operation, without modifying the original"]
3639    fn unwrapped_div(self, rhs: Self) -> Self {
3640        self.strict_div(rhs)
3641    }
3642
3643    /// Strict remainder. Returns the quotient, panicking if the divisor is zero.
3644    ///
3645    /// # Panics
3646    ///
3647    /// Panics if the divisor is zero.
3648    #[deprecated(since = "1.30.0", note = "renamed to `strict_rem`")]
3649    #[track_caller]
3650    #[must_use = "this returns the result of the operation, without modifying the original"]
3651    fn unwrapped_rem(self, rhs: Self) -> Self {
3652        self.strict_rem(rhs)
3653    }
3654
3655    /// Strict reciprocal. Returns reciprocal, panicking on overflow.
3656    ///
3657    /// # Panics
3658    ///
3659    /// Panics if `self` is zero or on overflow.
3660    #[deprecated(since = "1.30.0", note = "renamed to `strict_recip`")]
3661    #[track_caller]
3662    #[must_use]
3663    fn unwrapped_recip(self) -> Self {
3664        self.strict_recip()
3665    }
3666
3667    /// Strict next multiple of `other`. Returns the next multiple, panicking
3668    /// on overflow.
3669    ///
3670    /// # Panics
3671    ///
3672    /// Panics if `other` is zero or on overflow.
3673    #[deprecated(since = "1.30.0", note = "renamed to `strict_next_multiple_of`")]
3674    #[track_caller]
3675    #[must_use]
3676    fn unwrapped_next_multiple_of(self, other: Self) -> Self {
3677        self.strict_next_multiple_of(other)
3678    }
3679
3680    /// Strict multiply and add. Returns `self` × `mul` + `add`, panicking on overflow.
3681    ///
3682    /// # Panics
3683    ///
3684    /// Panics if the result does not fit.
3685    #[deprecated(since = "1.30.0", note = "renamed to `strict_mul_add`")]
3686    #[track_caller]
3687    #[must_use = "this returns the result of the operation, without modifying the original"]
3688    fn unwrapped_mul_add(self, mul: Self, add: Self) -> Self {
3689        self.strict_mul_add(mul, add)
3690    }
3691
3692    /// Adds `self` to the product `a`&nbsp;×&nbsp;`b`, panicking on overflow.
3693    ///
3694    /// # Panics
3695    ///
3696    /// Panics if the result does not fit.
3697    #[deprecated(since = "1.30.0", note = "renamed to `strict_add_prod`")]
3698    #[track_caller]
3699    #[must_use]
3700    fn unwrapped_add_prod(self, a: Self, b: Self) -> Self {
3701        self.strict_add_prod(a, b)
3702    }
3703
3704    /// Strict multiply and accumulate. Adds (`a` × `b`) to `self`, panicking on overflow.
3705    ///
3706    /// # Panics
3707    ///
3708    /// Panics if the result does not fit.
3709    #[deprecated(since = "1.30.0", note = "renamed to `strict_mul_acc`")]
3710    #[track_caller]
3711    fn unwrapped_mul_acc(&mut self, a: Self, b: Self) {
3712        self.strict_mul_acc(a, b)
3713    }
3714
3715    /// Strict Euclidean division. Returns the quotient, panicking on overflow.
3716    ///
3717    /// # Panics
3718    ///
3719    /// Panics if the divisor is zero or if the result does not fit.
3720    #[deprecated(since = "1.30.0", note = "renamed to `strict_div_euclid`")]
3721    #[track_caller]
3722    #[must_use = "this returns the result of the operation, without modifying the original"]
3723    fn unwrapped_div_euclid(self, rhs: Self) -> Self {
3724        self.strict_div_euclid(rhs)
3725    }
3726
3727    /// Strict remainder for Euclidean division. Returns the
3728    /// remainder, panicking if the divisor is zero.
3729    ///
3730    /// # Panics
3731    ///
3732    /// Panics if the divisor is zero.
3733    #[deprecated(since = "1.30.0", note = "renamed to `strict_rem_euclid`")]
3734    #[track_caller]
3735    #[must_use = "this returns the result of the operation, without modifying the original"]
3736    fn unwrapped_rem_euclid(self, rhs: Self) -> Self {
3737        self.strict_rem_euclid(rhs)
3738    }
3739
3740    /// Strict multiplication by an integer. Returns the product, panicking on overflow.
3741    ///
3742    /// # Panics
3743    ///
3744    /// Panics if the result does not fit.
3745    #[deprecated(since = "1.30.0", note = "renamed to `strict_mul_int`")]
3746    #[track_caller]
3747    #[must_use = "this returns the result of the operation, without modifying the original"]
3748    fn unwrapped_mul_int(self, rhs: Self::Bits) -> Self {
3749        self.strict_mul_int(rhs)
3750    }
3751
3752    /// Strict division by an integer. Returns the quotient, panicking on overflow.
3753    ///
3754    /// # Panics
3755    ///
3756    /// Panics if the divisor is zero or if the result does not fit.
3757    #[deprecated(since = "1.30.0", note = "renamed to `strict_div_int`")]
3758    #[track_caller]
3759    #[must_use = "this returns the result of the operation, without modifying the original"]
3760    fn unwrapped_div_int(self, rhs: Self::Bits) -> Self {
3761        self.strict_div_int(rhs)
3762    }
3763
3764    /// Strict remainder for division by an integer. Returns the
3765    /// remainder, panicking if the divisor is zero.
3766    ///
3767    /// # Panics
3768    ///
3769    /// Panics if the divisor is zero.
3770    #[deprecated(since = "1.30.0", note = "renamed to `strict_rem_int`")]
3771    #[track_caller]
3772    #[must_use = "this returns the result of the operation, without modifying the original"]
3773    fn unwrapped_rem_int(self, rhs: Self::Bits) -> Self {
3774        self.strict_rem_int(rhs)
3775    }
3776
3777    /// Strict Euclidean division by an integer. Returns the
3778    /// quotient, panicking on overflow.
3779    ///
3780    /// # Panics
3781    ///
3782    /// Panics if the divisor is zero or if the result does not fit.
3783    #[deprecated(since = "1.30.0", note = "renamed to `strict_div_euclid_int`")]
3784    #[track_caller]
3785    #[must_use = "this returns the result of the operation, without modifying the original"]
3786    fn unwrapped_div_euclid_int(self, rhs: Self::Bits) -> Self {
3787        self.strict_div_euclid_int(rhs)
3788    }
3789
3790    /// Strict remainder for Euclidean division by an integer.
3791    /// Returns the remainder, panicking on overflow.
3792    ///
3793    /// # Panics
3794    ///
3795    /// Panics if the divisor is zero or if the result does not fit.
3796    #[deprecated(since = "1.30.0", note = "renamed to `strict_rem_euclid_int`")]
3797    #[track_caller]
3798    #[must_use = "this returns the result of the operation, without modifying the original"]
3799    fn unwrapped_rem_euclid_int(self, rhs: Self::Bits) -> Self {
3800        self.strict_rem_euclid_int(rhs)
3801    }
3802
3803    /// Strict shift left. Panics if `rhs`&nbsp;≥ the number of bits.
3804    ///
3805    /// # Panics
3806    ///
3807    /// Panics if `rhs`&nbsp;≥ the number of bits.
3808    #[deprecated(since = "1.30.0", note = "renamed to `strict_shl`")]
3809    #[track_caller]
3810    #[must_use = "this returns the result of the operation, without modifying the original"]
3811    fn unwrapped_shl(self, rhs: u32) -> Self {
3812        self.strict_shl(rhs)
3813    }
3814
3815    /// Strict shift right. Panics if `rhs`&nbsp;≥ the number of bits.
3816    ///
3817    /// # Panics
3818    ///
3819    /// Panics if `rhs`&nbsp;≥ the number of bits.
3820    #[deprecated(since = "1.30.0", note = "renamed to `strict_shr`")]
3821    #[track_caller]
3822    #[must_use = "this returns the result of the operation, without modifying the original"]
3823    fn unwrapped_shr(self, rhs: u32) -> Self {
3824        self.strict_shr(rhs)
3825    }
3826
3827    /// Strict distance. Returns the distance from `self` to `other`,
3828    /// panicking on overflow.
3829    ///
3830    /// # Panics
3831    ///
3832    /// Panics if the result does not fit.
3833    ///
3834    /// See also
3835    /// <code>FixedI32::[unwrapped\_dist][FixedI32::unwrapped_dist]</code> and
3836    /// <code>FixedU32::[unwrapped\_dist][FixedU32::unwrapped_dist]</code>.
3837    #[deprecated(since = "1.30.0", note = "renamed to `strict_dist`")]
3838    #[track_caller]
3839    #[must_use = "this returns the result of the operation, without modifying the original"]
3840    fn unwrapped_dist(self, other: Self) -> Self {
3841        self.strict_dist(other)
3842    }
3843
3844    /// Compute the hypotenuse of a right triange, panicking on overflow.
3845    ///
3846    /// # Panics
3847    ///
3848    /// Panics if the result does not fit.
3849    #[deprecated(since = "1.30.0", note = "renamed to `strict_hypot`")]
3850    #[track_caller]
3851    #[must_use = "this returns the result of the operation, without modifying the original"]
3852    fn unwrapped_hypot(self, other: Self) -> Self {
3853        self.strict_hypot(other)
3854    }
3855
3856    /// Returns the square root, panicking if the number is negative or on overflow.
3857    ///
3858    /// # Panics
3859    ///
3860    /// Panics if the number is negative or on overflow.
3861    #[deprecated(since = "1.30.0", note = "renamed to `strict_sqrt`")]
3862    fn unwrapped_sqrt(self) -> Self {
3863        self.strict_sqrt()
3864    }
3865
3866    /// Linear interpolation between `start` and `end`, panicking on overflow.
3867    ///
3868    /// # Panics
3869    ///
3870    /// Panics if the result does not fit.
3871    #[deprecated(since = "1.30.0", note = "renamed to `strict_lerp`")]
3872    #[track_caller]
3873    #[must_use]
3874    fn unwrapped_lerp(self, start: Self, end: Self) -> Self {
3875        self.strict_lerp(start, end)
3876    }
3877
3878    /// Inverse linear interpolation between `start` and `end`, panicking on overflow.
3879    ///
3880    /// # Panics
3881    ///
3882    /// Panics when `start`&nbsp;=&nbsp;`end` or when the results overflows.
3883    #[deprecated(since = "1.30.0", note = "renamed to `strict_inv_lerp`")]
3884    #[track_caller]
3885    #[must_use]
3886    fn unwrapped_inv_lerp(self, start: Self, end: Self) -> Self {
3887        self.strict_inv_lerp(start, end)
3888    }
3889}
3890
3891/// This trait provides methods common to all signed fixed-point numbers.
3892///
3893/// Methods common to all fixed-point numbers including unsigned
3894/// fixed-point numbers are provided by the [`Fixed`] supertrait.
3895///
3896/// This trait is sealed and cannot be implemented for more types; it
3897/// is implemented for [`FixedI8`], [`FixedI16`], [`FixedI32`],
3898/// [`FixedI64`], and [`FixedI128`].
3899pub trait FixedSigned: Fixed
3900where
3901    Self: Neg<Output = Self>,
3902{
3903    /// Negative one if the fixed-point number can represent it, otherwise
3904    /// [`None`].
3905    const TRY_NEG_ONE: Option<Self>;
3906
3907    /// Returns the number of bits required to represent the value.
3908    ///
3909    /// See also <code>FixedI32::[signed\_bits][FixedI32::signed_bits]</code>.
3910    fn signed_bits(self) -> u32;
3911
3912    /// Returns [`true`] if the number is >&nbsp;0.
3913    ///
3914    /// See also <code>FixedI32::[is\_positive][FixedI32::is_positive]</code>.
3915    fn is_positive(self) -> bool;
3916
3917    /// Returns [`true`] if the number is <&nbsp;0.
3918    ///
3919    /// See also <code>FixedI32::[is\_negative][FixedI32::is_negative]</code>.
3920    fn is_negative(self) -> bool;
3921
3922    /// Returns the absolute value.
3923    ///
3924    /// See also <code>FixedI32::[abs][FixedI32::abs]</code>.
3925    #[must_use]
3926    fn abs(self) -> Self;
3927
3928    /// Returns the absolute value using an unsigned type without any
3929    /// wrapping or panicking.
3930    ///
3931    /// See also <code>FixedI32::[unsigned\_abs][FixedI32::unsigned_abs]</code>.
3932    fn unsigned_abs(self) -> Self::Unsigned;
3933
3934    /// Returns the distance from `self` to `other` using an unsigned type
3935    /// without any wrapping or panicking.
3936    ///
3937    /// See also
3938    /// <code>FixedI32::[unsigned\_dist][FixedI32::unsigned_dist]</code>.
3939    fn unsigned_dist(self, other: Self) -> Self::Unsigned;
3940
3941    /// Returns a number representing the sign of `self`.
3942    ///
3943    /// See also <code>FixedI32::[signum][FixedI32::signum]</code>.
3944    ///
3945    /// # Panics
3946    ///
3947    /// When debug assertions are enabled, this method panics
3948    ///   * if the value is positive and the fixed-point number has
3949    ///     zero or one integer bits such that it cannot hold the
3950    ///     value 1.
3951    ///   * if the value is negative and the fixed-point number has
3952    ///     zero integer bits, such that it cannot hold the value &minus;1.
3953    ///
3954    /// When debug assertions are not enabled, the wrapped value can
3955    /// be returned in those cases, but it is not considered a
3956    /// breaking change if in the future it panics; using this method
3957    /// when 1 and &minus;1 cannot be represented is almost certainly a bug.
3958    #[must_use]
3959    fn signum(self) -> Self;
3960
3961    /// Addition with an unsigned fixed-point number.
3962    ///
3963    /// See also <code>FixedI32::[add\_unsigned][FixedI32::add_unsigned]</code>.
3964    #[must_use]
3965    fn add_unsigned(self, rhs: Self::Unsigned) -> Self;
3966
3967    /// Subtraction with an unsigned fixed-point number.
3968    ///
3969    /// See also <code>FixedI32::[sub\_unsigned][FixedI32::sub_unsigned]</code>.
3970    #[must_use]
3971    fn sub_unsigned(self, rhs: Self::Unsigned) -> Self;
3972
3973    /// Checked absolute value. Returns the absolute value, or [`None`] on overflow.
3974    ///
3975    /// Overflow can only occur when trying to find the absolute value of the minimum value.
3976    ///
3977    /// See also <code>FixedI32::[checked\_abs][FixedI32::checked_abs]</code>.
3978    fn checked_abs(self) -> Option<Self>;
3979
3980    /// Checked signum. Returns a number representing the sign of
3981    /// `self`, or [`None`] on overflow.
3982    ///
3983    /// Overflow can only occur
3984    ///   * if the value is positive and the fixed-point number has zero
3985    ///     or one integer bits such that it cannot hold the value 1.
3986    ///   * if the value is negative and the fixed-point number has zero
3987    ///     integer bits, such that it cannot hold the value &minus;1.
3988    ///
3989    /// See also
3990    /// <code>FixedI32::[checked\_signum][FixedI32::checked_signum]</code>.
3991    fn checked_signum(self) -> Option<Self>;
3992
3993    /// Checked addition with an unsigned fixed-point number. Returns the sum,
3994    /// or [`None`] on overflow.
3995    ///
3996    /// See also
3997    /// <code>FixedI32::[checked\_add\_unsigned][FixedI32::checked_add_unsigned]</code>.
3998    #[must_use]
3999    fn checked_add_unsigned(self, rhs: Self::Unsigned) -> Option<Self>;
4000
4001    /// Checked subtraction with an unsigned fixed-point number. Returns the
4002    /// difference, or [`None`] on overflow.
4003    ///
4004    /// See also <code>FixedI32::[checked\_sub\_unsigned][FixedI32::checked_sub_unsigned]</code>.
4005    #[must_use]
4006    fn checked_sub_unsigned(self, rhs: Self::Unsigned) -> Option<Self>;
4007
4008    /// Saturating absolute value. Returns the absolute value, saturating on overflow.
4009    ///
4010    /// Overflow can only occur when trying to find the absolute value of the minimum value.
4011    ///
4012    /// See also
4013    /// <code>FixedI32::[saturating\_abs][FixedI32::saturating_abs]</code>.
4014    #[must_use]
4015    fn saturating_abs(self) -> Self;
4016
4017    /// Saturating signum. Returns a number representing the sign of
4018    /// `self`, saturating on overflow.
4019    ///
4020    /// Overflow can only occur
4021    ///   * if the value is positive and the fixed-point number has zero
4022    ///     or one integer bits such that it cannot hold the value 1.
4023    ///   * if the value is negative and the fixed-point number has zero
4024    ///     integer bits, such that it cannot hold the value &minus;1.
4025    ///
4026    /// See also
4027    /// <code>FixedI32::[saturating\_signum][FixedI32::saturating_signum]</code>.
4028    #[must_use]
4029    fn saturating_signum(self) -> Self;
4030
4031    /// Saturating addition with an unsigned fixed-point number. Returns the
4032    /// sum, saturating on overflow.
4033    ///
4034    /// See also
4035    /// <code>FixedI32::[saturating\_add\_unsigned][FixedI32::saturating_add_unsigned]</code>.
4036    #[must_use]
4037    fn saturating_add_unsigned(self, rhs: Self::Unsigned) -> Self;
4038
4039    /// Saturating subtraction with an unsigned fixed-point number. Returns the
4040    /// difference, saturating on overflow.
4041    ///
4042    /// See also
4043    /// <code>FixedI32::[saturating\_sub\_unsigned][FixedI32::saturating_sub_unsigned]</code>.
4044    #[must_use]
4045    fn saturating_sub_unsigned(self, rhs: Self::Unsigned) -> Self;
4046
4047    /// Wrapping absolute value. Returns the absolute value, wrapping on overflow.
4048    ///
4049    /// Overflow can only occur when trying to find the absolute value of the minimum value.
4050    ///
4051    /// See also <code>FixedI32::[wrapping\_abs][FixedI32::wrapping_abs]</code>.
4052    #[must_use]
4053    fn wrapping_abs(self) -> Self;
4054
4055    /// Wrapping signum. Returns a number representing the sign of
4056    /// `self`, wrapping on overflow.
4057    ///
4058    /// Overflow can only occur
4059    ///   * if the value is positive and the fixed-point number has zero
4060    ///     or one integer bits such that it cannot hold the value 1.
4061    ///   * if the value is negative and the fixed-point number has zero
4062    ///     integer bits, such that it cannot hold the value &minus;1.
4063    ///
4064    /// See also
4065    /// <code>FixedI32::[wrapping\_signum][FixedI32::wrapping_signum]</code>.
4066    #[must_use]
4067    fn wrapping_signum(self) -> Self;
4068
4069    /// Wrapping addition with an unsigned fixed-point number. Returns the sum,
4070    /// wrapping on overflow.
4071    ///
4072    /// See also
4073    /// <code>FixedI32::[wrapping\_add\_unsigned][FixedI32::wrapping_add_unsigned]</code>.
4074    #[must_use]
4075    fn wrapping_add_unsigned(self, rhs: Self::Unsigned) -> Self;
4076
4077    /// Wrapping subtraction with an unsigned fixed-point number. Returns the
4078    /// difference, wrapping on overflow.
4079    ///
4080    /// See also
4081    /// <code>FixedI32::[wrapping\_sub\_unsigned][FixedI32::wrapping_sub_unsigned]</code>.
4082    #[must_use]
4083    fn wrapping_sub_unsigned(self, rhs: Self::Unsigned) -> Self;
4084
4085    /// Strict absolute value. Returns the absolute value, panicking on overflow.
4086    ///
4087    /// Overflow can only occur when trying to find the absolute value of the minimum value.
4088    ///
4089    /// See also
4090    /// <code>FixedI32::[strict\_abs][FixedI32::strict_abs]</code>.
4091    ///
4092    /// # Panics
4093    ///
4094    /// Panics if the result does not fit.
4095    #[track_caller]
4096    #[must_use]
4097    fn strict_abs(self) -> Self;
4098
4099    /// Strict signum. Returns a number representing the sign of
4100    /// `self`, panicking on overflow.
4101    ///
4102    /// Overflow can only occur
4103    ///   * if the value is positive and the fixed-point number has zero
4104    ///     or one integer bits such that it cannot hold the value 1.
4105    ///   * if the value is negative and the fixed-point number has zero
4106    ///     integer bits, such that it cannot hold the value &minus;1.
4107    ///
4108    /// See also
4109    /// <code>FixedI32::[strict\_signum][FixedI32::strict_signum]</code>.
4110    ///
4111    /// # Panics
4112    ///
4113    /// Panics if the result does not fit.
4114    #[track_caller]
4115    #[must_use]
4116    fn strict_signum(self) -> Self;
4117
4118    /// Strict addition with an unsigned fixed-point number. Returns the sum,
4119    /// panicking on overflow.
4120    ///
4121    /// See also
4122    /// <code>FixedI32::[strict\_add\_unsigned][FixedI32::strict_add_unsigned]</code>.
4123    ///
4124    /// # Panics
4125    ///
4126    /// Panics if the result does not fit.
4127    #[track_caller]
4128    #[must_use]
4129    fn strict_add_unsigned(self, rhs: Self::Unsigned) -> Self;
4130
4131    /// Strict subtraction with an unsigned fixed-point number. Returns the
4132    /// difference, panicking on overflow.
4133    ///
4134    /// See also
4135    /// <code>FixedI32::[strict\_sub\_unsigned][FixedI32::strict_sub_unsigned]</code>.
4136    ///
4137    /// # Panics
4138    ///
4139    /// Panics if the result does not fit.
4140    #[track_caller]
4141    #[must_use]
4142    fn strict_sub_unsigned(self, rhs: Self::Unsigned) -> Self;
4143
4144    /// Overflowing absolute value.
4145    ///
4146    /// Returns a [tuple] of the fixed-point number and a [`bool`],
4147    /// indicating whether an overflow has occurred. On overflow, the
4148    /// wrapped value is returned.
4149    ///
4150    /// See also
4151    /// <code>FixedI32::[overflowing\_abs][FixedI32::overflowing_abs]</code>.
4152    fn overflowing_abs(self) -> (Self, bool);
4153
4154    /// Overflowing signum.
4155    ///
4156    /// Returns a [tuple] of the signum and a [`bool`], indicating
4157    /// whether an overflow has occurred. On overflow, the wrapped
4158    /// value is returned.
4159    ///
4160    /// Overflow can only occur
4161    ///   * if the value is positive and the fixed-point number has zero
4162    ///     or one integer bits such that it cannot hold the value 1.
4163    ///   * if the value is negative and the fixed-point number has zero
4164    ///     integer bits, such that it cannot hold the value &minus;1.
4165    ///
4166    /// See also
4167    /// <code>FixedI32::[overflowing\_signum][FixedI32::overflowing_signum]</code>.
4168    fn overflowing_signum(self) -> (Self, bool);
4169
4170    /// Overflowing addition with an unsigned fixed-point number.
4171    ///
4172    /// Returns a [tuple] of the sum and a [`bool`], indicating whether an
4173    /// overflow has occurred. On overflow, the wrapped value is returned.
4174    ///
4175    /// See also
4176    /// <code>FixedI32::[overflowing\_add\_unsigned][FixedI32::overflowing_add_unsigned]</code>.
4177    #[must_use]
4178    fn overflowing_add_unsigned(self, rhs: Self::Unsigned) -> (Self, bool);
4179
4180    /// Overflowing subtraction with an unsigned fixed-point number.
4181    ///
4182    /// Returns a [tuple] of the difference and a [`bool`], indicating whether
4183    /// an overflow has occurred. On overflow, the wrapped value is returned.
4184    ///
4185    /// See also
4186    /// <code>FixedI32::[overflowing\_sub\_unsigned][FixedI32::overflowing_sub_unsigned]</code>.
4187    #[must_use]
4188    fn overflowing_sub_unsigned(self, rhs: Self::Unsigned) -> (Self, bool);
4189
4190    /// Strict absolute value. Returns the absolute value, panicking on overflow.
4191    ///
4192    /// # Panics
4193    ///
4194    /// Panics if the result does not fit.
4195    #[deprecated(since = "1.30.0", note = "renamed to `strict_abs`")]
4196    #[track_caller]
4197    #[must_use]
4198    fn unwrapped_abs(self) -> Self {
4199        self.strict_abs()
4200    }
4201
4202    /// Strict signum. Returns a number representing the sign of
4203    /// `self`, panicking on overflow.
4204    ///
4205    /// # Panics
4206    ///
4207    /// Panics if the result does not fit.
4208    #[deprecated(since = "1.30.0", note = "renamed to `strict_signum`")]
4209    #[track_caller]
4210    #[must_use]
4211    fn unwrapped_signum(self) -> Self {
4212        self.strict_signum()
4213    }
4214
4215    /// Strict addition with an unsigned fixed-point number. Returns the sum,
4216    /// panicking on overflow.
4217    ///
4218    /// # Panics
4219    ///
4220    /// Panics if the result does not fit.
4221    #[deprecated(since = "1.30.0", note = "renamed to `strict_add_unsigned`")]
4222    #[track_caller]
4223    #[must_use]
4224    fn unwrapped_add_unsigned(self, rhs: Self::Unsigned) -> Self {
4225        self.strict_add_unsigned(rhs)
4226    }
4227
4228    /// Strict subtraction with an unsigned fixed-point number. Returns the
4229    /// difference, panicking on overflow.
4230    ///
4231    /// # Panics
4232    ///
4233    /// Panics if the result does not fit.
4234    #[deprecated(since = "1.30.0", note = "renamed to `strict_sub_unsigned`")]
4235    #[track_caller]
4236    #[must_use]
4237    fn unwrapped_sub_unsigned(self, rhs: Self::Unsigned) -> Self {
4238        self.strict_sub_unsigned(rhs)
4239    }
4240}
4241
4242/// This trait provides methods common to all unsigned fixed-point numbers.
4243///
4244/// Methods common to all fixed-point numbers including signed
4245/// fixed-point numbers are provided by the [`Fixed`] supertrait.
4246///
4247/// This trait is sealed and cannot be implemented for more types; it
4248/// is implemented for [`FixedU8`], [`FixedU16`], [`FixedU32`],
4249/// [`FixedU64`], and [`FixedU128`].
4250pub trait FixedUnsigned: Fixed
4251where
4252    Self: Div<<Self as Fixed>::NonZeroBits, Output = Self>,
4253    Self: DivAssign<<Self as Fixed>::NonZeroBits>,
4254{
4255    /// Returns the number of bits required to represent the value.
4256    ///
4257    /// See also
4258    /// <code>FixedU32::[significant\_bits][FixedU32::significant_bits]</code>.
4259    fn significant_bits(self) -> u32;
4260
4261    /// Returns [`true`] if the fixed-point number is
4262    /// 2<sup><i>k</i></sup> for some integer <i>k</i>.
4263    ///
4264    /// See also
4265    /// <code>FixedU32::[is\_power\_of\_two][FixedU32::is_power_of_two]</code>.
4266    fn is_power_of_two(self) -> bool;
4267
4268    /// Returns the highest one in the binary representation, or zero
4269    /// if `self` is zero.
4270    ///
4271    /// See also <code>FixedU32::[highest\_one][FixedU32::highest_one]</code>.
4272    #[must_use]
4273    fn highest_one(self) -> Self;
4274
4275    /// Returns the smallest power of two that is ≥&nbsp;`self`.
4276    ///
4277    /// See also
4278    /// <code>FixedU32::[next\_power\_of\_two][FixedU32::next_power_of_two]</code>.
4279    #[must_use]
4280    fn next_power_of_two(self) -> Self;
4281
4282    /// Addition with an signed fixed-point number.
4283    ///
4284    /// See also <code>FixedU32::[add\_signed][FixedU32::add_signed]</code>.
4285    #[must_use]
4286    fn add_signed(self, rhs: Self::Signed) -> Self;
4287
4288    /// Subtraction with an signed fixed-point number.
4289    ///
4290    /// See also <code>FixedU32::[sub\_signed][FixedU32::sub_signed]</code>.
4291    #[must_use]
4292    fn sub_signed(self, rhs: Self::Signed) -> Self;
4293
4294    /// Returns the smallest power of two that is ≥&nbsp;`self`, or [`None`] if the
4295    /// next power of two is too large to represent.
4296    ///
4297    /// See also
4298    /// <code>FixedU32::[checked\_next\_power\_of\_two][FixedU32::checked_next_power_of_two]</code>.
4299    fn checked_next_power_of_two(self) -> Option<Self>;
4300
4301    /// Checked addition with an signed fixed-point number. Returns the sum,
4302    /// or [`None`] on overflow.
4303    ///
4304    /// See also
4305    /// <code>FixedU32::[checked\_add\_signed][FixedU32::checked_add_signed]</code>.
4306    #[must_use]
4307    fn checked_add_signed(self, rhs: Self::Signed) -> Option<Self>;
4308
4309    /// Checked subtraction with an signed fixed-point number. Returns the
4310    /// difference, or [`None`] on overflow.
4311    ///
4312    /// See also <code>FixedU32::[checked\_sub\_signed][FixedU32::checked_sub_signed]</code>.
4313    #[must_use]
4314    fn checked_sub_signed(self, rhs: Self::Signed) -> Option<Self>;
4315
4316    /// Saturating addition with an signed fixed-point number. Returns the
4317    /// sum, saturating on overflow.
4318    ///
4319    /// See also
4320    /// <code>FixedU32::[saturating\_add\_signed][FixedU32::saturating_add_signed]</code>.
4321    #[must_use]
4322    fn saturating_add_signed(self, rhs: Self::Signed) -> Self;
4323
4324    /// Saturating subtraction with an signed fixed-point number. Returns the
4325    /// difference, saturating on overflow.
4326    ///
4327    /// See also
4328    /// <code>FixedU32::[saturating\_sub\_signed][FixedU32::saturating_sub_signed]</code>.
4329    #[must_use]
4330    fn saturating_sub_signed(self, rhs: Self::Signed) -> Self;
4331
4332    /// Returns the smallest power of two that is ≥&nbsp;`self`, wrapping
4333    /// to 0 if the next power of two is too large to represent.
4334    ///
4335    /// See also
4336    /// <code>FixedU32::[wrapping\_next\_power\_of\_two][FixedU32::wrapping_next_power_of_two]</code>.
4337    #[must_use]
4338    fn wrapping_next_power_of_two(self) -> Self;
4339
4340    /// Wrapping addition with an signed fixed-point number. Returns the sum,
4341    /// wrapping on overflow.
4342    ///
4343    /// See also
4344    /// <code>FixedU32::[wrapping\_add\_signed][FixedU32::wrapping_add_signed]</code>.
4345    #[must_use]
4346    fn wrapping_add_signed(self, rhs: Self::Signed) -> Self;
4347
4348    /// Wrapping subtraction with an signed fixed-point number. Returns the
4349    /// difference, wrapping on overflow.
4350    ///
4351    /// See also
4352    /// <code>FixedU32::[wrapping\_sub\_signed][FixedU32::wrapping_sub_signed]</code>.
4353    #[must_use]
4354    fn wrapping_sub_signed(self, rhs: Self::Signed) -> Self;
4355
4356    /// Returns the smallest power of two that is ≥&nbsp;`self`, panicking
4357    /// if the next power of two is too large to represent.
4358    ///
4359    /// See also
4360    /// <code>FixedU32::[strict\_next\_power\_of\_two][FixedU32::strict_next_power_of_two]</code>.
4361    ///
4362    /// # Panics
4363    ///
4364    /// Panics if the result does not fit.
4365    #[track_caller]
4366    #[must_use]
4367    fn strict_next_power_of_two(self) -> Self;
4368
4369    /// Strict addition with an signed fixed-point number. Returns the sum,
4370    /// panicking on overflow.
4371    ///
4372    /// See also
4373    /// <code>FixedU32::[strict\_add\_signed][FixedU32::strict_add_signed]</code>.
4374    ///
4375    /// # Panics
4376    ///
4377    /// Panics if the result does not fit.
4378    #[track_caller]
4379    #[must_use]
4380    fn strict_add_signed(self, rhs: Self::Signed) -> Self;
4381
4382    /// Strict subtraction with an signed fixed-point number. Returns the
4383    /// difference, panicking on overflow.
4384    ///
4385    /// See also
4386    /// <code>FixedU32::[strict\_sub\_signed][FixedU32::strict_sub_signed]</code>.
4387    ///
4388    /// # Panics
4389    ///
4390    /// Panics if the result does not fit.
4391    #[track_caller]
4392    #[must_use]
4393    fn strict_sub_signed(self, rhs: Self::Signed) -> Self;
4394
4395    /// Overflowing addition with an signed fixed-point number.
4396    ///
4397    /// Returns a [tuple] of the sum and a [`bool`], indicating whether an
4398    /// overflow has occurred. On overflow, the wrapped value is returned.
4399    ///
4400    /// See also
4401    /// <code>FixedU32::[overflowing\_add\_signed][FixedU32::overflowing_add_signed]</code>.
4402    #[must_use]
4403    fn overflowing_add_signed(self, rhs: Self::Signed) -> (Self, bool);
4404
4405    /// Overflowing subtraction with an signed fixed-point number.
4406    ///
4407    /// Returns a [tuple] of the difference and a [`bool`], indicating whether
4408    /// an overflow has occurred. On overflow, the wrapped value is returned.
4409    ///
4410    /// See also
4411    /// <code>FixedU32::[overflowing\_sub\_signed][FixedU32::overflowing_sub_signed]</code>.
4412    #[must_use]
4413    fn overflowing_sub_signed(self, rhs: Self::Signed) -> (Self, bool);
4414
4415    /// Returns the smallest power of two that is ≥&nbsp;`self`, panicking
4416    /// if the next power of two is too large to represent.
4417    ///
4418    /// # Panics
4419    ///
4420    /// Panics if the result does not fit.
4421    #[deprecated(since = "1.30.0", note = "renamed to `strict_next_power_of_two`")]
4422    #[track_caller]
4423    #[must_use]
4424    fn unwrapped_next_power_of_two(self) -> Self {
4425        self.strict_next_power_of_two()
4426    }
4427
4428    /// Strict addition with an signed fixed-point number. Returns the sum,
4429    /// panicking on overflow.
4430    ///
4431    /// # Panics
4432    ///
4433    /// Panics if the result does not fit.
4434    #[deprecated(since = "1.30.0", note = "renamed to `strict_add_signed`")]
4435    #[track_caller]
4436    #[must_use]
4437    fn unwrapped_add_signed(self, rhs: Self::Signed) -> Self {
4438        self.strict_add_signed(rhs)
4439    }
4440
4441    /// Strict subtraction with an signed fixed-point number. Returns the
4442    /// difference, panicking on overflow.
4443    ///
4444    /// # Panics
4445    ///
4446    /// Panics if the result does not fit.
4447    #[deprecated(since = "1.30.0", note = "renamed to `strict_sub_signed`")]
4448    #[track_caller]
4449    #[must_use]
4450    fn unwrapped_sub_signed(self, rhs: Self::Signed) -> Self {
4451        self.strict_sub_signed(rhs)
4452    }
4453}
4454
4455/// This trait provides lossless conversions that might be fallible.
4456///
4457/// This trait is implemented for conversions between integer
4458/// primitives, floating-point primitives and fixed-point numbers.
4459///
4460/// # Examples
4461///
4462/// ```rust
4463/// use fixed::traits::LosslessTryFrom;
4464/// use fixed::types::{I24F8, I4F12};
4465/// // original is 0x000001.23, lossless is 0x1.230
4466/// let original = I24F8::from_bits(0x0000_0123);
4467/// let lossless = I4F12::lossless_try_from(original);
4468/// assert_eq!(lossless, Some(I4F12::from_bits(0x1230)));
4469/// // too_large is 0x000012.34, 0x12.340 does not fit in I4F12
4470/// let too_large = I24F8::from_bits(0x0000_1234);
4471/// let overflow = I4F12::lossless_try_from(too_large);
4472/// assert_eq!(overflow, None);
4473/// ```
4474pub trait LosslessTryFrom<Src>: Sized {
4475    /// Performs the conversion.
4476    fn lossless_try_from(src: Src) -> Option<Self>;
4477}
4478
4479/// This trait provides lossless conversions that might be fallible.
4480/// This is the reciprocal of [`LosslessTryFrom`].
4481///
4482/// Usually [`LosslessTryFrom`] should be implemented instead of this
4483/// trait; there is a blanket implementation which provides this trait
4484/// when [`LosslessTryFrom`] is implemented (similar to [`Into`] and
4485/// [`From`]).
4486///
4487/// # Examples
4488///
4489/// ```rust
4490/// use fixed::traits::LosslessTryInto;
4491/// use fixed::types::{I24F8, I4F12};
4492/// // original is 0x000001.23, lossless is 0x1.230
4493/// let original = I24F8::from_bits(0x0000_0123);
4494/// let lossless: Option<I4F12> = original.lossless_try_into();
4495/// assert_eq!(lossless, Some(I4F12::from_bits(0x1230)));
4496/// // too_large is 0x000012.34, 0x12.340 does not fit in I4F12
4497/// let too_large = I24F8::from_bits(0x0000_1234);
4498/// let overflow: Option<I4F12> = too_large.lossless_try_into();
4499/// assert_eq!(overflow, None);
4500/// ```
4501pub trait LosslessTryInto<Dst> {
4502    /// Performs the conversion.
4503    fn lossless_try_into(self) -> Option<Dst>;
4504}
4505
4506impl<Src, Dst> LosslessTryInto<Dst> for Src
4507where
4508    Dst: LosslessTryFrom<Src>,
4509{
4510    fn lossless_try_into(self) -> Option<Dst> {
4511        Dst::lossless_try_from(self)
4512    }
4513}
4514
4515/// This trait provides infallible conversions that might be lossy.
4516///
4517/// This trait is implemented for conversions between integer
4518/// primitives, floating-point primitives and fixed-point numbers.
4519///
4520/// # Examples
4521///
4522/// ```rust
4523/// use fixed::traits::LossyFrom;
4524/// use fixed::types::{I12F4, I8F24};
4525/// // original is 0x12.345678, lossy is 0x012.3
4526/// let original = I8F24::from_bits(0x1234_5678);
4527/// let lossy = I12F4::lossy_from(original);
4528/// assert_eq!(lossy, I12F4::from_bits(0x0123));
4529/// ```
4530pub trait LossyFrom<Src> {
4531    /// Performs the conversion.
4532    fn lossy_from(src: Src) -> Self;
4533}
4534
4535/// This trait provides infallible conversions that might be lossy.
4536/// This is the reciprocal of [`LossyFrom`].
4537///
4538/// Usually [`LossyFrom`] should be implemented instead of this trait;
4539/// there is a blanket implementation which provides this trait when
4540/// [`LossyFrom`] is implemented (similar to [`Into`] and [`From`]).
4541///
4542/// # Examples
4543///
4544/// ```rust
4545/// use fixed::traits::LossyInto;
4546/// use fixed::types::{I12F4, I8F24};
4547/// // original is 0x12.345678, lossy is 0x012.3
4548/// let original = I8F24::from_bits(0x1234_5678);
4549/// let lossy: I12F4 = original.lossy_into();
4550/// assert_eq!(lossy, I12F4::from_bits(0x0123));
4551/// ```
4552pub trait LossyInto<Dst> {
4553    /// Performs the conversion.
4554    fn lossy_into(self) -> Dst;
4555}
4556
4557impl<Src, Dst> LossyInto<Dst> for Src
4558where
4559    Dst: LossyFrom<Src>,
4560{
4561    fn lossy_into(self) -> Dst {
4562        Dst::lossy_from(self)
4563    }
4564}
4565
4566/// This trait provides checked conversions from fixed-point numbers.
4567///
4568/// This trait is implemented for conversions between integer
4569/// primitives, floating-point primitives and fixed-point numbers.
4570///
4571/// # Examples
4572///
4573/// ```rust
4574/// use fixed::traits::FromFixed;
4575/// use fixed::types::U8F8;
4576/// // 0x87.65
4577/// let f = U8F8::from_bits(0x8765);
4578/// assert_eq!(f32::from_fixed(f), f32::from(0x8765u16) / 256.0);
4579/// assert_eq!(i32::checked_from_fixed(f), Some(0x87));
4580/// assert_eq!(u8::saturating_from_fixed(f), 0x87);
4581/// // no fit
4582/// assert_eq!(i8::checked_from_fixed(f), None);
4583/// assert_eq!(i8::saturating_from_fixed(f), i8::MAX);
4584/// assert_eq!(i8::wrapping_from_fixed(f), 0x87u8 as i8);
4585/// assert_eq!(i8::overflowing_from_fixed(f), (0x87u8 as i8, true));
4586/// ```
4587pub trait FromFixed {
4588    /// Converts from a fixed-point number.
4589    ///
4590    /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
4591    ///
4592    /// # Panics
4593    ///
4594    /// When debug assertions are enabled, panics if the value does
4595    /// not fit. When debug assertions are not enabled, the wrapped
4596    /// value can be returned, but it is not considered a breaking
4597    /// change if in the future it panics; if wrapping is required use
4598    /// [`wrapping_from_fixed`] instead.
4599    ///
4600    /// [`wrapping_from_fixed`]: FromFixed::wrapping_from_fixed
4601    fn from_fixed<F: Fixed>(src: F) -> Self;
4602
4603    /// Converts from a fixed-point number if it fits, otherwise returns [`None`].
4604    ///
4605    /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
4606    fn checked_from_fixed<F: Fixed>(src: F) -> Option<Self>
4607    where
4608        Self: Sized;
4609
4610    /// Converts from a fixed-point number, saturating if it does not fit.
4611    ///
4612    /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
4613    fn saturating_from_fixed<F: Fixed>(src: F) -> Self;
4614
4615    /// Converts from a fixed-point number, wrapping if it does not fit.
4616    ///
4617    /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
4618    fn wrapping_from_fixed<F: Fixed>(src: F) -> Self;
4619
4620    /// Converts from a fixed-point number.
4621    ///
4622    /// Returns a [tuple] of the value and a [`bool`] indicating whether
4623    /// an overflow has occurred. On overflow, the wrapped value is
4624    /// returned.
4625    ///
4626    /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
4627    fn overflowing_from_fixed<F: Fixed>(src: F) -> (Self, bool)
4628    where
4629        Self: Sized;
4630
4631    /// Converts from a fixed-point number, panicking if the value
4632    /// does not fit.
4633    ///
4634    /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
4635    ///
4636    /// # Panics
4637    ///
4638    /// Panics if the value does not fit, even when debug assertions
4639    /// are not enabled.
4640    #[inline]
4641    #[track_caller]
4642    fn strict_from_fixed<F: Fixed>(src: F) -> Self
4643    where
4644        Self: Sized,
4645    {
4646        match Self::overflowing_from_fixed(src) {
4647            (val, false) => val,
4648            (_, true) => panic!("overflow"),
4649        }
4650    }
4651
4652    /// Converts from a fixed-point number, panicking if the value
4653    /// does not fit.
4654    ///
4655    /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
4656    ///
4657    /// # Panics
4658    ///
4659    /// Panics if the value does not fit, even when debug assertions
4660    /// are not enabled.
4661    #[deprecated(since = "1.30.0", note = "renamed to `strict_from_fixed`")]
4662    #[inline]
4663    #[track_caller]
4664    fn unwrapped_from_fixed<F: Fixed>(src: F) -> Self
4665    where
4666        Self: Sized,
4667    {
4668        Self::strict_from_fixed(src)
4669    }
4670}
4671
4672/// This trait provides checked conversions to fixed-point numbers.
4673///
4674/// This trait is implemented for conversions between integer
4675/// primitives, floating-point primitives and fixed-point numbers.
4676///
4677/// # Examples
4678///
4679/// ```rust
4680/// use fixed::traits::ToFixed;
4681/// use fixed::types::{U8F8, U16F16};
4682/// let f: U8F8 = 13.5f32.to_fixed();
4683/// assert_eq!(f, U8F8::from_bits((13 << 8) | (1 << 7)));
4684/// // 0x1234.5678 is too large and can be wrapped to 0x34.56
4685/// let too_large = U16F16::from_bits(0x1234_5678);
4686/// let checked: Option<U8F8> = too_large.checked_to_num();
4687/// assert_eq!(checked, None);
4688/// let saturating: U8F8 = too_large.saturating_to_num();
4689/// assert_eq!(saturating, U8F8::MAX);
4690/// let wrapping: U8F8 = too_large.wrapping_to_num();
4691/// assert_eq!(wrapping, U8F8::from_bits(0x3456));
4692/// let overflowing: (U8F8, bool) = too_large.overflowing_to_num();
4693/// assert_eq!(overflowing, (U8F8::from_bits(0x3456), true));
4694/// ```
4695pub trait ToFixed {
4696    /// Converts to a fixed-point number.
4697    ///
4698    /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
4699    ///
4700    /// # Panics
4701    ///
4702    /// Panics if `self` is a floating-point number that is not [finite].
4703    ///
4704    /// When debug assertions are enabled, also panics if the value
4705    /// does not fit. When debug assertions are not enabled, the
4706    /// wrapped value can be returned, but it is not considered a
4707    /// breaking change if in the future it panics; if wrapping is
4708    /// required use [`wrapping_to_fixed`] instead.
4709    ///
4710    /// [`wrapping_to_fixed`]: ToFixed::wrapping_to_fixed
4711    /// [finite]: f64::is_finite
4712    fn to_fixed<F: Fixed>(self) -> F;
4713
4714    /// Converts to a fixed-point number if it fits, otherwise returns [`None`].
4715    ///
4716    /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
4717    fn checked_to_fixed<F: Fixed>(self) -> Option<F>;
4718
4719    /// Converts to a fixed-point number, saturating if it does not fit.
4720    ///
4721    /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
4722    ///
4723    /// # Panics
4724    ///
4725    /// Panics if `self` is a floating-point number that is [NaN].
4726    ///
4727    /// [NaN]: f64::is_nan
4728    fn saturating_to_fixed<F: Fixed>(self) -> F;
4729
4730    /// Converts to a fixed-point number, wrapping if it does not fit.
4731    ///
4732    /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
4733    ///
4734    /// # Panics
4735    ///
4736    /// Panics if `self` is a floating-point number that is not [finite].
4737    ///
4738    /// [finite]: f64::is_finite
4739    fn wrapping_to_fixed<F: Fixed>(self) -> F;
4740
4741    /// Converts to a fixed-point number.
4742    ///
4743    /// Returns a [tuple] of the fixed-point number and a [`bool`]
4744    /// indicating whether an overflow has occurred. On overflow, the
4745    /// wrapped value is returned.
4746    ///
4747    /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
4748    ///
4749    /// # Panics
4750    ///
4751    /// Panics if `self` is a floating-point number that is not [finite].
4752    ///
4753    /// [finite]: f64::is_finite
4754    fn overflowing_to_fixed<F: Fixed>(self) -> (F, bool);
4755
4756    /// Converts to a fixed-point number, panicking if it does not fit.
4757    ///
4758    /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
4759    ///
4760    /// # Panics
4761    ///
4762    /// Panics if `self` is a floating-point number that is not
4763    /// [finite] or if the value does not fit, even if debug
4764    /// assertions are not enabled.
4765    ///
4766    /// [finite]: f64::is_finite
4767    #[inline]
4768    #[track_caller]
4769    fn strict_to_fixed<F: Fixed>(self) -> F
4770    where
4771        Self: Sized,
4772    {
4773        match self.overflowing_to_fixed() {
4774            (val, false) => val,
4775            (_, true) => panic!("overflow"),
4776        }
4777    }
4778
4779    /// Converts to a fixed-point number, panicking if it does not fit.
4780    ///
4781    /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
4782    ///
4783    /// # Panics
4784    ///
4785    /// Panics if `self` is a floating-point number that is not
4786    /// [finite] or if the value does not fit, even if debug
4787    /// assertions are not enabled.
4788    ///
4789    /// [finite]: f64::is_finite
4790    #[deprecated(since = "1.30.0", note = "renamed to `strict_to_fixed`")]
4791    #[inline]
4792    #[track_caller]
4793    fn unwrapped_to_fixed<F: Fixed>(self) -> F
4794    where
4795        Self: Sized,
4796    {
4797        self.strict_to_fixed()
4798    }
4799}
4800
4801/// This trait provides a way to convert a number to/from an equivalent
4802/// fixed-point number.
4803///
4804/// Implementations are provided for the signed integer primitives [`i8`],
4805/// [`i16`], [`i32`], [`i64`] and [`i128`], which have equivalent fixed-point
4806/// types [`I8F0`], [`I16F0`], [`I32F0`], [`I64F0`] and [`I128F0`]. Similar
4807/// implementations are provided for the unsigned integer primitives [`u8`],
4808/// [`u16`], [`u32`], [`u64`] and [`u128`].
4809///
4810/// # Examples
4811///
4812/// An [`i32`] can be treated as an [`I32F0`].
4813///
4814/// ```rust
4815/// use fixed::traits::{Fixed, FixedEquiv};
4816///
4817/// fn next_up<F: Fixed>(f: &mut F) {
4818///     *f += F::DELTA;
4819/// }
4820///
4821/// let mut i = 12i32;
4822/// // next_up is called with &mut i converted to &mut I32F0
4823/// next_up(i.as_fixed_equiv_mut());
4824/// assert_eq!(i, 13);
4825/// ```
4826///
4827/// Simlarly, an [`I32F0`] can be treated as an [`i32`].
4828///
4829/// ```rust
4830/// use fixed::traits::FixedEquiv;
4831/// use fixed::types::I32F0;
4832///
4833/// fn increase_by_5(i: &mut i32) {
4834///     *i += 5;
4835/// }
4836///
4837/// let mut f = I32F0::from_num(12);
4838/// // increase_by_5 is called with &mut f converted to &mut i32
4839/// increase_by_5(i32::mut_from_fixed_equiv(&mut f));
4840/// assert_eq!(f, 17);
4841/// ```
4842///
4843/// [`I8F0`]: crate::types::I8F0
4844/// [`I16F0`]: crate::types::I16F0
4845/// [`I32F0`]: crate::types::I32F0
4846/// [`I64F0`]: crate::types::I64F0
4847/// [`I128F0`]: crate::types::I128F0
4848pub trait FixedEquiv {
4849    /// The equivalent fixed-point type.
4850    type Equiv: Fixed;
4851
4852    /// Converts an owned value to the equivalent fixed-point type.
4853    fn to_fixed_equiv(self) -> Self::Equiv;
4854
4855    /// Converts a reference into a reference to the equivalent fixed-point
4856    /// type.
4857    fn as_fixed_equiv(&self) -> &Self::Equiv;
4858
4859    /// Converts a mutable reference into a mutable reference to the equivalent
4860    /// fixed-point type.
4861    fn as_fixed_equiv_mut(&mut self) -> &mut Self::Equiv;
4862
4863    /// Converts an owned equivalent fixed-point type to this type.
4864    fn from_fixed_equiv(f: Self::Equiv) -> Self;
4865
4866    /// Converts a reference to the equivalent fixed-point type into a reference
4867    /// to this type.
4868    fn ref_from_fixed_equiv(f: &Self::Equiv) -> &Self;
4869
4870    /// Converts a mutable reference to the equivalent fixed-point type into a
4871    /// mutable reference to this type.
4872    fn mut_from_fixed_equiv(f: &mut Self::Equiv) -> &mut Self;
4873}
4874
4875macro_rules! trait_delegate {
4876    (fn $method:ident($($param:ident: $Param:ty),*$(,)?) -> $Ret:ty) => {
4877        #[inline]
4878        fn $method($($param: $Param),*) -> $Ret {
4879            Self::$method($($param),*)
4880        }
4881    };
4882    (fn $method:ident(self $(, $param:ident: $Param:ty)*) -> $Ret:ty) => {
4883        #[inline]
4884        fn $method(self $(, $param: $Param)*) -> $Ret {
4885            self.$method($($param),*)
4886        }
4887    };
4888    (unsafe fn $method:ident(self $(, $param:ident: $Param:ty)*) -> $Ret:ty) => {
4889        #[inline]
4890        unsafe fn $method(self $(, $param: $Param)*) -> $Ret {
4891            unsafe { self.$method($($param),*) }
4892        }
4893    };
4894    (fn $method:ident(&mut self $(, $param:ident: $Param:ty)*) $(-> $Ret:ty)*) => {
4895        #[inline]
4896        fn $method(&mut self $(, $param: $Param)*) $(-> $Ret)* {
4897            self.$method($($param),*)
4898        }
4899    };
4900    (fn $method:ident<$Gen:ident: $Trait:ident>($($param:ident: $Param:ty),*) -> $Ret:ty) => {
4901        #[inline]
4902        fn $method<$Gen: $Trait>($($param: $Param),*) -> $Ret {
4903            Self::$method($($param),*)
4904        }
4905    };
4906    (fn $method:ident<$Gen:ident: $Trait:ident>(self $(, $param:ident: $Param:ty)*) -> $Ret:ty) => {
4907        #[inline]
4908        fn $method<$Gen: $Trait>(self $(, $param: $Param)*) -> $Ret {
4909            self.$method($($param),*)
4910        }
4911    };
4912}
4913
4914macro_rules! impl_fixed {
4915    (
4916        $Fixed:ident, $IFixed:ident, $UFixed:ident, $LeEqU:ident, $Bits:ident, $Signedness:ident
4917    ) => {
4918        impl<Frac: $LeEqU> FixedOptionalArbitrary for $Fixed<Frac> {}
4919        impl<Frac: $LeEqU> FixedOptionalBorsh for $Fixed<Frac> {}
4920        impl<Frac: $LeEqU> FixedOptionalNum for $Fixed<Frac> {}
4921        impl<Frac: $LeEqU> FixedOptionalSerde for $Fixed<Frac> {}
4922        impl<Frac: $LeEqU> FixedOptionalNightlyFloat for $Fixed<Frac> {}
4923        impl<Frac: $LeEqU> FixedOptionalFeatures for $Fixed<Frac> {}
4924
4925        impl<Frac: $LeEqU> Fixed for $Fixed<Frac> {
4926            type Bits = $Bits;
4927            type NonZeroBits = NonZero<$Bits>;
4928            type Bytes = [u8; size_of::<$Bits>()];
4929            type Frac = Frac;
4930            type Signed = $IFixed<Frac>;
4931            type Unsigned = $UFixed<Frac>;
4932            const ZERO: Self = Self::ZERO;
4933            const TRY_ONE: Option<Self> = Self::TRY_ONE;
4934            const DELTA: Self = Self::DELTA;
4935            const MIN: Self = Self::MIN;
4936            const MAX: Self = Self::MAX;
4937            const IS_SIGNED: bool = Self::IS_SIGNED;
4938            const INT_NBITS: u32 = Self::INT_NBITS;
4939            const FRAC_NBITS: u32 = Self::FRAC_NBITS;
4940            trait_delegate! { fn from_bits(bits: Self::Bits) -> Self }
4941            trait_delegate! { fn to_bits(self) -> Self::Bits }
4942            trait_delegate! { fn from_be(fixed: Self) -> Self }
4943            trait_delegate! { fn from_le(fixed: Self) -> Self }
4944            trait_delegate! { fn to_be(self) -> Self }
4945            trait_delegate! { fn to_le(self) -> Self }
4946            trait_delegate! { fn swap_bytes(self) -> Self }
4947            trait_delegate! { fn from_be_bytes(bits: Self::Bytes) -> Self }
4948            trait_delegate! { fn from_le_bytes(bits: Self::Bytes) -> Self }
4949            trait_delegate! { fn from_ne_bytes(bits: Self::Bytes) -> Self }
4950            trait_delegate! { fn to_be_bytes(self) -> Self::Bytes }
4951            trait_delegate! { fn to_le_bytes(self) -> Self::Bytes }
4952            trait_delegate! { fn to_ne_bytes(self) -> Self::Bytes }
4953            trait_delegate! { fn from_num<Src: ToFixed>(src: Src) -> Self }
4954            trait_delegate! { fn to_num<Dst: FromFixed>(self) -> Dst }
4955            trait_delegate! { fn checked_from_num<Src: ToFixed>(val: Src) -> Option<Self> }
4956            trait_delegate! { fn checked_to_num<Dst: FromFixed>(self) -> Option<Dst> }
4957            trait_delegate! { fn saturating_from_num<Src: ToFixed>(val: Src) -> Self }
4958            trait_delegate! { fn saturating_to_num<Dst: FromFixed>(self) -> Dst }
4959            trait_delegate! { fn wrapping_from_num<Src: ToFixed>(val: Src) -> Self }
4960            trait_delegate! { fn wrapping_to_num<Dst: FromFixed>(self) -> Dst }
4961            trait_delegate! { fn strict_from_num<Src: ToFixed>(val: Src) -> Self }
4962            trait_delegate! { fn strict_to_num<Dst: FromFixed>(self) -> Dst }
4963            trait_delegate! { fn overflowing_from_num<Src: ToFixed>(val: Src) -> (Self, bool) }
4964            trait_delegate! { fn overflowing_to_num<Dst: FromFixed>(self) -> (Dst, bool) }
4965            trait_delegate! { fn from_str_binary(src: &str) -> Result<Self, ParseFixedError> }
4966            trait_delegate! { fn from_str_octal(src: &str) -> Result<Self, ParseFixedError> }
4967            trait_delegate! { fn from_str_hex(src: &str) -> Result<Self, ParseFixedError> }
4968            trait_delegate! { fn from_ascii(src: &[u8]) -> Result<Self, ParseFixedError> }
4969            trait_delegate! { fn from_ascii_binary(src: &[u8]) -> Result<Self, ParseFixedError> }
4970            trait_delegate! { fn from_ascii_octal(src: &[u8]) -> Result<Self, ParseFixedError> }
4971            trait_delegate! { fn from_ascii_hex(src: &[u8]) -> Result<Self, ParseFixedError> }
4972            trait_delegate! {
4973                fn saturating_from_str(src: &str) -> Result<Self, ParseFixedError>
4974            }
4975            trait_delegate! {
4976                fn saturating_from_str_binary(src: &str) -> Result<Self, ParseFixedError>
4977            }
4978            trait_delegate! {
4979                fn saturating_from_str_octal(src: &str) -> Result<Self, ParseFixedError>
4980            }
4981            trait_delegate! {
4982                fn saturating_from_str_hex(src: &str) -> Result<Self, ParseFixedError>
4983            }
4984            trait_delegate! {
4985                fn saturating_from_ascii(src: &[u8]) -> Result<Self, ParseFixedError>
4986            }
4987            trait_delegate! {
4988                fn saturating_from_ascii_binary(src: &[u8]) -> Result<Self, ParseFixedError>
4989            }
4990            trait_delegate! {
4991                fn saturating_from_ascii_octal(src: &[u8]) -> Result<Self, ParseFixedError>
4992            }
4993            trait_delegate! {
4994                fn saturating_from_ascii_hex(src: &[u8]) -> Result<Self, ParseFixedError>
4995            }
4996            trait_delegate! {
4997                fn wrapping_from_str(src: &str) -> Result<Self, ParseFixedError>
4998            }
4999            trait_delegate! {
5000                fn wrapping_from_str_binary(src: &str) -> Result<Self, ParseFixedError>
5001            }
5002            trait_delegate! {
5003                fn wrapping_from_str_octal(src: &str) -> Result<Self, ParseFixedError>
5004            }
5005            trait_delegate! {
5006                fn wrapping_from_str_hex(src: &str) -> Result<Self, ParseFixedError>
5007            }
5008            trait_delegate! {
5009                fn wrapping_from_ascii(src: &[u8]) -> Result<Self, ParseFixedError>
5010            }
5011            trait_delegate! {
5012                fn wrapping_from_ascii_binary(src: &[u8]) -> Result<Self, ParseFixedError>
5013            }
5014            trait_delegate! {
5015                fn wrapping_from_ascii_octal(src: &[u8]) -> Result<Self, ParseFixedError>
5016            }
5017            trait_delegate! {
5018                fn wrapping_from_ascii_hex(src: &[u8]) -> Result<Self, ParseFixedError>
5019            }
5020            trait_delegate! { fn strict_from_str(src: &str) -> Self }
5021            trait_delegate! { fn strict_from_str_binary(src: &str) -> Self }
5022            trait_delegate! { fn strict_from_str_octal(src: &str) -> Self }
5023            trait_delegate! { fn strict_from_str_hex(src: &str) -> Self }
5024            trait_delegate! { fn strict_from_ascii(src: &[u8]) -> Self }
5025            trait_delegate! { fn strict_from_ascii_binary(src: &[u8]) -> Self }
5026            trait_delegate! { fn strict_from_ascii_octal(src: &[u8]) -> Self }
5027            trait_delegate! { fn strict_from_ascii_hex(src: &[u8]) -> Self }
5028            trait_delegate! {
5029                fn overflowing_from_str(src: &str) -> Result<(Self, bool), ParseFixedError>
5030            }
5031            trait_delegate! {
5032                fn overflowing_from_str_binary(src: &str) -> Result<(Self, bool), ParseFixedError>
5033            }
5034            trait_delegate! {
5035                fn overflowing_from_str_octal(src: &str) -> Result<(Self, bool), ParseFixedError>
5036            }
5037            trait_delegate! {
5038                fn overflowing_from_str_hex(src: &str) -> Result<(Self, bool), ParseFixedError>
5039            }
5040            trait_delegate! {
5041                fn overflowing_from_ascii(src: &[u8]) -> Result<(Self, bool), ParseFixedError>
5042            }
5043            trait_delegate! {
5044                fn overflowing_from_ascii_binary(
5045                    src: &[u8],
5046                ) -> Result<(Self, bool), ParseFixedError>
5047            }
5048            trait_delegate! {
5049                fn overflowing_from_ascii_octal(src: &[u8]) -> Result<(Self, bool), ParseFixedError>
5050            }
5051            trait_delegate! {
5052                fn overflowing_from_ascii_hex(src: &[u8]) -> Result<(Self, bool), ParseFixedError>
5053            }
5054            trait_delegate! { fn int(self) -> Self }
5055            trait_delegate! { fn frac(self) -> Self }
5056            trait_delegate! { fn ceil(self) -> Self }
5057            trait_delegate! { fn floor(self) -> Self }
5058            trait_delegate! { fn round_to_zero(self) -> Self }
5059            trait_delegate! { fn round(self) -> Self }
5060            trait_delegate! { fn round_ties_even(self) -> Self }
5061            trait_delegate! { fn checked_ceil(self) -> Option<Self> }
5062            trait_delegate! { fn checked_floor(self) -> Option<Self> }
5063            trait_delegate! { fn checked_round(self) -> Option<Self> }
5064            trait_delegate! { fn checked_round_ties_even(self) -> Option<Self> }
5065            trait_delegate! { fn saturating_ceil(self) -> Self }
5066            trait_delegate! { fn saturating_floor(self) -> Self }
5067            trait_delegate! { fn saturating_round(self) -> Self }
5068            trait_delegate! { fn saturating_round_ties_even(self) -> Self }
5069            trait_delegate! { fn wrapping_ceil(self) -> Self }
5070            trait_delegate! { fn wrapping_floor(self) -> Self }
5071            trait_delegate! { fn wrapping_round(self) -> Self }
5072            trait_delegate! { fn wrapping_round_ties_even(self) -> Self }
5073            trait_delegate! { fn strict_ceil(self) -> Self }
5074            trait_delegate! { fn strict_floor(self) -> Self }
5075            trait_delegate! { fn strict_round(self) -> Self }
5076            trait_delegate! { fn strict_round_ties_even(self) -> Self }
5077            trait_delegate! { fn overflowing_ceil(self) -> (Self, bool) }
5078            trait_delegate! { fn overflowing_floor(self) -> (Self, bool) }
5079            trait_delegate! { fn overflowing_round(self) -> (Self, bool) }
5080            trait_delegate! { fn overflowing_round_ties_even(self) -> (Self, bool) }
5081            trait_delegate! { fn count_ones(self) -> u32 }
5082            trait_delegate! { fn count_zeros(self) -> u32 }
5083            trait_delegate! { fn leading_ones(self) -> u32 }
5084            trait_delegate! { fn leading_zeros(self) -> u32 }
5085            trait_delegate! { fn trailing_ones(self) -> u32 }
5086            trait_delegate! { fn trailing_zeros(self) -> u32 }
5087            trait_delegate! { fn int_log2(self) -> i32 }
5088            trait_delegate! { fn int_log10(self) -> i32 }
5089            trait_delegate! { fn int_log(self, base: u32) -> i32 }
5090            trait_delegate! { fn checked_int_log2(self) -> Option<i32> }
5091            trait_delegate! { fn checked_int_log10(self) -> Option<i32> }
5092            trait_delegate! { fn checked_int_log(self, base: u32) -> Option<i32> }
5093            trait_delegate! { fn reverse_bits(self) -> Self }
5094            trait_delegate! { fn rotate_left(self, n: u32) -> Self }
5095            trait_delegate! { fn rotate_right(self, n: u32) -> Self }
5096            trait_delegate! { fn is_zero(self) -> bool }
5097            trait_delegate! { fn dist(self, other: Self) -> Self }
5098            trait_delegate! { fn abs_diff(self, other: Self) -> Self::Unsigned }
5099            trait_delegate! { fn mean(self, other: Self) -> Self }
5100            trait_delegate! { fn hypot(self, other: Self) -> Self }
5101            trait_delegate! { fn recip(self) -> Self }
5102            trait_delegate! { fn next_multiple_of(self, other: Self) -> Self }
5103            trait_delegate! { fn mul_add(self, mul: Self, add: Self) -> Self }
5104            trait_delegate! { fn add_prod(self, a: Self, b: Self) -> Self }
5105            trait_delegate! { fn mul_acc(&mut self, a: Self, b: Self) }
5106            trait_delegate! { fn div_euclid(self, rhs: Self) -> Self }
5107            trait_delegate! { fn rem_euclid(self, rhs: Self) -> Self }
5108            trait_delegate! { fn div_euclid_int(self, rhs: Self::Bits) -> Self }
5109            trait_delegate! { fn rem_euclid_int(self, rhs: Self::Bits) -> Self }
5110            trait_delegate! { fn unbounded_shl(self, rhs: u32) -> Self }
5111            trait_delegate! { fn unbounded_shr(self, rhs: u32) -> Self }
5112            trait_delegate! { fn sqrt(self) -> Self }
5113            trait_delegate! { fn lerp(self, start: Self, end: Self) -> Self }
5114            trait_delegate! { fn inv_lerp(self, start: Self, end: Self) -> Self }
5115            trait_delegate! { fn checked_neg(self) -> Option<Self> }
5116            trait_delegate! { fn checked_add(self, rhs: Self) -> Option<Self> }
5117            trait_delegate! { fn checked_sub(self, rhs: Self) -> Option<Self> }
5118            trait_delegate! { fn checked_mul(self, rhs: Self) -> Option<Self> }
5119            trait_delegate! { fn checked_div(self, rhs: Self) -> Option<Self> }
5120            trait_delegate! { fn checked_rem(self, rhs: Self) -> Option<Self> }
5121            trait_delegate! { fn checked_recip(self) -> Option<Self> }
5122            trait_delegate! { fn checked_next_multiple_of(self, other: Self) -> Option<Self> }
5123            trait_delegate! { fn checked_mul_add(self, mul: Self, add: Self) -> Option<Self> }
5124            trait_delegate! { fn checked_add_prod(self, a: Self, b: Self) -> Option<Self> }
5125            trait_delegate! { fn checked_mul_acc(&mut self, a: Self, b: Self) -> Option<()> }
5126            trait_delegate! { fn checked_div_euclid(self, rhs: Self) -> Option<Self> }
5127            trait_delegate! { fn checked_rem_euclid(self, rhs: Self) -> Option<Self> }
5128            trait_delegate! { fn checked_mul_int(self, rhs: Self::Bits) -> Option<Self> }
5129            trait_delegate! { fn checked_div_int(self, rhs: Self::Bits) -> Option<Self> }
5130            trait_delegate! { fn checked_rem_int(self, rhs: Self::Bits) -> Option<Self> }
5131            trait_delegate! { fn checked_div_euclid_int(self, rhs: Self::Bits) -> Option<Self> }
5132            trait_delegate! { fn checked_rem_euclid_int(self, rhs: Self::Bits) -> Option<Self> }
5133            trait_delegate! { fn checked_shl(self, rhs: u32) -> Option<Self> }
5134            trait_delegate! { fn checked_shr(self, rhs: u32) -> Option<Self> }
5135            trait_delegate! { fn checked_dist(self, other: Self) -> Option<Self> }
5136            trait_delegate! { fn checked_hypot(self, other: Self) -> Option<Self> }
5137            trait_delegate! { fn checked_sqrt(self) -> Option<Self> }
5138            trait_delegate! { fn checked_lerp(self, start: Self, end: Self) -> Option<Self> }
5139            trait_delegate! { fn checked_inv_lerp(self, start: Self, end: Self) -> Option<Self> }
5140            trait_delegate! { fn saturating_neg(self) -> Self }
5141            trait_delegate! { fn saturating_add(self, rhs: Self) -> Self }
5142            trait_delegate! { fn saturating_sub(self, rhs: Self) -> Self }
5143            trait_delegate! { fn saturating_mul(self, rhs: Self) -> Self }
5144            trait_delegate! { fn saturating_div(self, rhs: Self) -> Self }
5145            trait_delegate! { fn saturating_recip(self) -> Self }
5146            trait_delegate! { fn saturating_next_multiple_of(self, other: Self) -> Self }
5147            trait_delegate! { fn saturating_mul_add(self, mul: Self, add: Self) -> Self }
5148            trait_delegate! { fn saturating_add_prod(self, a: Self, b: Self) -> Self }
5149            trait_delegate! { fn saturating_mul_acc(&mut self, a: Self, b: Self) }
5150            trait_delegate! { fn saturating_div_euclid(self, rhs: Self) -> Self }
5151            trait_delegate! { fn saturating_mul_int(self, rhs: Self::Bits) -> Self }
5152            trait_delegate! { fn saturating_div_int(self, rhs: Self::Bits) -> Self }
5153            trait_delegate! { fn saturating_div_euclid_int(self, rhs: Self::Bits) -> Self }
5154            trait_delegate! { fn saturating_rem_euclid_int(self, rhs: Self::Bits) -> Self }
5155            trait_delegate! { fn saturating_dist(self, other: Self) -> Self }
5156            trait_delegate! { fn saturating_hypot(self, other: Self) -> Self }
5157            trait_delegate! { fn saturating_sqrt(self) -> Self }
5158            trait_delegate! { fn saturating_lerp(self, start: Self, end: Self) -> Self }
5159            trait_delegate! { fn saturating_inv_lerp(self, start: Self, end: Self) -> Self }
5160            trait_delegate! { fn wrapping_neg(self) -> Self }
5161            trait_delegate! { fn wrapping_add(self, rhs: Self) -> Self }
5162            trait_delegate! { fn wrapping_sub(self, rhs: Self) -> Self }
5163            trait_delegate! { fn wrapping_mul(self, rhs: Self) -> Self }
5164            trait_delegate! { fn wrapping_div(self, rhs: Self) -> Self }
5165            trait_delegate! { fn wrapping_recip(self) -> Self }
5166            trait_delegate! { fn wrapping_next_multiple_of(self, other: Self) -> Self }
5167            trait_delegate! { fn wrapping_mul_add(self, mul: Self, add: Self) -> Self }
5168            trait_delegate! { fn wrapping_add_prod(self, a: Self, b: Self) -> Self }
5169            trait_delegate! { fn wrapping_mul_acc(&mut self, a: Self, b: Self) }
5170            trait_delegate! { fn wrapping_div_euclid(self, rhs: Self) -> Self }
5171            trait_delegate! { fn wrapping_mul_int(self, rhs: Self::Bits) -> Self }
5172            trait_delegate! { fn wrapping_div_int(self, rhs: Self::Bits) -> Self }
5173            trait_delegate! { fn wrapping_div_euclid_int(self, rhs: Self::Bits) -> Self }
5174            trait_delegate! { fn wrapping_rem_euclid_int(self, rhs: Self::Bits) -> Self }
5175            trait_delegate! { fn wrapping_shl(self, rhs: u32) -> Self }
5176            trait_delegate! { fn wrapping_shr(self, rhs: u32) -> Self }
5177            trait_delegate! { fn wrapping_dist(self, other: Self) -> Self }
5178            trait_delegate! { fn wrapping_hypot(self, other: Self) -> Self }
5179            trait_delegate! { fn wrapping_sqrt(self) -> Self }
5180            trait_delegate! { fn wrapping_lerp(self, start: Self, end: Self) -> Self }
5181            trait_delegate! { fn wrapping_inv_lerp(self, start: Self, end: Self) -> Self }
5182            trait_delegate! { fn strict_neg(self) -> Self }
5183            trait_delegate! { fn strict_add(self, rhs: Self) -> Self }
5184            trait_delegate! { fn strict_sub(self, rhs: Self) -> Self }
5185            trait_delegate! { fn strict_mul(self, rhs: Self) -> Self }
5186            trait_delegate! { fn strict_div(self, rhs: Self) -> Self }
5187            trait_delegate! { fn strict_rem(self, rhs: Self) -> Self }
5188            trait_delegate! { fn strict_recip(self) -> Self }
5189            trait_delegate! { fn strict_next_multiple_of(self, other: Self) -> Self }
5190            trait_delegate! { fn strict_mul_add(self, mul: Self, add: Self) -> Self }
5191            trait_delegate! { fn strict_add_prod(self, a: Self, b: Self) -> Self }
5192            trait_delegate! { fn strict_mul_acc(&mut self, a: Self, b: Self) }
5193            trait_delegate! { fn strict_div_euclid(self, rhs: Self) -> Self }
5194            trait_delegate! { fn strict_rem_euclid(self, rhs: Self) -> Self }
5195            trait_delegate! { fn strict_mul_int(self, rhs: Self::Bits) -> Self }
5196            trait_delegate! { fn strict_div_int(self, rhs: Self::Bits) -> Self }
5197            trait_delegate! { fn strict_rem_int(self, rhs: Self::Bits) -> Self }
5198            trait_delegate! { fn strict_div_euclid_int(self, rhs: Self::Bits) -> Self }
5199            trait_delegate! { fn strict_rem_euclid_int(self, rhs: Self::Bits) -> Self }
5200            trait_delegate! { fn strict_shl(self, rhs: u32) -> Self }
5201            trait_delegate! { fn strict_shr(self, rhs: u32) -> Self }
5202            trait_delegate! { fn strict_dist(self, other: Self) -> Self }
5203            trait_delegate! { fn strict_hypot(self, other: Self) -> Self }
5204            trait_delegate! { fn strict_sqrt(self) -> Self }
5205            trait_delegate! { fn strict_lerp(self, start: Self, end: Self) -> Self }
5206            trait_delegate! { fn strict_inv_lerp(self, start: Self, end: Self) -> Self }
5207            trait_delegate! { fn overflowing_neg(self) -> (Self, bool) }
5208            trait_delegate! { fn overflowing_add(self, rhs: Self) -> (Self, bool) }
5209            trait_delegate! { fn overflowing_sub(self, rhs: Self) -> (Self, bool) }
5210            trait_delegate! { fn overflowing_mul(self, rhs: Self) -> (Self, bool) }
5211            trait_delegate! { fn overflowing_div(self, rhs: Self) -> (Self, bool) }
5212            trait_delegate! { fn overflowing_recip(self) -> (Self, bool) }
5213            trait_delegate! { fn overflowing_next_multiple_of(self, other: Self) -> (Self, bool) }
5214            trait_delegate! { fn overflowing_mul_add(self, mul: Self, add: Self) -> (Self, bool) }
5215            trait_delegate! { fn overflowing_add_prod(self, a: Self, b: Self) -> (Self, bool) }
5216            trait_delegate! { fn overflowing_mul_acc(&mut self, a: Self, b: Self) -> bool }
5217            trait_delegate! { fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool) }
5218            trait_delegate! { fn overflowing_mul_int(self, rhs: Self::Bits) -> (Self, bool) }
5219            trait_delegate! { fn overflowing_div_int(self, rhs: Self::Bits) -> (Self, bool) }
5220            trait_delegate! { fn overflowing_div_euclid_int(self, rhs: Self::Bits) -> (Self, bool) }
5221            trait_delegate! { fn overflowing_rem_euclid_int(self, rhs: Self::Bits) -> (Self, bool) }
5222            trait_delegate! { fn overflowing_shl(self, rhs: u32) -> (Self, bool) }
5223            trait_delegate! { fn overflowing_shr(self, rhs: u32) -> (Self, bool) }
5224            trait_delegate! { fn overflowing_dist(self, other: Self) -> (Self, bool) }
5225            trait_delegate! { fn overflowing_hypot(self, other: Self) -> (Self, bool) }
5226            trait_delegate! { fn overflowing_sqrt(self) -> (Self, bool) }
5227            trait_delegate! { fn overflowing_lerp(self, start: Self, end: Self) -> (Self, bool) }
5228            trait_delegate! {
5229                fn overflowing_inv_lerp(self, start: Self, end: Self) -> (Self, bool)
5230            }
5231            trait_delegate! { unsafe fn unchecked_add(self, rhs: Self) -> Self }
5232            trait_delegate! { unsafe fn unchecked_sub(self, rhs: Self) -> Self }
5233            trait_delegate! { unsafe fn unchecked_mul_int(self, rhs: Self::Bits) -> Self }
5234        }
5235
5236        impl<Frac: $LeEqU> FromFixed for $Fixed<Frac> {
5237            /// Converts a fixed-point number.
5238            ///
5239            /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
5240            ///
5241            /// # Panics
5242            ///
5243            /// When debug assertions are enabled, panics if the value
5244            /// does not fit. When debug assertions are not enabled,
5245            /// the wrapped value can be returned, but it is not
5246            /// considered a breaking change if in the future it
5247            /// panics; if wrapping is required use
5248            /// [`wrapping_from_fixed`] instead.
5249            ///
5250            /// [`wrapping_from_fixed`]: FromFixed::wrapping_from_fixed
5251            #[inline]
5252            fn from_fixed<F: Fixed>(src: F) -> Self {
5253                let (wrapped, overflow) = FromFixed::overflowing_from_fixed(src);
5254                debug_assert!(!overflow, "{} overflows", src);
5255                wrapped
5256            }
5257
5258            /// Converts a fixed-point number if it fits, otherwise returns [`None`].
5259            ///
5260            /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
5261            #[inline]
5262            fn checked_from_fixed<F: Fixed>(src: F) -> Option<Self> {
5263                match FromFixed::overflowing_from_fixed(src) {
5264                    (_, true) => None,
5265                    (wrapped, false) => Some(wrapped),
5266                }
5267            }
5268
5269            /// Converts a fixed-point number, saturating if it does not fit.
5270            ///
5271            /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
5272            #[inline]
5273            fn saturating_from_fixed<F: Fixed>(src: F) -> Self {
5274                let conv = src.to_fixed_helper(Private, Self::FRAC_NBITS, Self::INT_NBITS);
5275                if conv.overflow {
5276                    return if src < 0 { Self::MIN } else { Self::MAX };
5277                }
5278                let bits = if_signed_unsigned!(
5279                    $Signedness,
5280                    match conv.bits {
5281                        Widest::Unsigned(bits) => {
5282                            if (bits as $Bits) < 0 {
5283                                return Self::MAX;
5284                            }
5285                            bits as $Bits
5286                        }
5287                        Widest::Negative(bits) => bits as $Bits,
5288                    },
5289                    match conv.bits {
5290                        Widest::Unsigned(bits) => bits as $Bits,
5291                        Widest::Negative(_) => {
5292                            return Self::MIN;
5293                        }
5294                    },
5295                );
5296                Self::from_bits(bits)
5297            }
5298
5299            /// Converts a fixed-point number, wrapping if it does not fit.
5300            ///
5301            /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
5302            #[inline]
5303            fn wrapping_from_fixed<F: Fixed>(src: F) -> Self {
5304                let (wrapped, _) = FromFixed::overflowing_from_fixed(src);
5305                wrapped
5306            }
5307
5308            /// Converts a fixed-point number.
5309            ///
5310            /// Returns a [tuple] of the value and a [`bool`]
5311            /// indicating whether an overflow has occurred. On
5312            /// overflow, the wrapped value is returned.
5313            ///
5314            /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
5315            #[inline]
5316            fn overflowing_from_fixed<F: Fixed>(src: F) -> (Self, bool) {
5317                let conv = src.to_fixed_helper(Private, Self::FRAC_NBITS, Self::INT_NBITS);
5318                let mut new_overflow = false;
5319                let bits = if_signed_unsigned!(
5320                    $Signedness,
5321                    match conv.bits {
5322                        Widest::Unsigned(bits) => {
5323                            if (bits as $Bits) < 0 {
5324                                new_overflow = true;
5325                            }
5326                            bits as $Bits
5327                        }
5328                        Widest::Negative(bits) => bits as $Bits,
5329                    },
5330                    match conv.bits {
5331                        Widest::Unsigned(bits) => bits as $Bits,
5332                        Widest::Negative(bits) => {
5333                            new_overflow = true;
5334                            bits as $Bits
5335                        }
5336                    },
5337                );
5338                (Self::from_bits(bits), conv.overflow || new_overflow)
5339            }
5340        }
5341
5342        impl<Frac: $LeEqU> ToFixed for $Fixed<Frac> {
5343            /// Converts a fixed-point number.
5344            ///
5345            /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
5346            ///
5347            /// # Panics
5348            ///
5349            /// When debug assertions are enabled, panics if the value
5350            /// does not fit. When debug assertions are not enabled,
5351            /// the wrapped value can be returned, but it is not
5352            /// considered a breaking change if in the future it
5353            /// panics; if wrapping is required use
5354            /// [`wrapping_to_fixed`] instead.
5355            ///
5356            /// [`wrapping_to_fixed`]: ToFixed::wrapping_to_fixed
5357            #[inline]
5358            fn to_fixed<F: Fixed>(self) -> F {
5359                FromFixed::from_fixed(self)
5360            }
5361
5362            /// Converts a fixed-point number if it fits, otherwise returns [`None`].
5363            ///
5364            /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
5365            #[inline]
5366            fn checked_to_fixed<F: Fixed>(self) -> Option<F> {
5367                FromFixed::checked_from_fixed(self)
5368            }
5369
5370            /// Converts a fixed-point number, saturating if it does not fit.
5371            ///
5372            /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
5373            #[inline]
5374            fn saturating_to_fixed<F: Fixed>(self) -> F {
5375                FromFixed::saturating_from_fixed(self)
5376            }
5377
5378            /// Converts a fixed-point number, wrapping if it does not fit.
5379            ///
5380            /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
5381            #[inline]
5382            fn wrapping_to_fixed<F: Fixed>(self) -> F {
5383                FromFixed::wrapping_from_fixed(self)
5384            }
5385
5386            /// Converts a fixed-point number.
5387            ///
5388            /// Returns a [tuple] of the value and a [`bool`]
5389            /// indicating whether an overflow has occurred. On
5390            /// overflow, the wrapped value is returned.
5391            ///
5392            /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
5393            #[inline]
5394            fn overflowing_to_fixed<F: Fixed>(self) -> (F, bool) {
5395                FromFixed::overflowing_from_fixed(self)
5396            }
5397
5398            /// Converts a fixed-point number, panicking if it does not fit.
5399            ///
5400            /// Any extra fractional bits are discarded, which rounds towards &minus;∞.
5401            ///
5402            /// # Panics
5403            ///
5404            /// Panics if the value does not fit, even when debug
5405            /// assertions are not enabled.
5406            #[inline]
5407            fn strict_to_fixed<F: Fixed>(self) -> F {
5408                FromFixed::strict_from_fixed(self)
5409            }
5410        }
5411
5412        if_signed! {
5413            $Signedness;
5414            impl<Frac: $LeEqU> FixedSigned for $Fixed<Frac> {
5415                const TRY_NEG_ONE: Option<Self> = Self::TRY_NEG_ONE;
5416                trait_delegate! { fn signed_bits(self) -> u32 }
5417                trait_delegate! { fn is_positive(self) -> bool }
5418                trait_delegate! { fn is_negative(self) -> bool }
5419                trait_delegate! { fn abs(self) -> Self }
5420                trait_delegate! { fn unsigned_abs(self) -> Self::Unsigned }
5421                trait_delegate! { fn unsigned_dist(self, other: Self) -> Self::Unsigned }
5422                trait_delegate! { fn signum(self) -> Self }
5423                trait_delegate! { fn add_unsigned(self, rhs: Self::Unsigned) -> Self }
5424                trait_delegate! { fn sub_unsigned(self, rhs: Self::Unsigned) -> Self }
5425                trait_delegate! { fn checked_abs(self) -> Option<Self> }
5426                trait_delegate! { fn checked_signum(self) -> Option<Self> }
5427                trait_delegate! {
5428                    fn checked_add_unsigned(self, rhs: Self::Unsigned) -> Option<Self>
5429                }
5430                trait_delegate! {
5431                    fn checked_sub_unsigned(self, rhs: Self::Unsigned) -> Option<Self>
5432                }
5433                trait_delegate! { fn saturating_abs(self) -> Self }
5434                trait_delegate! { fn saturating_signum(self) -> Self }
5435                trait_delegate! { fn saturating_add_unsigned(self, rhs: Self::Unsigned) -> Self }
5436                trait_delegate! { fn saturating_sub_unsigned(self, rhs: Self::Unsigned) -> Self }
5437                trait_delegate! { fn wrapping_abs(self) -> Self }
5438                trait_delegate! { fn wrapping_signum(self) -> Self }
5439                trait_delegate! { fn wrapping_add_unsigned(self, rhs: Self::Unsigned) -> Self }
5440                trait_delegate! { fn wrapping_sub_unsigned(self, rhs: Self::Unsigned) -> Self }
5441                trait_delegate! { fn strict_abs(self) -> Self }
5442                trait_delegate! { fn strict_signum(self) -> Self }
5443                trait_delegate! { fn strict_add_unsigned(self, rhs: Self::Unsigned) -> Self }
5444                trait_delegate! { fn strict_sub_unsigned(self, rhs: Self::Unsigned) -> Self }
5445                trait_delegate! { fn overflowing_abs(self) -> (Self, bool) }
5446                trait_delegate! { fn overflowing_signum(self) -> (Self, bool) }
5447                trait_delegate! {
5448                    fn overflowing_add_unsigned(self, rhs: Self::Unsigned) -> (Self, bool)
5449                }
5450                trait_delegate! {
5451                    fn overflowing_sub_unsigned(self, rhs: Self::Unsigned) -> (Self, bool)
5452                }
5453            }
5454        }
5455
5456        if_unsigned! {
5457            $Signedness;
5458            impl<Frac: $LeEqU> FixedUnsigned for $Fixed<Frac> {
5459                trait_delegate! { fn significant_bits(self) -> u32 }
5460                trait_delegate! { fn is_power_of_two(self) -> bool }
5461                trait_delegate! { fn highest_one(self) -> Self }
5462                trait_delegate! { fn next_power_of_two(self) -> Self }
5463                trait_delegate! { fn add_signed(self, rhs: Self::Signed) -> Self }
5464                trait_delegate! { fn sub_signed(self, rhs: Self::Signed) -> Self }
5465                trait_delegate! { fn checked_next_power_of_two(self) -> Option<Self> }
5466                trait_delegate! { fn checked_add_signed(self, rhs: Self::Signed) -> Option<Self> }
5467                trait_delegate! { fn checked_sub_signed(self, rhs: Self::Signed) -> Option<Self> }
5468                trait_delegate! { fn saturating_add_signed(self, rhs: Self::Signed) -> Self }
5469                trait_delegate! { fn saturating_sub_signed(self, rhs: Self::Signed) -> Self }
5470                trait_delegate! { fn wrapping_next_power_of_two(self) -> Self }
5471                trait_delegate! { fn wrapping_add_signed(self, rhs: Self::Signed) -> Self }
5472                trait_delegate! { fn wrapping_sub_signed(self, rhs: Self::Signed) -> Self }
5473                trait_delegate! { fn strict_next_power_of_two(self) -> Self }
5474                trait_delegate! { fn strict_add_signed(self, rhs: Self::Signed) -> Self }
5475                trait_delegate! { fn strict_sub_signed(self, rhs: Self::Signed) -> Self }
5476                trait_delegate! {
5477                    fn overflowing_add_signed(self, rhs: Self::Signed) -> (Self, bool)
5478                }
5479                trait_delegate! {
5480                    fn overflowing_sub_signed(self, rhs: Self::Signed) -> (Self, bool)
5481                }
5482            }
5483        }
5484    };
5485}
5486
5487impl_fixed! { FixedI8, FixedI8, FixedU8, LeEqU8, i8, Signed }
5488impl_fixed! { FixedI16, FixedI16, FixedU16, LeEqU16, i16, Signed }
5489impl_fixed! { FixedI32, FixedI32, FixedU32, LeEqU32, i32, Signed }
5490impl_fixed! { FixedI64, FixedI64, FixedU64, LeEqU64, i64, Signed }
5491impl_fixed! { FixedI128, FixedI128, FixedU128, LeEqU128, i128, Signed }
5492impl_fixed! { FixedU8, FixedI8, FixedU8, LeEqU8, u8, Unsigned }
5493impl_fixed! { FixedU16, FixedI16, FixedU16, LeEqU16, u16, Unsigned }
5494impl_fixed! { FixedU32, FixedI32, FixedU32, LeEqU32, u32, Unsigned }
5495impl_fixed! { FixedU64, FixedI64, FixedU64, LeEqU64, u64, Unsigned }
5496impl_fixed! { FixedU128, FixedI128, FixedU128, LeEqU128, u128, Unsigned }