Skip to content

Commit 143ecc3

Browse files
committed
Add basic f16 and f128 modules
Create empty modules so `rustdoc` has someplace to link to for these types.
1 parent 454de78 commit 143ecc3

File tree

8 files changed

+150
-0
lines changed

8 files changed

+150
-0
lines changed

library/core/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ pub mod u8;
347347
#[path = "num/shells/usize.rs"]
348348
pub mod usize;
349349

350+
#[path = "num/f128.rs"]
351+
pub mod f128;
352+
#[path = "num/f16.rs"]
353+
pub mod f16;
350354
#[path = "num/f32.rs"]
351355
pub mod f32;
352356
#[path = "num/f64.rs"]

library/core/src/num/f128.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//! Constants for the `f128` quadruple-precision floating point type.
2+
//!
3+
//! *[See also the `f128` primitive type][f128].*
4+
//!
5+
//! Mathematically significant numbers are provided in the `consts` sub-module.
6+
//!
7+
//! For the constants defined directly in this module
8+
//! (as distinct from those defined in the `consts` sub-module),
9+
//! new code should instead use the associated constants
10+
//! defined directly on the `f128` type.
11+
12+
#![unstable(feature = "f128", issue = "116909")]
13+
14+
/// Basic mathematical constants.
15+
#[unstable(feature = "f128", issue = "116909")]
16+
pub mod consts {}

library/core/src/num/f16.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//! Constants for the `f16` half-precision floating point type.
2+
//!
3+
//! *[See also the `f16` primitive type][f16].*
4+
//!
5+
//! Mathematically significant numbers are provided in the `consts` sub-module.
6+
//!
7+
//! For the constants defined directly in this module
8+
//! (as distinct from those defined in the `consts` sub-module),
9+
//! new code should instead use the associated constants
10+
//! defined directly on the `f16` type.
11+
12+
#![unstable(feature = "f16", issue = "116909")]
13+
14+
/// Basic mathematical constants.
15+
#[unstable(feature = "f16", issue = "116909")]
16+
pub mod consts {}

library/std/src/f128.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! Constants for the `f128` double-precision floating point type.
2+
//!
3+
//! *[See also the `f128` primitive type](primitive@f128).*
4+
//!
5+
//! Mathematically significant numbers are provided in the `consts` sub-module.
6+
7+
#[cfg(test)]
8+
mod tests;
9+
10+
#[unstable(feature = "f128", issue = "116909")]
11+
pub use core::f128::consts;

library/std/src/f128/tests.rs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#![allow(dead_code)] // FIXME(f16_f128): remove once constants are used
2+
3+
/// Smallest number
4+
const TINY_BITS: u128 = 0x1;
5+
/// Next smallest number
6+
const TINY_UP_BITS: u128 = 0x2;
7+
/// Exponent = 0b11...10, Sifnificand 0b1111..10. Min val > 0
8+
const MAX_DOWN_BITS: u128 = 0x7ffeffffffffffffffffffffffffffff;
9+
/// Zeroed exponent, full significant
10+
const LARGEST_SUBNORMAL_BITS: u128 = 0x0000ffffffffffffffffffffffffffff;
11+
/// Exponent = 0b1, zeroed significand
12+
const SMALLEST_NORMAL_BITS: u128 = 0x00010000000000000000000000000000;
13+
/// First pattern over the mantissa
14+
const NAN_MASK1: u128 = 0x0000aaaaaaaaaaaaaaaaaaaaaaaaaaaa;
15+
/// Second pattern over the mantissa
16+
const NAN_MASK2: u128 = 0x00005555555555555555555555555555;
17+
18+
/// Compare by value
19+
#[allow(unused_macros)]
20+
macro_rules! assert_f128_eq {
21+
($a:expr, $b:expr) => {
22+
let (l, r): (&f128, &f128) = (&$a, &$b);
23+
assert_eq!(*l, *r, "\na: {:#0130x}\nb: {:#0130x}", l.to_bits(), r.to_bits())
24+
};
25+
}
26+
27+
/// Compare by representation
28+
#[allow(unused_macros)]
29+
macro_rules! assert_f128_biteq {
30+
($a:expr, $b:expr) => {
31+
let (l, r): (&f128, &f128) = (&$a, &$b);
32+
let lb = l.to_bits();
33+
let rb = r.to_bits();
34+
assert_eq!(
35+
lb, rb,
36+
"float {:?} is not bitequal to {:?}.\na: {:#0130x}\nb: {:#0130x}",
37+
*l, *r, lb, rb
38+
);
39+
};
40+
}

library/std/src/f16.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! Constants for the `f16` double-precision floating point type.
2+
//!
3+
//! *[See also the `f16` primitive type](primitive@f16).*
4+
//!
5+
//! Mathematically significant numbers are provided in the `consts` sub-module.
6+
7+
#[cfg(test)]
8+
mod tests;
9+
10+
#[unstable(feature = "f16", issue = "116909")]
11+
pub use core::f16::consts;

library/std/src/f16/tests.rs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#![allow(dead_code)] // FIXME(f16_f128): remove once constants are used
2+
3+
// We run out of precision pretty quickly with f16
4+
const F16_APPROX_L1: f16 = 0.001;
5+
const F16_APPROX_L2: f16 = 0.01;
6+
const F16_APPROX_L3: f16 = 0.1;
7+
const F16_APPROX_L4: f16 = 0.5;
8+
9+
/// Smallest number
10+
const TINY_BITS: u16 = 0x1;
11+
/// Next smallest number
12+
const TINY_UP_BITS: u16 = 0x2;
13+
/// Exponent = 0b11...10, Sifnificand 0b1111..10. Min val > 0
14+
const MAX_DOWN_BITS: u16 = 0x7bfe;
15+
/// Zeroed exponent, full significant
16+
const LARGEST_SUBNORMAL_BITS: u16 = 0x03ff;
17+
/// Exponent = 0b1, zeroed significand
18+
const SMALLEST_NORMAL_BITS: u16 = 0x0400;
19+
/// First pattern over the mantissa
20+
const NAN_MASK1: u16 = 0x02aa;
21+
/// Second pattern over the mantissa
22+
const NAN_MASK2: u16 = 0x0155;
23+
24+
/// Compare by value
25+
#[allow(unused_macros)]
26+
macro_rules! assert_f16_eq {
27+
($a:expr, $b:expr) => {
28+
let (l, r): (&f16, &f16) = (&$a, &$b);
29+
assert_eq!(*l, *r, "\na: {:#018x}\nb: {:#018x}", l.to_bits(), r.to_bits())
30+
};
31+
}
32+
33+
/// Compare by representation
34+
#[allow(unused_macros)]
35+
macro_rules! assert_f16_biteq {
36+
($a:expr, $b:expr) => {
37+
let (l, r): (&f16, &f16) = (&$a, &$b);
38+
let lb = l.to_bits();
39+
let rb = r.to_bits();
40+
assert_eq!(
41+
lb, rb,
42+
"float {:?} is not bitequal to {:?}.\na: {:#018x}\nb: {:#018x}",
43+
*l, *r, lb, rb
44+
);
45+
};
46+
}

library/std/src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@
283283
#![feature(doc_masked)]
284284
#![feature(doc_notable_trait)]
285285
#![feature(dropck_eyepatch)]
286+
#![feature(f128)]
287+
#![feature(f16)]
286288
#![feature(if_let_guard)]
287289
#![feature(intra_doc_pointers)]
288290
#![feature(lang_items)]
@@ -558,6 +560,10 @@ pub use core::u8;
558560
#[allow(deprecated, deprecated_in_future)]
559561
pub use core::usize;
560562

563+
#[unstable(feature = "f128", issue = "116909")]
564+
pub mod f128;
565+
#[unstable(feature = "f16", issue = "116909")]
566+
pub mod f16;
561567
pub mod f32;
562568
pub mod f64;
563569

0 commit comments

Comments
 (0)