-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
f16
and f128
step 4: basic library support
#122470
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
88bcc79
Revert "Put basic impls for f16 and f128 behind cfg(not(bootstrap))"
tgross35 454de78
Add basic library support for `f16` and `f128`
tgross35 143ecc3
Add basic f16 and f128 modules
tgross35 311ad55
Add primitive documentation for `f16` and `f128`
tgross35 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,7 @@ macro_rules! floating { | |
}; | ||
} | ||
|
||
floating! { f16 } | ||
floating! { f32 } | ||
floating! { f64 } | ||
floating! { f128 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//! Constants for the `f128` quadruple-precision floating point type. | ||
//! | ||
//! *[See also the `f128` primitive type][f128].* | ||
//! | ||
//! Mathematically significant numbers are provided in the `consts` sub-module. | ||
//! | ||
//! For the constants defined directly in this module | ||
//! (as distinct from those defined in the `consts` sub-module), | ||
//! new code should instead use the associated constants | ||
//! defined directly on the `f128` type. | ||
|
||
#![unstable(feature = "f128", issue = "116909")] | ||
|
||
/// Basic mathematical constants. | ||
#[unstable(feature = "f128", issue = "116909")] | ||
pub mod consts {} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//! Constants for the `f16` half-precision floating point type. | ||
//! | ||
//! *[See also the `f16` primitive type][f16].* | ||
//! | ||
//! Mathematically significant numbers are provided in the `consts` sub-module. | ||
//! | ||
//! For the constants defined directly in this module | ||
//! (as distinct from those defined in the `consts` sub-module), | ||
//! new code should instead use the associated constants | ||
//! defined directly on the `f16` type. | ||
|
||
#![unstable(feature = "f16", issue = "116909")] | ||
|
||
/// Basic mathematical constants. | ||
#[unstable(feature = "f16", issue = "116909")] | ||
pub mod consts {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//! Constants for the `f128` double-precision floating point type. | ||
//! | ||
//! *[See also the `f128` primitive type](primitive@f128).* | ||
//! | ||
//! Mathematically significant numbers are provided in the `consts` sub-module. | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
|
||
#[unstable(feature = "f128", issue = "116909")] | ||
pub use core::f128::consts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//! Constants for the `f16` double-precision floating point type. | ||
//! | ||
//! *[See also the `f16` primitive type](primitive@f16).* | ||
//! | ||
//! Mathematically significant numbers are provided in the `consts` sub-module. | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
|
||
#[unstable(feature = "f16", issue = "116909")] | ||
pub use core::f16::consts; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there plans to add these constants later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I didn't add them because I have no way to test yet. The modules are only here so doc links work for now.