substrate_fixed/
lib.rs

1// Copyright © 2018–2019 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/*!
17# Fixed-point numbers
18
19The [*fixed* crate] provides fixed-point numbers.
20
21  * [`FixedI8`] and [`FixedU8`] are eight-bit fixed-point numbers.
22  * [`FixedI16`] and [`FixedU16`] are 16-bit fixed-point numbers.
23  * [`FixedI32`] and [`FixedU32`] are 32-bit fixed-point numbers.
24  * [`FixedI64`] and [`FixedU64`] are 64-bit fixed-point numbers.
25  * [`FixedI128`] and [`FixedU128`] are 128-bit fixed-point numbers.
26
27These types can have `Frac` fractional bits, where
280 ≤ `Frac` ≤ <i>n</i> and <i>n</i> is the total number of bits. When
29`Frac` = 0, the fixed-point number behaves like an <i>n</i>-bit
30integer. When `Frac` = <i>n</i>, the value <i>x</i> lies in the range
31−0.5 ≤ <i>x</i> < 0.5 for signed numbers, and in the range
320 ≤ <i>x</i> < 1 for unsigned numbers.
33
34Currently the [*typenum* crate] is used for the fractional bit count
35`Frac`; it is planned to move to [const generics] when they are
36supported by the Rust compiler.
37
38The main features are
39
40  * Representation of fixed-point numbers up to 128 bits wide.
41  * Conversions between fixed-point numbers and numeric primitives.
42  * Comparisons between fixed-point numbers and numeric primitives.
43  * Parsing from strings in decimal, binary, octal and hexadecimal.
44  * Display as decimal, binary, octal and hexadecimal.
45  * Arithmetic and logic operations.
46
47This crate does *not* provide general analytic functions.
48
49  * No algebraic functions are provided, for example no `sqrt` or
50    `pow`.
51  * No trigonometric functions are provided, for example no `sin` or
52    `cos`.
53  * No other transcendental functions are provided, for example no
54    `log` or `exp`.
55
56These functions are not provided because different implementations can
57have different trade-offs, for example trading some correctness for
58speed. Implementations can be provided in other crates.
59
60  * The [*fixed-sqrt* crate] provides the square root operation.
61
62The conversions supported cover the following cases.
63
64  * Infallible lossless conversions between fixed-point numbers and
65    numeric primitives are provided using [`From`] and [`Into`]. These
66    never fail (infallible) and do not lose any bits (lossless).
67  * Infallible lossy conversions between fixed-point numbers and
68    numeric primitives are provided using the [`LossyFrom`] and
69    [`LossyInto`] traits. The source can have more fractional bits
70    than the destination.
71  * Checked conversions between fixed-point numbers and numeric
72    primitives are provided using the [`FromFixed`] and [`ToFixed`]
73    traits, or using the [`from_num`] and [`to_num`] methods and
74    [their checked versions][`checked_from_num`].
75  * Fixed-point numbers can be parsed from decimal strings using
76    [`FromStr`], and from binary, octal and hexadecimal strings using
77    the [`from_str_binary`], [`from_str_octal`] and [`from_str_hex`]
78    methods. The result is rounded to the nearest, with ties rounded
79    to even.
80  * Fixed-point numbers can be converted to strings using [`Display`],
81    [`Binary`], [`Octal`], [`LowerHex`] and [`UpperHex`]. The output
82    is rounded to the nearest, with ties rounded to even.
83
84## Quick examples
85
86```rust
87use substrate_fixed::types::I20F12;
88
89// 19/3 = 6 1/3
90let six_and_third = I20F12::from_num(19) / 3;
91// four decimal digits for 12 binary digits
92assert_eq!(six_and_third.to_string(), "6.3333");
93// find the ceil and convert to i32
94assert_eq!(six_and_third.ceil().to_num::<i32>(), 7);
95// we can also compare directly to integers
96assert_eq!(six_and_third.ceil(), 7);
97```
98
99The type [`I20F12`] is a 32-bit fixed-point signed number with 20
100integer bits and 12 fractional bits. It is an alias to
101<code>[FixedI32][`FixedI32`]&lt;[U12][`U12`]&gt;</code>. The unsigned
102counterpart would be [`U20F12`]. Aliases are provided for all
103combinations of integer and fractional bits adding up to a total of
104eight, 16, 32, 64 or 128 bits.
105
106```rust
107use substrate_fixed::types::{I4F4, I4F12};
108
109// −8 ≤ I4F4 < 8 with steps of 1/16 (~0.06)
110let a = I4F4::from_num(1);
111// multiplication and division by integers are possible
112let ans1 = a / 5 * 17;
113// 1 / 5 × 17 = 3 2/5 (3.4), but we get 3 3/16 (~3.2)
114assert_eq!(ans1, I4F4::from_bits((3 << 4) + 3));
115assert_eq!(ans1.to_string(), "3.2");
116
117// −8 ≤ I4F12 < 8 with steps of 1/4096 (~0.0002)
118let wider_a = I4F12::from(a);
119let wider_ans = wider_a / 5 * 17;
120let ans2 = I4F4::from_num(wider_ans);
121// now the answer is the much closer 3 6/16 (~3.4)
122assert_eq!(ans2, I4F4::from_bits((3 << 4) + 6));
123assert_eq!(ans2.to_string(), "3.4");
124```
125
126The second example shows some precision and conversion issues. The low
127precision of `a` means that `a / 5` is 3⁄16 instead of 1⁄5, leading to
128an inaccurate result `ans1` = 3 3⁄16 (~3.2). With a higher precision,
129we get `wider_a / 5` equal to 819⁄4096, leading to a more accurate
130intermediate result `wider_ans` = 3 1635⁄4096. When we convert back to
131four fractional bits, we get `ans2` = 3 6⁄16 (~3.4).
132
133Note that we can convert from [`I4F4`] to [`I4F12`] using [`From`], as
134the target type has the same number of integer bits and a larger
135number of fractional bits. Converting from [`I4F12`] to [`I4F4`]
136cannot use [`From`] as we have less fractional bits, so we use
137[`from_num`] instead.
138
139## Using the *fixed* crate
140
141The *fixed* crate is available on [crates.io][*fixed* crate]. To use
142it in your crate, add it as a dependency inside [*Cargo.toml*]:
143
144```toml
145[dependencies]
146fixed = "0.5.4"
147```
148
149The *fixed* crate requires rustc version 1.39.0 or later.
150
151## Optional features
152
153The *fixed* crate has four optional feature:
154
155 1. `az`, disabled by default. This implements the cast traits
156    provided by the [*az* crate].
157 2. `f16`, disabled by default. This provides conversion to/from
158    [`f16`] and [`bf16`]. This features requires the [*half* crate].
159 3. `serde`, disabled by default. This provides serialization support
160    for the fixed-point types. This feature requires the
161    [*serde* crate].
162 4. `std`, disabled by default. This is for features that are not
163    possible under `no_std`: currently the implementation of the
164    [`Error`] trait for [`ParseFixedError`].
165
166To enable features, you can add the dependency like this to
167[*Cargo.toml*]:
168
169```toml
170[dependencies.fixed]
171version = "0.5.4"
172features = ["f16", "serde"]
173```
174
175## License
176
177This crate is free software: you can redistribute it and/or modify it
178under the terms of either
179
180  * the [Apache License, Version 2.0][LICENSE-APACHE] or
181  * the [MIT License][LICENSE-MIT]
182
183at your option.
184
185### Contribution
186
187Unless you explicitly state otherwise, any contribution intentionally
188submitted for inclusion in the work by you, as defined in the Apache
189License, Version 2.0, shall be dual licensed as above, without any
190additional terms or conditions.
191
192[*Cargo.toml*]: https://doc.rust-lang.org/cargo/guide/dependencies.html
193[*az* crate]: https://crates.io/crates/az
194[*fixed* crate]: https://crates.io/crates/fixed
195[*fixed-sqrt* crate]: https://crates.io/crates/fixed-sqrt
196[*half* crate]: https://crates.io/crates/half
197[*serde* crate]: https://crates.io/crates/serde
198[*typenum* crate]: https://crates.io/crates/typenum
199[LICENSE-APACHE]: https://www.apache.org/licenses/LICENSE-2.0
200[LICENSE-MIT]: https://opensource.org/licenses/MIT
201[`Binary`]: https://doc.rust-lang.org/nightly/core/fmt/trait.Binary.html
202[`Display`]: https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html
203[`Error`]: https://doc.rust-lang.org/nightly/std/error/trait.Error.html
204[`FixedI128`]: struct.FixedI128.html
205[`FixedI16`]: struct.FixedI16.html
206[`FixedI32`]: struct.FixedI32.html
207[`FixedI64`]: struct.FixedI64.html
208[`FixedI8`]: struct.FixedI8.html
209[`FixedU128`]: struct.FixedU128.html
210[`FixedU16`]: struct.FixedU16.html
211[`FixedU32`]: struct.FixedU32.html
212[`FixedU64`]: struct.FixedU64.html
213[`FixedU8`]: struct.FixedU8.html
214[`FromFixed`]: traits/trait.FromFixed.html
215[`FromStr`]: https://doc.rust-lang.org/nightly/core/str/trait.FromStr.html
216[`From`]: https://doc.rust-lang.org/nightly/core/convert/trait.From.html
217[`I20F12`]: types/type.I20F12.html
218[`I4F12`]: types/type.I4F12.html
219[`I4F4`]: types/type.I4F4.html
220[`Into`]: https://doc.rust-lang.org/nightly/core/convert/trait.Into.html
221[`LossyFrom`]: traits/trait.LossyFrom.html
222[`LossyInto`]: traits/trait.LossyInto.html
223[`LowerHex`]: https://doc.rust-lang.org/nightly/core/fmt/trait.LowerHex.html
224[`Octal`]: https://doc.rust-lang.org/nightly/core/fmt/trait.Octal.html
225[`ParseFixedError`]: struct.ParseFixedError.html
226[`ToFixed`]: traits/trait.ToFixed.html
227[`U12`]: types/extra/type.U12.html
228[`U20F12`]: types/type.U20F12.html
229[`UpperHex`]: https://doc.rust-lang.org/nightly/core/fmt/trait.UpperHex.html
230[`bf16`]: https://docs.rs/half/^1/half/struct.bf16.html
231[`checked_from_num`]: struct.FixedI32.html#method.checked_from_num
232[`f16`]: https://docs.rs/half/^1/half/struct.f16.html
233[`from_num`]: struct.FixedI32.html#method.from_num
234[`from_str_binary`]: struct.FixedI32.html#method.from_str_binary
235[`from_str_hex`]: struct.FixedI32.html#method.from_str_hex
236[`from_str_octal`]: struct.FixedI32.html#method.from_str_octal
237[`to_num`]: struct.FixedI32.html#method.to_num
238[const generics]: https://github.com/rust-lang/rust/issues/44580
239*/
240#![cfg_attr(not(feature = "std"), no_std)]
241#![warn(missing_docs)]
242#![doc(html_root_url = "https://docs.rs/fixed/0.5.4")]
243#![doc(test(attr(deny(warnings))))]
244#![cfg_attr(feature = "fail-on-warnings", deny(warnings))]
245#![allow(clippy::type_repetition_in_bounds)]
246
247#[cfg(all(not(feature = "std"), test))]
248extern crate std;
249
250#[macro_use]
251mod macros;
252
253mod arith;
254#[cfg(feature = "az")]
255mod cast;
256mod cmp;
257pub mod consts;
258mod convert;
259mod display;
260mod float_helper;
261mod from_str;
262mod helpers;
263mod int_helper;
264#[cfg(feature = "serde")]
265mod serdeize;
266pub mod traits;
267pub mod transcendental;
268pub mod types;
269mod wide_div;
270mod wrapping;
271
272use crate::{
273    arith::MulDivOverflow,
274    from_str::FromStrRadix,
275    traits::{FromFixed, ToFixed},
276    types::extra::{LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
277};
278pub use crate::{from_str::ParseFixedError, wrapping::Wrapping};
279use core::{
280    cmp::Ordering,
281    hash::{Hash, Hasher},
282    marker::PhantomData,
283    mem,
284};
285
286/// A prelude for users of the *fixed* crate.
287///
288/// This prelude is similar to the [standard library’s
289/// prelude][prelude] in that you’ll almost always want to import its
290/// entire contents, but unlike the standard library’s prelude you’ll
291/// have to do so manually:
292///
293/// ```
294/// # #[allow(unused_imports)]
295/// use substrate_fixed::prelude::*;
296/// ```
297///
298/// The prelude may grow over time as additional items see ubiquitous use.
299///
300/// [prelude]: https://doc.rust-lang.org/nightly/std/prelude/index.html
301pub mod prelude {
302    pub use crate::traits::{FromFixed, ToFixed};
303}
304
305#[macro_use]
306mod macros_from_to;
307#[macro_use]
308mod macros_round;
309#[macro_use]
310mod macros_no_frac;
311#[macro_use]
312mod macros_frac;
313
314use codec::{Decode, Encode, DecodeWithMemTracking, MaxEncodedLen};
315macro_rules! fixed {
316    (
317        $description:expr,
318        $Fixed:ident($Inner:ty, $LeEqU:tt, $s_nbits:expr, $s_nbits_m4:expr),
319        $nbytes:expr, $bytes_val:expr, $be_bytes:expr, $le_bytes:expr,
320        $UInner:ty, $Signedness:tt
321    ) => {
322        fixed! {
323            $description,
324            $Fixed[stringify!($Fixed)]($Inner[stringify!($Inner)], $LeEqU, $s_nbits, $s_nbits_m4),
325            $nbytes, $bytes_val, $be_bytes, $le_bytes,
326            $UInner, $Signedness
327        }
328    };
329    (
330        $description:expr,
331        $Fixed:ident[$s_fixed:expr](
332            $Inner:ty[$s_inner:expr], $LeEqU:tt, $s_nbits:expr, $s_nbits_m4:expr
333        ),
334        $nbytes:expr, $bytes_val:expr, $be_bytes:expr, $le_bytes:expr,
335        $UInner:ty, $Signedness:tt
336    ) => {
337        comment! {
338            $description,
339            " number with `Frac` fractional bits.
340
341Currently `Frac` is an [`Unsigned`] as provided by the
342[typenum crate]; it is planned to move to [const generics] when they
343are implemented by the Rust compiler.
344
345# Examples
346
347```rust
348use substrate_fixed::{types::extra::U3, ", $s_fixed, "};
349let eleven = ", $s_fixed, "::<U3>::from_num(11);
350assert_eq!(eleven, ", $s_fixed, "::<U3>::from_bits(11 << 3));
351assert_eq!(eleven, 11);
352assert_eq!(eleven.to_string(), \"11\");
353let two_point_75 = eleven / 4;
354assert_eq!(two_point_75, ", $s_fixed, "::<U3>::from_bits(11 << 1));
355assert_eq!(two_point_75, 2.75);
356assert_eq!(two_point_75.to_string(), \"2.8\");
357```
358
359[`Unsigned`]: https://docs.rs/typenum/^1.3/typenum/marker_traits/trait.Unsigned.html
360[const generics]: https://github.com/rust-lang/rust/issues/44580
361[typenum crate]: https://crates.io/crates/typenum
362";
363            #[repr(transparent)]
364            #[derive(Encode, Decode, DecodeWithMemTracking, scale_info::TypeInfo, MaxEncodedLen)]
365            pub struct $Fixed<Frac> {
366                bits: $Inner,
367                phantom: PhantomData<Frac>,
368            }
369        }
370
371        impl<Frac> Clone for $Fixed<Frac> {
372            #[inline]
373            fn clone(&self) -> $Fixed<Frac> {
374                $Fixed {
375                    bits: self.bits,
376                    phantom: PhantomData,
377                }
378            }
379        }
380
381        impl<Frac> Copy for $Fixed<Frac> {}
382
383        impl<Frac> Default for $Fixed<Frac> {
384            #[inline]
385            fn default() -> Self {
386                $Fixed {
387                    bits: Default::default(),
388                    phantom: PhantomData,
389                }
390            }
391        }
392
393        impl<Frac> Hash for $Fixed<Frac> {
394            #[inline]
395            fn hash<H: Hasher>(&self, state: &mut H) {
396                self.bits.hash(state);
397            }
398        }
399
400        // inherent methods that do not require Frac bounds, some of which can thus be const
401        fixed_no_frac! {
402            $description,
403            $Fixed[$s_fixed]($Inner[$s_inner], $s_nbits),
404            $nbytes, $bytes_val, $be_bytes, $le_bytes,
405            $UInner, $Signedness
406        }
407        // inherent methods that require Frac bounds, and cannot be const
408        fixed_frac! {
409            $description,
410            $Fixed[$s_fixed]($Inner[$s_inner], $LeEqU, $s_nbits, $s_nbits_m4),
411            $UInner, $Signedness
412        }
413    };
414}
415
416fixed! {
417    "An eight-bit fixed-point unsigned",
418    FixedU8(u8, LeEqU8, "8", "4"),
419    1, "0x12", "[0x12]", "[0x12]",
420    u8, Unsigned
421}
422fixed! {
423    "A 16-bit fixed-point unsigned",
424    FixedU16(u16, LeEqU16, "16", "12"),
425    2, "0x1234", "[0x12, 0x34]", "[0x34, 0x12]",
426    u16, Unsigned
427}
428fixed! {
429    "A 32-bit fixed-point unsigned",
430    FixedU32(u32, LeEqU32, "32", "28"),
431    4, "0x1234_5678", "[0x12, 0x34, 0x56, 0x78]", "[0x78, 0x56, 0x34, 0x12]",
432    u32, Unsigned
433}
434fixed! {
435    "A 64-bit fixed-point unsigned",
436    FixedU64(u64, LeEqU64, "64", "60"),
437    8, "0x1234_5678_9ABC_DEF0",
438    "[0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0]",
439    "[0xF0, 0xDE, 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12]",
440    u64, Unsigned
441}
442fixed! {
443    "A 128-bit fixed-point unsigned",
444    FixedU128(u128, LeEqU128, "128", "124"),
445    16, "0x1234_5678_9ABC_DEF0_1234_5678_9ABC_DEF0",
446    "[0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, \
447     0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0]",
448    "[0xF0, 0xDE, 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, \
449     0xF0, 0xDE, 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12]",
450    u128, Unsigned
451}
452fixed! {
453    "An eight-bit fixed-point signed",
454    FixedI8(i8, LeEqU8, "8", "4"),
455    1, "0x12", "[0x12]", "[0x12]",
456    u8, Signed
457}
458fixed! {
459    "A 16-bit fixed-point signed",
460    FixedI16(i16, LeEqU16, "16", "12"),
461    2, "0x1234", "[0x12, 0x34]", "[0x34, 0x12]",
462    u16, Signed
463}
464fixed! {
465    "A 32-bit fixed-point signed",
466    FixedI32(i32, LeEqU32, "32", "28"),
467    4, "0x1234_5678", "[0x12, 0x34, 0x56, 0x78]", "[0x78, 0x56, 0x34, 0x12]",
468    u32, Signed
469}
470fixed! {
471    "A 64-bit fixed-point signed",
472    FixedI64(i64, LeEqU64, "64", "60"),
473    8, "0x1234_5678_9ABC_DEF0",
474    "[0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0]",
475    "[0xF0, 0xDE, 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12]",
476    u64, Signed
477}
478fixed! {
479    "A 128-bit fixed-point signed",
480    FixedI128(i128, LeEqU128, "128", "124"),
481    16, "0x1234_5678_9ABC_DEF0_1234_5678_9ABC_DEF0",
482    "[0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, \
483     0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0]",
484    "[0xF0, 0xDE, 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, \
485     0xF0, 0xDE, 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12]",
486    u128, Signed
487}
488
489#[cfg(test)]
490#[macro_use]
491extern crate approx;
492
493#[cfg(test)]
494#[allow(clippy::cognitive_complexity)]
495mod tests {
496    use crate::types::{I0F32, I16F16, I1F31, U0F32, U16F16, I64F64};
497    use scale_info::TypeInfo;
498
499    #[test]
500    fn scale_info_works() {
501        // suffices if this test compiles
502        I64F64::type_info();
503    }
504
505    #[test]
506    fn rounding_signed() {
507        // -0.5
508        let f = I0F32::from_bits(-1 << 31);
509        assert_eq!(f.to_num::<i32>(), -1);
510        assert_eq!(f.round_to_zero(), 0);
511        assert_eq!(f.overflowing_ceil(), (I0F32::from_num(0), false));
512        assert_eq!(f.overflowing_floor(), (I0F32::from_num(0), true));
513        assert_eq!(f.overflowing_round(), (I0F32::from_num(0), true));
514        assert_eq!(
515            f.overflowing_round_ties_to_even(),
516            (I0F32::from_num(0), false)
517        );
518
519        // -0.5 + Δ
520        let f = I0F32::from_bits((-1 << 31) + 1);
521        assert_eq!(f.to_num::<i32>(), -1);
522        assert_eq!(f.round_to_zero(), 0);
523        assert_eq!(f.overflowing_ceil(), (I0F32::from_num(0), false));
524        assert_eq!(f.overflowing_floor(), (I0F32::from_num(0), true));
525        assert_eq!(f.overflowing_round(), (I0F32::from_num(0), false));
526        assert_eq!(
527            f.overflowing_round_ties_to_even(),
528            (I0F32::from_num(0), false)
529        );
530
531        // 0
532        let f = I0F32::from_bits(0);
533        assert_eq!(f.to_num::<i32>(), 0);
534        assert_eq!(f.round_to_zero(), 0);
535        assert_eq!(f.overflowing_ceil(), (I0F32::from_num(0), false));
536        assert_eq!(f.overflowing_floor(), (I0F32::from_num(0), false));
537        assert_eq!(f.overflowing_round(), (I0F32::from_num(0), false));
538        assert_eq!(
539            f.overflowing_round_ties_to_even(),
540            (I0F32::from_num(0), false)
541        );
542
543        // 0.5 - Δ
544        let f = I0F32::from_bits((1 << 30) - 1 + (1 << 30));
545        assert_eq!(f.to_num::<i32>(), 0);
546        assert_eq!(f.round_to_zero(), 0);
547        assert_eq!(f.overflowing_ceil(), (I0F32::from_num(0), true));
548        assert_eq!(f.overflowing_floor(), (I0F32::from_num(0), false));
549        assert_eq!(f.overflowing_round(), (I0F32::from_num(0), false));
550        assert_eq!(
551            f.overflowing_round_ties_to_even(),
552            (I0F32::from_num(0), false)
553        );
554
555        // -1
556        let f = I1F31::from_bits((-1) << 31);
557        assert_eq!(f.to_num::<i32>(), -1);
558        assert_eq!(f.round_to_zero(), -1);
559        assert_eq!(f.overflowing_ceil(), (I1F31::from_num(-1), false));
560        assert_eq!(f.overflowing_floor(), (I1F31::from_num(-1), false));
561        assert_eq!(f.overflowing_round(), (I1F31::from_num(-1), false));
562        assert_eq!(
563            f.overflowing_round_ties_to_even(),
564            (I1F31::from_num(-1), false)
565        );
566
567        // -0.5 - Δ
568        let f = I1F31::from_bits(((-1) << 30) - 1);
569        assert_eq!(f.to_num::<i32>(), -1);
570        assert_eq!(f.round_to_zero(), 0);
571        assert_eq!(f.overflowing_ceil(), (I1F31::from_num(0), false));
572        assert_eq!(f.overflowing_floor(), (I1F31::from_num(-1), false));
573        assert_eq!(f.overflowing_round(), (I1F31::from_num(-1), false));
574        assert_eq!(
575            f.overflowing_round_ties_to_even(),
576            (I1F31::from_num(-1), false)
577        );
578
579        // -0.5
580        let f = I1F31::from_bits((-1) << 30);
581        assert_eq!(f.to_num::<i32>(), -1);
582        assert_eq!(f.round_to_zero(), 0);
583        assert_eq!(f.overflowing_ceil(), (I1F31::from_num(0), false));
584        assert_eq!(f.overflowing_floor(), (I1F31::from_num(-1), false));
585        assert_eq!(f.overflowing_round(), (I1F31::from_num(-1), false));
586        assert_eq!(
587            f.overflowing_round_ties_to_even(),
588            (I1F31::from_num(0), false)
589        );
590
591        // -0.5 + Δ
592        let f = I1F31::from_bits(((-1) << 30) + 1);
593        assert_eq!(f.to_num::<i32>(), -1);
594        assert_eq!(f.round_to_zero(), 0);
595        assert_eq!(f.overflowing_ceil(), (I1F31::from_num(0), false));
596        assert_eq!(f.overflowing_floor(), (I1F31::from_num(-1), false));
597        assert_eq!(f.overflowing_round(), (I1F31::from_num(0), false));
598        assert_eq!(
599            f.overflowing_round_ties_to_even(),
600            (I1F31::from_num(0), false)
601        );
602
603        // 0.5 - Δ
604        let f = I1F31::from_bits((1 << 30) - 1);
605        assert_eq!(f.to_num::<i32>(), 0);
606        assert_eq!(f.round_to_zero(), 0);
607        assert_eq!(f.overflowing_ceil(), (I1F31::from_num(-1), true));
608        assert_eq!(f.overflowing_floor(), (I1F31::from_num(0), false));
609        assert_eq!(f.overflowing_round(), (I1F31::from_num(0), false));
610        assert_eq!(
611            f.overflowing_round_ties_to_even(),
612            (I1F31::from_num(0), false)
613        );
614
615        // 0.5
616        let f = I1F31::from_bits(1 << 30);
617        assert_eq!(f.to_num::<i32>(), 0);
618        assert_eq!(f.round_to_zero(), 0);
619        assert_eq!(f.overflowing_ceil(), (I1F31::from_num(-1), true));
620        assert_eq!(f.overflowing_floor(), (I1F31::from_num(0), false));
621        assert_eq!(f.overflowing_round(), (I1F31::from_num(-1), true));
622        assert_eq!(
623            f.overflowing_round_ties_to_even(),
624            (I1F31::from_num(0), false)
625        );
626
627        // 0
628        let f = I1F31::from_bits(0);
629        assert_eq!(f.to_num::<i32>(), 0);
630        assert_eq!(f.round_to_zero(), 0);
631        assert_eq!(f.overflowing_ceil(), (I1F31::from_num(0), false));
632        assert_eq!(f.overflowing_floor(), (I1F31::from_num(0), false));
633        assert_eq!(f.overflowing_round(), (I1F31::from_num(0), false));
634        assert_eq!(
635            f.overflowing_round_ties_to_even(),
636            (I1F31::from_num(0), false)
637        );
638
639        // 0.5 + Δ
640        let f = I1F31::from_bits((1 << 30) + 1);
641        assert_eq!(f.to_num::<i32>(), 0);
642        assert_eq!(f.round_to_zero(), 0);
643        assert_eq!(f.overflowing_ceil(), (I1F31::from_num(-1), true));
644        assert_eq!(f.overflowing_floor(), (I1F31::from_num(0), false));
645        assert_eq!(f.overflowing_round(), (I1F31::from_num(-1), true));
646        assert_eq!(
647            f.overflowing_round_ties_to_even(),
648            (I1F31::from_num(-1), true)
649        );
650
651        // -3.5 - Δ
652        let f = I16F16::from_bits(((-7) << 15) - 1);
653        assert_eq!(f.to_num::<i32>(), -4);
654        assert_eq!(f.round_to_zero(), -3);
655        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(-3), false));
656        assert_eq!(f.overflowing_floor(), (I16F16::from_num(-4), false));
657        assert_eq!(f.overflowing_round(), (I16F16::from_num(-4), false));
658        assert_eq!(
659            f.overflowing_round_ties_to_even(),
660            (I16F16::from_num(-4), false)
661        );
662
663        // -3.5
664        let f = I16F16::from_bits((-7) << 15);
665        assert_eq!(f.to_num::<i32>(), -4);
666        assert_eq!(f.round_to_zero(), -3);
667        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(-3), false));
668        assert_eq!(f.overflowing_floor(), (I16F16::from_num(-4), false));
669        assert_eq!(f.overflowing_round(), (I16F16::from_num(-4), false));
670        assert_eq!(
671            f.overflowing_round_ties_to_even(),
672            (I16F16::from_num(-4), false)
673        );
674
675        // -3.5 + Δ
676        let f = I16F16::from_bits(((-7) << 15) + 1);
677        assert_eq!(f.to_num::<i32>(), -4);
678        assert_eq!(f.round_to_zero(), -3);
679        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(-3), false));
680        assert_eq!(f.overflowing_floor(), (I16F16::from_num(-4), false));
681        assert_eq!(f.overflowing_round(), (I16F16::from_num(-3), false));
682        assert_eq!(
683            f.overflowing_round_ties_to_even(),
684            (I16F16::from_num(-3), false)
685        );
686
687        // -2.5 - Δ
688        let f = I16F16::from_bits(((-5) << 15) - 1);
689        assert_eq!(f.to_num::<i32>(), -3);
690        assert_eq!(f.round_to_zero(), -2);
691        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(-2), false));
692        assert_eq!(f.overflowing_floor(), (I16F16::from_num(-3), false));
693        assert_eq!(f.overflowing_round(), (I16F16::from_num(-3), false));
694        assert_eq!(
695            f.overflowing_round_ties_to_even(),
696            (I16F16::from_num(-3), false)
697        );
698
699        // -2.5
700        let f = I16F16::from_bits((-5) << 15);
701        assert_eq!(f.to_num::<i32>(), -3);
702        assert_eq!(f.round_to_zero(), -2);
703        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(-2), false));
704        assert_eq!(f.overflowing_floor(), (I16F16::from_num(-3), false));
705        assert_eq!(f.overflowing_round(), (I16F16::from_num(-3), false));
706        assert_eq!(
707            f.overflowing_round_ties_to_even(),
708            (I16F16::from_num(-2), false)
709        );
710
711        // -2.5 + Δ
712        let f = I16F16::from_bits(((-5) << 15) + 1);
713        assert_eq!(f.to_num::<i32>(), -3);
714        assert_eq!(f.round_to_zero(), -2);
715        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(-2), false));
716        assert_eq!(f.overflowing_floor(), (I16F16::from_num(-3), false));
717        assert_eq!(f.overflowing_round(), (I16F16::from_num(-2), false));
718        assert_eq!(
719            f.overflowing_round_ties_to_even(),
720            (I16F16::from_num(-2), false)
721        );
722
723        // -1
724        let f = I16F16::from_bits((-1) << 16);
725        assert_eq!(f.to_num::<i32>(), -1);
726        assert_eq!(f.round_to_zero(), -1);
727        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(-1), false));
728        assert_eq!(f.overflowing_floor(), (I16F16::from_num(-1), false));
729        assert_eq!(f.overflowing_round(), (I16F16::from_num(-1), false));
730        assert_eq!(
731            f.overflowing_round_ties_to_even(),
732            (I16F16::from_num(-1), false)
733        );
734
735        // -0.5 - Δ
736        let f = I16F16::from_bits(((-1) << 15) - 1);
737        assert_eq!(f.to_num::<i32>(), -1);
738        assert_eq!(f.round_to_zero(), 0);
739        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(0), false));
740        assert_eq!(f.overflowing_floor(), (I16F16::from_num(-1), false));
741        assert_eq!(f.overflowing_round(), (I16F16::from_num(-1), false));
742        assert_eq!(
743            f.overflowing_round_ties_to_even(),
744            (I16F16::from_num(-1), false)
745        );
746
747        // -0.5
748        let f = I16F16::from_bits((-1) << 15);
749        assert_eq!(f.to_num::<i32>(), -1);
750        assert_eq!(f.round_to_zero(), 0);
751        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(0), false));
752        assert_eq!(f.overflowing_floor(), (I16F16::from_num(-1), false));
753        assert_eq!(f.overflowing_round(), (I16F16::from_num(-1), false));
754        assert_eq!(
755            f.overflowing_round_ties_to_even(),
756            (I16F16::from_num(0), false)
757        );
758
759        // -0.5 + Δ
760        let f = I16F16::from_bits(((-1) << 15) + 1);
761        assert_eq!(f.to_num::<i32>(), -1);
762        assert_eq!(f.round_to_zero(), 0);
763        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(0), false));
764        assert_eq!(f.overflowing_floor(), (I16F16::from_num(-1), false));
765        assert_eq!(f.overflowing_round(), (I16F16::from_num(0), false));
766        assert_eq!(
767            f.overflowing_round_ties_to_even(),
768            (I16F16::from_num(0), false)
769        );
770
771        // 0
772        let f = I16F16::from_bits(0);
773        assert_eq!(f.to_num::<i32>(), 0);
774        assert_eq!(f.round_to_zero(), 0);
775        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(0), false));
776        assert_eq!(f.overflowing_floor(), (I16F16::from_num(0), false));
777        assert_eq!(f.overflowing_round(), (I16F16::from_num(0), false));
778        assert_eq!(
779            f.overflowing_round_ties_to_even(),
780            (I16F16::from_num(0), false)
781        );
782
783        // 0.5 - Δ
784        let f = I16F16::from_bits((1 << 15) - 1);
785        assert_eq!(f.to_num::<i32>(), 0);
786        assert_eq!(f.round_to_zero(), 0);
787        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(1), false));
788        assert_eq!(f.overflowing_floor(), (I16F16::from_num(0), false));
789        assert_eq!(f.overflowing_round(), (I16F16::from_num(0), false));
790        assert_eq!(
791            f.overflowing_round_ties_to_even(),
792            (I16F16::from_num(0), false)
793        );
794
795        // 0.5
796        let f = I16F16::from_bits(1 << 15);
797        assert_eq!(f.to_num::<i32>(), 0);
798        assert_eq!(f.round_to_zero(), 0);
799        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(1), false));
800        assert_eq!(f.overflowing_floor(), (I16F16::from_num(0), false));
801        assert_eq!(f.overflowing_round(), (I16F16::from_num(1), false));
802        assert_eq!(
803            f.overflowing_round_ties_to_even(),
804            (I16F16::from_num(0), false)
805        );
806
807        // 0.5 + Δ
808        let f = I16F16::from_bits((1 << 15) + 1);
809        assert_eq!(f.to_num::<i32>(), 0);
810        assert_eq!(f.round_to_zero(), 0);
811        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(1), false));
812        assert_eq!(f.overflowing_floor(), (I16F16::from_num(0), false));
813        assert_eq!(f.overflowing_round(), (I16F16::from_num(1), false));
814        assert_eq!(
815            f.overflowing_round_ties_to_even(),
816            (I16F16::from_num(1), false)
817        );
818
819        // 1
820        let f = I16F16::from_bits(1 << 16);
821        assert_eq!(f.to_num::<i32>(), 1);
822        assert_eq!(f.round_to_zero(), 1);
823        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(1), false));
824        assert_eq!(f.overflowing_floor(), (I16F16::from_num(1), false));
825        assert_eq!(f.overflowing_round(), (I16F16::from_num(1), false));
826        assert_eq!(
827            f.overflowing_round_ties_to_even(),
828            (I16F16::from_num(1), false)
829        );
830
831        // 2.5 - Δ
832        let f = I16F16::from_bits((5 << 15) - 1);
833        assert_eq!(f.to_num::<i32>(), 2);
834        assert_eq!(f.round_to_zero(), 2);
835        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(3), false));
836        assert_eq!(f.overflowing_floor(), (I16F16::from_num(2), false));
837        assert_eq!(f.overflowing_round(), (I16F16::from_num(2), false));
838        assert_eq!(
839            f.overflowing_round_ties_to_even(),
840            (I16F16::from_num(2), false)
841        );
842
843        // 2.5
844        let f = I16F16::from_bits(5 << 15);
845        assert_eq!(f.to_num::<i32>(), 2);
846        assert_eq!(f.round_to_zero(), 2);
847        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(3), false));
848        assert_eq!(f.overflowing_floor(), (I16F16::from_num(2), false));
849        assert_eq!(f.overflowing_round(), (I16F16::from_num(3), false));
850        assert_eq!(
851            f.overflowing_round_ties_to_even(),
852            (I16F16::from_num(2), false)
853        );
854
855        // 2.5 + Δ
856        let f = I16F16::from_bits((5 << 15) + 1);
857        assert_eq!(f.to_num::<i32>(), 2);
858        assert_eq!(f.round_to_zero(), 2);
859        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(3), false));
860        assert_eq!(f.overflowing_floor(), (I16F16::from_num(2), false));
861        assert_eq!(f.overflowing_round(), (I16F16::from_num(3), false));
862        assert_eq!(
863            f.overflowing_round_ties_to_even(),
864            (I16F16::from_num(3), false)
865        );
866
867        // 3.5 - Δ
868        let f = I16F16::from_bits((7 << 15) - 1);
869        assert_eq!(f.to_num::<i32>(), 3);
870        assert_eq!(f.round_to_zero(), 3);
871        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(4), false));
872        assert_eq!(f.overflowing_floor(), (I16F16::from_num(3), false));
873        assert_eq!(f.overflowing_round(), (I16F16::from_num(3), false));
874        assert_eq!(
875            f.overflowing_round_ties_to_even(),
876            (I16F16::from_num(3), false)
877        );
878
879        // 3.5
880        let f = I16F16::from_bits(7 << 15);
881        assert_eq!(f.to_num::<i32>(), 3);
882        assert_eq!(f.round_to_zero(), 3);
883        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(4), false));
884        assert_eq!(f.overflowing_floor(), (I16F16::from_num(3), false));
885        assert_eq!(f.overflowing_round(), (I16F16::from_num(4), false));
886        assert_eq!(
887            f.overflowing_round_ties_to_even(),
888            (I16F16::from_num(4), false)
889        );
890
891        // 3.5 + Δ
892        let f = I16F16::from_bits((7 << 15) + 1);
893        assert_eq!(f.to_num::<i32>(), 3);
894        assert_eq!(f.round_to_zero(), 3);
895        assert_eq!(f.overflowing_ceil(), (I16F16::from_num(4), false));
896        assert_eq!(f.overflowing_floor(), (I16F16::from_num(3), false));
897        assert_eq!(f.overflowing_round(), (I16F16::from_num(4), false));
898        assert_eq!(
899            f.overflowing_round_ties_to_even(),
900            (I16F16::from_num(4), false)
901        );
902    }
903
904    #[test]
905    fn rounding_unsigned() {
906        // 0
907        let f = U0F32::from_bits(0);
908        assert_eq!(f.to_num::<i32>(), 0);
909        assert_eq!(f.round_to_zero(), 0);
910        assert_eq!(f.overflowing_ceil(), (U0F32::from_num(0), false));
911        assert_eq!(f.overflowing_floor(), (U0F32::from_num(0), false));
912        assert_eq!(f.overflowing_round(), (U0F32::from_num(0), false));
913        assert_eq!(
914            f.overflowing_round_ties_to_even(),
915            (U0F32::from_num(0), false)
916        );
917
918        // 0.5 - Δ
919        let f = U0F32::from_bits((1 << 31) - 1);
920        assert_eq!(f.to_num::<i32>(), 0);
921        assert_eq!(f.round_to_zero(), 0);
922        assert_eq!(f.overflowing_ceil(), (U0F32::from_num(0), true));
923        assert_eq!(f.overflowing_floor(), (U0F32::from_num(0), false));
924        assert_eq!(f.overflowing_round(), (U0F32::from_num(0), false));
925        assert_eq!(
926            f.overflowing_round_ties_to_even(),
927            (U0F32::from_num(0), false)
928        );
929
930        // 0.5
931        let f = U0F32::from_bits(1 << 31);
932        assert_eq!(f.to_num::<i32>(), 0);
933        assert_eq!(f.round_to_zero(), 0);
934        assert_eq!(f.overflowing_ceil(), (U0F32::from_num(0), true));
935        assert_eq!(f.overflowing_floor(), (U0F32::from_num(0), false));
936        assert_eq!(f.overflowing_round(), (U0F32::from_num(0), true));
937        assert_eq!(
938            f.overflowing_round_ties_to_even(),
939            (U0F32::from_num(0), false)
940        );
941
942        // 0.5 + Δ
943        let f = U0F32::from_bits((1 << 31) + 1);
944        assert_eq!(f.to_num::<i32>(), 0);
945        assert_eq!(f.round_to_zero(), 0);
946        assert_eq!(f.overflowing_ceil(), (U0F32::from_num(0), true));
947        assert_eq!(f.overflowing_floor(), (U0F32::from_num(0), false));
948        assert_eq!(f.overflowing_round(), (U0F32::from_num(0), true));
949        assert_eq!(
950            f.overflowing_round_ties_to_even(),
951            (U0F32::from_num(0), true)
952        );
953
954        // 0
955        let f = U16F16::from_bits(0);
956        assert_eq!(f.to_num::<i32>(), 0);
957        assert_eq!(f.round_to_zero(), 0);
958        assert_eq!(f.overflowing_ceil(), (U16F16::from_num(0), false));
959        assert_eq!(f.overflowing_floor(), (U16F16::from_num(0), false));
960        assert_eq!(f.overflowing_round(), (U16F16::from_num(0), false));
961        assert_eq!(
962            f.overflowing_round_ties_to_even(),
963            (U16F16::from_num(0), false)
964        );
965
966        // 0.5 - Δ
967        let f = U16F16::from_bits((1 << 15) - 1);
968        assert_eq!(f.to_num::<i32>(), 0);
969        assert_eq!(f.round_to_zero(), 0);
970        assert_eq!(f.overflowing_ceil(), (U16F16::from_num(1), false));
971        assert_eq!(f.overflowing_floor(), (U16F16::from_num(0), false));
972        assert_eq!(f.overflowing_round(), (U16F16::from_num(0), false));
973        assert_eq!(
974            f.overflowing_round_ties_to_even(),
975            (U16F16::from_num(0), false)
976        );
977
978        // 0.5
979        let f = U16F16::from_bits(1 << 15);
980        assert_eq!(f.to_num::<i32>(), 0);
981        assert_eq!(f.round_to_zero(), 0);
982        assert_eq!(f.overflowing_ceil(), (U16F16::from_num(1), false));
983        assert_eq!(f.overflowing_floor(), (U16F16::from_num(0), false));
984        assert_eq!(f.overflowing_round(), (U16F16::from_num(1), false));
985        assert_eq!(
986            f.overflowing_round_ties_to_even(),
987            (U16F16::from_num(0), false)
988        );
989
990        // 0.5 + Δ
991        let f = U16F16::from_bits((1 << 15) + 1);
992        assert_eq!(f.to_num::<i32>(), 0);
993        assert_eq!(f.round_to_zero(), 0);
994        assert_eq!(f.overflowing_ceil(), (U16F16::from_num(1), false));
995        assert_eq!(f.overflowing_floor(), (U16F16::from_num(0), false));
996        assert_eq!(f.overflowing_round(), (U16F16::from_num(1), false));
997        assert_eq!(
998            f.overflowing_round_ties_to_even(),
999            (U16F16::from_num(1), false)
1000        );
1001
1002        // 1
1003        let f = U16F16::from_bits(1 << 16);
1004        assert_eq!(f.to_num::<i32>(), 1);
1005        assert_eq!(f.round_to_zero(), 1);
1006        assert_eq!(f.overflowing_ceil(), (U16F16::from_num(1), false));
1007        assert_eq!(f.overflowing_floor(), (U16F16::from_num(1), false));
1008        assert_eq!(f.overflowing_round(), (U16F16::from_num(1), false));
1009        assert_eq!(
1010            f.overflowing_round_ties_to_even(),
1011            (U16F16::from_num(1), false)
1012        );
1013
1014        // 2.5 - Δ
1015        let f = U16F16::from_bits((5 << 15) - 1);
1016        assert_eq!(f.to_num::<i32>(), 2);
1017        assert_eq!(f.round_to_zero(), 2);
1018        assert_eq!(f.overflowing_ceil(), (U16F16::from_num(3), false));
1019        assert_eq!(f.overflowing_floor(), (U16F16::from_num(2), false));
1020        assert_eq!(f.overflowing_round(), (U16F16::from_num(2), false));
1021        assert_eq!(
1022            f.overflowing_round_ties_to_even(),
1023            (U16F16::from_num(2), false)
1024        );
1025
1026        // 2.5
1027        let f = U16F16::from_bits(5 << 15);
1028        assert_eq!(f.to_num::<i32>(), 2);
1029        assert_eq!(f.round_to_zero(), 2);
1030        assert_eq!(f.overflowing_ceil(), (U16F16::from_num(3), false));
1031        assert_eq!(f.overflowing_floor(), (U16F16::from_num(2), false));
1032        assert_eq!(f.overflowing_round(), (U16F16::from_num(3), false));
1033        assert_eq!(
1034            f.overflowing_round_ties_to_even(),
1035            (U16F16::from_num(2), false)
1036        );
1037
1038        // 2.5 + Δ
1039        let f = U16F16::from_bits((5 << 15) + 1);
1040        assert_eq!(f.to_num::<i32>(), 2);
1041        assert_eq!(f.round_to_zero(), 2);
1042        assert_eq!(f.overflowing_ceil(), (U16F16::from_num(3), false));
1043        assert_eq!(f.overflowing_floor(), (U16F16::from_num(2), false));
1044        assert_eq!(f.overflowing_round(), (U16F16::from_num(3), false));
1045        assert_eq!(
1046            f.overflowing_round_ties_to_even(),
1047            (U16F16::from_num(3), false)
1048        );
1049
1050        // 3.5 - Δ
1051        let f = U16F16::from_bits((7 << 15) - 1);
1052        assert_eq!(f.to_num::<i32>(), 3);
1053        assert_eq!(f.round_to_zero(), 3);
1054        assert_eq!(f.overflowing_ceil(), (U16F16::from_num(4), false));
1055        assert_eq!(f.overflowing_floor(), (U16F16::from_num(3), false));
1056        assert_eq!(f.overflowing_round(), (U16F16::from_num(3), false));
1057        assert_eq!(
1058            f.overflowing_round_ties_to_even(),
1059            (U16F16::from_num(3), false)
1060        );
1061
1062        // 3.5
1063        let f = U16F16::from_bits(7 << 15);
1064        assert_eq!(f.to_num::<i32>(), 3);
1065        assert_eq!(f.round_to_zero(), 3);
1066        assert_eq!(f.overflowing_ceil(), (U16F16::from_num(4), false));
1067        assert_eq!(f.overflowing_floor(), (U16F16::from_num(3), false));
1068        assert_eq!(f.overflowing_round(), (U16F16::from_num(4), false));
1069        assert_eq!(
1070            f.overflowing_round_ties_to_even(),
1071            (U16F16::from_num(4), false)
1072        );
1073
1074        // 3.5 + Δ
1075        let f = U16F16::from_bits((7 << 15) + 1);
1076        assert_eq!(f.to_num::<i32>(), 3);
1077        assert_eq!(f.round_to_zero(), 3);
1078        assert_eq!(f.overflowing_ceil(), (U16F16::from_num(4), false));
1079        assert_eq!(f.overflowing_floor(), (U16F16::from_num(3), false));
1080        assert_eq!(f.overflowing_round(), (U16F16::from_num(4), false));
1081        assert_eq!(
1082            f.overflowing_round_ties_to_even(),
1083            (U16F16::from_num(4), false)
1084        );
1085    }
1086}