Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1cac5fa
Look for `python3` first on MacOS, not `py`
jyn514 Feb 13, 2025
477a2ee
std::fs: slightly reformat `remove_dir_all` error docs
jieyouxu Feb 18, 2025
2c752bc
Undeprecate env::home_dir
arlosi Feb 20, 2025
9323ba5
Remove MaybeForgetReturn suggestion
compiler-errors Feb 20, 2025
b340545
[illumos] attempt to use posix_spawn to spawn processes
sunshowers Feb 11, 2025
a8bff87
Stabilize [T]::split_off... methods
cramertj Feb 28, 2025
ea13ff7
add exclude to config.toml
Shourya742 Feb 16, 2025
d9ceab9
add test for exclude feature
Shourya742 Feb 16, 2025
9206960
Add change info to change tracker
Shourya742 Feb 16, 2025
3998690
compiletest: remove legacy `Makefile`-based `run-make` support
jieyouxu Feb 5, 2025
413b824
run-make: remove `tools.mk`
jieyouxu Feb 5, 2025
9b17c98
run-make: update test suite README
jieyouxu Feb 5, 2025
ed168e7
run-make-support: remove outdated comments
jieyouxu Mar 1, 2025
efec638
tidy: remove legacy `Makefile` checks
jieyouxu Feb 5, 2025
b0d6a84
rustc-dev-guide: remove mentions of legacy `Makefile` run-make infra
jieyouxu Feb 5, 2025
95b030f
triagebot: stop backlinking to the test porting tracking issue
jieyouxu Feb 5, 2025
a0ed304
float: Update some constants to `pub(crate)`
tgross35 Dec 9, 2024
5a2da96
dec2flt: Update documentation of existing methods
tgross35 Dec 9, 2024
49a2d4c
dec2flt: Rename `Decimal` to `DecimalSeq`
tgross35 Dec 9, 2024
626d2c5
dec2flt: Rename `Number` to `Decimal`
tgross35 Dec 9, 2024
6c34daf
dec2flt: Rename fields to be consistent with documented notation
tgross35 Dec 9, 2024
19a909a
dec2flt: Refactor float traits
tgross35 Dec 9, 2024
37e223c
dec2flt: Refactor the fast path
tgross35 Dec 9, 2024
133705c
[rustdoc] hide item that is not marked as doc(inline) and whose src i…
xizheyin Feb 27, 2025
1f930e7
Rollup merge of #134063 - tgross35:dec2flt-refactoring, r=Noratrieb
tgross35 Mar 4, 2025
a0e1ffa
Rollup merge of #136581 - jieyouxu:makefile-be-gone, r=Kobzol
tgross35 Mar 4, 2025
9d3bbb5
Rollup merge of #136975 - jyn514:macos-x, r=Mark-Simulacrum
tgross35 Mar 4, 2025
b74c6d3
Rollup merge of #137147 - Shourya742:2025-02-16-support-exclude-in-co…
tgross35 Mar 4, 2025
1396b94
Rollup merge of #137240 - jieyouxu:remove_dir_all, r=Mark-Simulacrum
tgross35 Mar 4, 2025
1a13de3
Rollup merge of #137303 - compiler-errors:maybe-forgor, r=cjgillot
tgross35 Mar 4, 2025
99d631c
Rollup merge of #137327 - arlosi:home-dir, r=Mark-Simulacrum
tgross35 Mar 4, 2025
5d8da22
Rollup merge of #137463 - sunshowers:illumos-posix-spawn, r=Mark-Simu…
tgross35 Mar 4, 2025
b4ae140
Rollup merge of #137534 - xizheyin:issue-137342, r=GuillaumeGomez
tgross35 Mar 4, 2025
acdf367
Rollup merge of #137829 - cramertj:stabilize-split-off, r=jhpratt
tgross35 Mar 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
dec2flt: Update documentation of existing methods
Fix or elaborate existing float parsing documentation. This includes
introducing a convention that should make naming more consistent.
  • Loading branch information
tgross35 committed Mar 2, 2025
commit 5a2da96a44abad6be752c7ee1cac173aa1ca2f7c
14 changes: 8 additions & 6 deletions library/core/src/num/dec2flt/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ pub(crate) trait ByteSlice {
/// Writes a 64-bit integer as 8 bytes in little-endian order.
fn write_u64(&mut self, value: u64);

/// Calculate the offset of a slice from another.
/// Calculate the difference in length between two slices.
fn offset_from(&self, other: &Self) -> isize;

/// Iteratively parse and consume digits from bytes.
/// Returns the same bytes with consumed digits being
/// elided.
///
/// Returns the same bytes with consumed digits being elided. Breaks on invalid digits.
fn parse_digits(&self, func: impl FnMut(u8)) -> &Self;
}

Expand All @@ -39,11 +39,11 @@ impl ByteSlice for [u8] {
fn parse_digits(&self, mut func: impl FnMut(u8)) -> &Self {
let mut s = self;

while let Some((c, s_next)) = s.split_first() {
while let Some((c, rest)) = s.split_first() {
let c = c.wrapping_sub(b'0');
if c < 10 {
func(c);
s = s_next;
s = rest;
} else {
break;
}
Expand All @@ -53,7 +53,9 @@ impl ByteSlice for [u8] {
}
}

/// Determine if 8 bytes are all decimal digits.
/// Determine if all characters in an 8-byte byte string (represented as a `u64`) are all decimal
/// digits.
///
/// This does not care about the order in which the bytes were loaded.
pub(crate) fn is_8digits(v: u64) -> bool {
let a = v.wrapping_add(0x4646_4646_4646_4646);
Expand Down
22 changes: 13 additions & 9 deletions library/core/src/num/dec2flt/decimal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Arbitrary-precision decimal class for fallback algorithms.
//! Arbitrary-precision decimal type used by fallback algorithms.
//!
//! This is only used if the fast-path (native floats) and
//! the Eisel-Lemire algorithm are unable to unambiguously
Expand All @@ -11,6 +11,7 @@

use crate::num::dec2flt::common::{ByteSlice, is_8digits};

/// A decimal floating-point number.
#[derive(Clone)]
pub(super) struct Decimal {
/// The number of significant digits in the decimal.
Expand All @@ -30,18 +31,17 @@ impl Default for Decimal {
}

impl Decimal {
/// The maximum number of digits required to unambiguously round a float.
/// The maximum number of digits required to unambiguously round up to a 64-bit float.
///
/// For a double-precision IEEE 754 float, this required 767 digits,
/// so we store the max digits + 1.
/// For an IEEE 754 binary64 float, this required 767 digits. So we store the max digits + 1.
///
/// We can exactly represent a float in radix `b` from radix 2 if
/// `b` is divisible by 2. This function calculates the exact number of
/// digits required to exactly represent that float.
///
/// According to the "Handbook of Floating Point Arithmetic",
/// for IEEE754, with emin being the min exponent, p2 being the
/// precision, and b being the radix, the number of digits follows as:
/// for IEEE754, with `emin` being the min exponent, `p2` being the
/// precision, and `b` being the radix, the number of digits follows as:
///
/// `−emin + p2 + ⌊(emin + 1) log(2, b) − log(1 − 2^(−p2), b)⌋`
///
Expand All @@ -56,11 +56,14 @@ impl Decimal {
/// In Python:
/// `-emin + p2 + math.floor((emin+ 1)*math.log(2, b)-math.log(1-2**(-p2), b))`
pub(super) const MAX_DIGITS: usize = 768;
/// The max digits that can be exactly represented in a 64-bit integer.
/// The max decimal digits that can be exactly represented in a 64-bit integer.
pub(super) const MAX_DIGITS_WITHOUT_OVERFLOW: usize = 19;
pub(super) const DECIMAL_POINT_RANGE: i32 = 2047;

/// Append a digit to the buffer.
/// Append a digit to the buffer if it fits.
// FIXME(tgross35): it may be better for this to return an option
// FIXME(tgross35): incrementing the digit counter even if we don't push anything
// seems incorrect.
pub(super) fn try_add_digit(&mut self, digit: u8) {
if self.num_digits < Self::MAX_DIGITS {
self.digits[self.num_digits] = digit;
Expand All @@ -69,6 +72,7 @@ impl Decimal {
}

/// Trim trailing zeros from the buffer.
// FIXME(tgross35): this could be `.rev().position()` if perf is okay
pub(super) fn trim(&mut self) {
// All of the following calls to `Decimal::trim` can't panic because:
//
Expand All @@ -86,7 +90,7 @@ impl Decimal {
pub(super) fn round(&self) -> u64 {
if self.num_digits == 0 || self.decimal_point < 0 {
return 0;
} else if self.decimal_point > 18 {
} else if self.decimal_point >= Self::MAX_DIGITS_WITHOUT_OVERFLOW as i32 {
return 0xFFFF_FFFF_FFFF_FFFF_u64;
}
let dp = self.decimal_point as usize;
Expand Down
16 changes: 14 additions & 2 deletions library/core/src/num/dec2flt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
//! # Problem statement
//!
//! We are given a decimal string such as `12.34e56`. This string consists of integral (`12`),
//! fractional (`34`), and exponent (`56`) parts. All parts are optional and interpreted as zero
//! when missing.
//! fractional (`34`), and exponent (`56`) parts. All parts are optional and interpreted as a
//! default value (1 or 0) when missing.
//!
//! We seek the IEEE 754 floating point number that is closest to the exact value of the decimal
//! string. It is well-known that many decimal strings do not have terminating representations in
Expand Down Expand Up @@ -67,6 +67,18 @@
//! "such that the exponent +/- the number of decimal digits fits into a 64 bit integer".
//! Larger exponents are accepted, but we don't do arithmetic with them, they are immediately
//! turned into {positive,negative} {zero,infinity}.
//!
//! # Notation
//!
//! This module uses the same notation as the Lemire paper:
//!
//! - `m`: binary mantissa; always nonnegative
//! - `p`: binary exponent; a signed integer
//! - `w`: decimal significand; always nonnegative
//! - `q`: decimal exponent; a signed integer
//!
//! This gives `m * 2^p` for the binary floating-point number, with `w * 10^q` as the decimal
//! equivalent.

#![doc(hidden)]
#![unstable(
Expand Down