diff options
| author | Trevor Gross <tmgross@umich.edu> | 2024-03-26 04:02:54 -0400 |
|---|---|---|
| committer | Trevor Gross <tmgross@umich.edu> | 2024-04-10 13:50:27 -0400 |
| commit | 143ecc3202e033cf843bc05c06d29cd3e4033497 (patch) | |
| tree | c4c10a6dd90d1c25eced18379ef89d8eb2204b32 /library/std/src/f128/tests.rs | |
| parent | 454de78ea3073a284a7a8a41184789f9afa066a3 (diff) | |
| download | rust-143ecc3202e033cf843bc05c06d29cd3e4033497.tar.gz rust-143ecc3202e033cf843bc05c06d29cd3e4033497.zip | |
Add basic f16 and f128 modules
Create empty modules so `rustdoc` has someplace to link to for these types.
Diffstat (limited to 'library/std/src/f128/tests.rs')
| -rw-r--r-- | library/std/src/f128/tests.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/library/std/src/f128/tests.rs b/library/std/src/f128/tests.rs new file mode 100644 index 00000000000..b64c7f856a1 --- /dev/null +++ b/library/std/src/f128/tests.rs @@ -0,0 +1,40 @@ +#![allow(dead_code)] // FIXME(f16_f128): remove once constants are used + +/// Smallest number +const TINY_BITS: u128 = 0x1; +/// Next smallest number +const TINY_UP_BITS: u128 = 0x2; +/// Exponent = 0b11...10, Sifnificand 0b1111..10. Min val > 0 +const MAX_DOWN_BITS: u128 = 0x7ffeffffffffffffffffffffffffffff; +/// Zeroed exponent, full significant +const LARGEST_SUBNORMAL_BITS: u128 = 0x0000ffffffffffffffffffffffffffff; +/// Exponent = 0b1, zeroed significand +const SMALLEST_NORMAL_BITS: u128 = 0x00010000000000000000000000000000; +/// First pattern over the mantissa +const NAN_MASK1: u128 = 0x0000aaaaaaaaaaaaaaaaaaaaaaaaaaaa; +/// Second pattern over the mantissa +const NAN_MASK2: u128 = 0x00005555555555555555555555555555; + +/// Compare by value +#[allow(unused_macros)] +macro_rules! assert_f128_eq { + ($a:expr, $b:expr) => { + let (l, r): (&f128, &f128) = (&$a, &$b); + assert_eq!(*l, *r, "\na: {:#0130x}\nb: {:#0130x}", l.to_bits(), r.to_bits()) + }; +} + +/// Compare by representation +#[allow(unused_macros)] +macro_rules! assert_f128_biteq { + ($a:expr, $b:expr) => { + let (l, r): (&f128, &f128) = (&$a, &$b); + let lb = l.to_bits(); + let rb = r.to_bits(); + assert_eq!( + lb, rb, + "float {:?} is not bitequal to {:?}.\na: {:#0130x}\nb: {:#0130x}", + *l, *r, lb, rb + ); + }; +} |
