Skip to content

Rollup of 10 pull requests #140547

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

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
cf26d82
chore: remove redundant words in comment
pudongair Mar 26, 2025
d81559a
Refactor `diy_float`
TDecking Mar 31, 2025
5a20701
Change signature of File::try_lock and File::try_lock_shared
cberner Apr 4, 2025
7302f8e
Implement error::Error for TryLockError
cberner Apr 6, 2025
e5fb426
docs: Add example to `Iterator::take` with `by_ref`
ongardie Apr 14, 2025
0369ccb
Fix some grammar errors and hyperlinks in doc for `trait Allocator`
Lee-Janggun Apr 14, 2025
31cb737
simd_select_bitmask: the 'padding' bits in the mask are just ignored
RalfJung Apr 19, 2025
3a372e3
std: mention `remove_dir_all` can emit `DirectoryNotEmpty` when concu…
xizheyin Apr 20, 2025
e9d2fef
stop check paren if has different ctx
bvanjoi Apr 29, 2025
d9c060b
Optimize the codegen for `Span::from_expansion`
Jarcho Apr 29, 2025
00f25a8
interpret: better error message for out-of-bounds pointer arithmetic …
RalfJung Apr 30, 2025
64ba474
Rollup merge of #134034 - bvanjoi:issue-131655, r=petrochenkov
Zalathar May 1, 2025
a5ffdb8
Rollup merge of #138703 - pudongair:master, r=workingjubilee
Zalathar May 1, 2025
b06dbd0
Rollup merge of #139186 - TDecking:float, r=workingjubilee
Zalathar May 1, 2025
485270d
Rollup merge of #139343 - cberner:filelock_wouldblock, r=workingjubilee
Zalathar May 1, 2025
76fa362
Rollup merge of #139780 - ongardie:iterator-take-by_ref-example, r=wo…
Zalathar May 1, 2025
a471fe9
Rollup merge of #139802 - Lee-Janggun:fix-allocate-hyperlink, r=worki…
Zalathar May 1, 2025
c4da0f3
Rollup merge of #140034 - RalfJung:simd_select_bitmask-padding, r=wor…
Zalathar May 1, 2025
5d78430
Rollup merge of #140062 - xizheyin:issue-139958, r=workingjubilee
Zalathar May 1, 2025
ca45af0
Rollup merge of #140485 - Jarcho:from_expansion_opt, r=petrochenkov
Zalathar May 1, 2025
582dbdd
Rollup merge of #140521 - RalfJung:oob-error, r=saethlin
Zalathar May 1, 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
54 changes: 11 additions & 43 deletions library/core/src/num/diy_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,61 +21,29 @@ pub struct Fp {

impl Fp {
/// Returns a correctly rounded product of itself and `other`.
pub fn mul(&self, other: &Fp) -> Fp {
const MASK: u64 = 0xffffffff;
let a = self.f >> 32;
let b = self.f & MASK;
let c = other.f >> 32;
let d = other.f & MASK;
let ac = a * c;
let bc = b * c;
let ad = a * d;
let bd = b * d;
let tmp = (bd >> 32) + (ad & MASK) + (bc & MASK) + (1 << 31) /* round */;
let f = ac + (ad >> 32) + (bc >> 32) + (tmp >> 32);
pub fn mul(self, other: Self) -> Self {
let (lo, hi) = self.f.widening_mul(other.f);
let f = hi + (lo >> 63) /* round */;
let e = self.e + other.e + 64;
Fp { f, e }
Self { f, e }
}

/// Normalizes itself so that the resulting mantissa is at least `2^63`.
pub fn normalize(&self) -> Fp {
let mut f = self.f;
let mut e = self.e;
if f >> (64 - 32) == 0 {
f <<= 32;
e -= 32;
}
if f >> (64 - 16) == 0 {
f <<= 16;
e -= 16;
}
if f >> (64 - 8) == 0 {
f <<= 8;
e -= 8;
}
if f >> (64 - 4) == 0 {
f <<= 4;
e -= 4;
}
if f >> (64 - 2) == 0 {
f <<= 2;
e -= 2;
}
if f >> (64 - 1) == 0 {
f <<= 1;
e -= 1;
}
pub fn normalize(self) -> Self {
let lz = self.f.leading_zeros();
let f = self.f << lz;
let e = self.e - lz as i16;
debug_assert!(f >= (1 << 63));
Fp { f, e }
Self { f, e }
}

/// Normalizes itself to have the shared exponent.
/// It can only decrease the exponent (and thus increase the mantissa).
pub fn normalize_to(&self, e: i16) -> Fp {
pub fn normalize_to(self, e: i16) -> Self {
let edelta = self.e - e;
assert!(edelta >= 0);
let edelta = edelta as usize;
assert_eq!(self.f << edelta >> edelta, self.f);
Fp { f: self.f << edelta, e }
Self { f: self.f << edelta, e }
}
}
8 changes: 4 additions & 4 deletions library/core/src/num/flt2dec/strategy/grisu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ pub fn format_shortest_opt<'a>(
let (minusk, cached) = cached_power(ALPHA - plus.e - 64, GAMMA - plus.e - 64);

// scale fps. this gives the maximal error of 1 ulp (proved from Theorem 5.1).
let plus = plus.mul(&cached);
let minus = minus.mul(&cached);
let v = v.mul(&cached);
let plus = plus.mul(cached);
let minus = minus.mul(cached);
let v = v.mul(cached);
debug_assert_eq!(plus.e, minus.e);
debug_assert_eq!(plus.e, v.e);

Expand Down Expand Up @@ -480,7 +480,7 @@ pub fn format_exact_opt<'a>(
// normalize and scale `v`.
let v = Fp { f: d.mant, e: d.exp }.normalize();
let (minusk, cached) = cached_power(ALPHA - v.e - 64, GAMMA - v.e - 64);
let v = v.mul(&cached);
let v = v.mul(cached);

// divide `v` into integral and fractional parts.
let e = -v.e as usize;
Expand Down