Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
41e6f76
future-incompat lints: don't link to the nightly edition-guide version
dianne Jul 16, 2025
dad96b1
Use serde for target spec json deserialize
Noratrieb Jul 20, 2025
c4eb077
Ensure we codegen and don't internalize the entrypoint
saethlin Jul 17, 2025
6e8762f
Use less HIR in check_private_in_public.
cjgillot Oct 1, 2023
0aa6170
Add a test case for ui test false-sealed-traits-note.rs
yuk1ty Jul 21, 2025
2d1fccd
pass build.npm from bootstrap to tidy and use it for npm install
lolbinarycat Jul 22, 2025
9e75032
rustdoc: avoid allocating a temp String for aliases in search index
lolbinarycat Jul 22, 2025
3440bc9
Unquerify extern_mod_stmt_cnum.
cjgillot Jul 3, 2025
95de0aa
rustc_resolve: get rid of unused rustdoc::span_of_fragments_with_expa…
lolbinarycat Jul 22, 2025
ab8e521
get rid of some false negatives in rustdoc::broken_intra_doc_links
lolbinarycat Nov 7, 2024
91b9b33
adjust more unit tests to reflect more aggressive intra-doc linting
lolbinarycat Nov 8, 2024
de68c59
rustdoc::broken_intra_doc_links: no backticks = use old behavior
lolbinarycat Apr 18, 2025
c5b39cf
rustdoc: update tests to match new lint behavior
lolbinarycat Apr 18, 2025
82df892
rustdoc::broken_intra_doc_links: only be lenient with shortcut links
lolbinarycat Apr 19, 2025
2d38996
move bad-intra-doc test into intra-doc dir
lolbinarycat Apr 19, 2025
9bb9c39
Don't suggest assoc ty bound on non-angle-bracketed problematic assoc…
fmease Jul 22, 2025
eb9c654
std: net: uefi: Add support to query connection data
Ayush1325 Jul 12, 2025
af06bb9
Stop using the old `validate_attr` logic for stability attributes
JonathanBrouwer Jul 23, 2025
37480bc
coretests/num: use ldexp instead of hard-coding a power of 2
RalfJung Jul 21, 2025
371b010
generate elf symbol version in raw-dylib
usamoi Jul 20, 2025
648e844
Rollup merge of #132748 - lolbinarycat:rustdoc-intra-doc-link-warn-mo…
fmease Jul 24, 2025
bd914d0
Rollup merge of #143374 - cjgillot:bare-extern-crate-map, r=petrochenkov
fmease Jul 24, 2025
aaad15d
Rollup merge of #143838 - Ayush1325:uefi-tcp4-config-data, r=tgross35
fmease Jul 24, 2025
8432fc2
Rollup merge of #144014 - dianne:edition-guide-links, r=estebank
fmease Jul 24, 2025
8702a51
Rollup merge of #144094 - saethlin:codegen-the-main-fn, r=petrochenkov
fmease Jul 24, 2025
5b6238a
Rollup merge of #144218 - Noratrieb:target-spec-json-de-jank, r=fee1-…
fmease Jul 24, 2025
9ee0f7d
Rollup merge of #144221 - usamoi:versym, r=bjorn3
fmease Jul 24, 2025
f79ca51
Rollup merge of #144240 - yuk1ty:false-sealed-traits-note-reported-in…
fmease Jul 24, 2025
78f83fe
Rollup merge of #144247 - RalfJung:ldexp, r=tgross35
fmease Jul 24, 2025
cf6fdf6
Rollup merge of #144276 - cjgillot:no-hir-privacy, r=petrochenkov
fmease Jul 24, 2025
fafdf5b
Rollup merge of #144317 - lolbinarycat:tidy-obey-build.npm, r=Kobzol
fmease Jul 24, 2025
c031c78
Rollup merge of #144320 - lolbinarycat:rustdoc-search_index-BTreeMap-…
fmease Jul 24, 2025
bd9b61c
Rollup merge of #144334 - lolbinarycat:rustdoc-span_of_fragments-reve…
fmease Jul 24, 2025
7282814
Rollup merge of #144335 - fmease:no-angle-no-colon, r=SparrowLii
fmease Jul 24, 2025
bdede1c
Rollup merge of #144358 - JonathanBrouwer:fix-stability-malformed, r=…
fmease Jul 24, 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
coretests/num: use ldexp instead of hard-coding a power of 2
  • Loading branch information
RalfJung committed Jul 23, 2025
commit 37480bc9e6fef8b2a455b07742a1ee4f364f972c
11 changes: 5 additions & 6 deletions library/coretests/tests/num/dec2flt/float.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use core::num::dec2flt::float::RawFloat;

use crate::num::{ldexp_f32, ldexp_f64};

// FIXME(f16_f128): enable on all targets once possible.
#[test]
#[cfg(target_has_reliable_f16)]
fn test_f16_integer_decode() {
assert_eq!(3.14159265359f16.integer_decode(), (1608, -9, 1));
assert_eq!((-8573.5918555f16).integer_decode(), (1072, 3, -1));
#[cfg(not(miri))] // miri doesn't have powf16
assert_eq!(2f16.powf(14.0).integer_decode(), (1 << 10, 4, 1));
assert_eq!(crate::num::ldexp_f16(1.0, 14).integer_decode(), (1 << 10, 4, 1));
assert_eq!(0f16.integer_decode(), (0, -25, 1));
assert_eq!((-0f16).integer_decode(), (0, -25, -1));
assert_eq!(f16::INFINITY.integer_decode(), (1 << 10, 6, 1));
Expand All @@ -23,8 +24,7 @@ fn test_f16_integer_decode() {
fn test_f32_integer_decode() {
assert_eq!(3.14159265359f32.integer_decode(), (13176795, -22, 1));
assert_eq!((-8573.5918555f32).integer_decode(), (8779358, -10, -1));
// Set 2^100 directly instead of using powf, because it doesn't guarantee precision
assert_eq!(1.2676506e30_f32.integer_decode(), (8388608, 77, 1));
assert_eq!(ldexp_f32(1.0, 100).integer_decode(), (8388608, 77, 1));
assert_eq!(0f32.integer_decode(), (0, -150, 1));
assert_eq!((-0f32).integer_decode(), (0, -150, -1));
assert_eq!(f32::INFINITY.integer_decode(), (8388608, 105, 1));
Expand All @@ -40,8 +40,7 @@ fn test_f32_integer_decode() {
fn test_f64_integer_decode() {
assert_eq!(3.14159265359f64.integer_decode(), (7074237752028906, -51, 1));
assert_eq!((-8573.5918555f64).integer_decode(), (4713381968463931, -39, -1));
// Set 2^100 directly instead of using powf, because it doesn't guarantee precision
assert_eq!(1.2676506002282294e30_f64.integer_decode(), (4503599627370496, 48, 1));
assert_eq!(ldexp_f64(1.0, 100).integer_decode(), (4503599627370496, 48, 1));
assert_eq!(0f64.integer_decode(), (0, -1075, 1));
assert_eq!((-0f64).integer_decode(), (0, -1075, -1));
assert_eq!(f64::INFINITY.integer_decode(), (4503599627370496, 972, 1));
Expand Down
4 changes: 3 additions & 1 deletion library/coretests/tests/num/flt2dec/estimator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use core::num::flt2dec::estimator::*;

use crate::num::ldexp_f64;

#[test]
fn test_estimate_scaling_factor() {
macro_rules! assert_almost_eq {
Expand Down Expand Up @@ -56,7 +58,7 @@ fn test_estimate_scaling_factor() {
let step = if cfg!(miri) { 37 } else { 1 };

for i in (-1074..972).step_by(step) {
let expected = super::ldexp_f64(1.0, i).log10().ceil();
let expected = ldexp_f64(1.0, i).log10().ceil();
assert_almost_eq!(estimate_scaling_factor(1, i as i16), expected as i16);
}
}
34 changes: 9 additions & 25 deletions library/coretests/tests/num/flt2dec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use core::num::fmt::{Formatted, Part};
use std::mem::MaybeUninit;
use std::{fmt, str};

use crate::num::{ldexp_f32, ldexp_f64};

mod estimator;
mod strategy {
mod dragon;
Expand Down Expand Up @@ -75,24 +77,6 @@ macro_rules! try_fixed {
})
}

#[cfg(target_has_reliable_f16)]
fn ldexp_f16(a: f16, b: i32) -> f16 {
ldexp_f64(a as f64, b) as f16
}

fn ldexp_f32(a: f32, b: i32) -> f32 {
ldexp_f64(a as f64, b) as f32
}

fn ldexp_f64(a: f64, b: i32) -> f64 {
unsafe extern "C" {
fn ldexp(x: f64, n: i32) -> f64;
}
// SAFETY: assuming a correct `ldexp` has been supplied, the given arguments cannot possibly
// cause undefined behavior
unsafe { ldexp(a, b) }
}

fn check_exact<F, T>(mut f: F, v: T, vstr: &str, expected: &[u8], expectedk: i16)
where
T: DecodableFloat,
Expand Down Expand Up @@ -268,7 +252,7 @@ where
// 10^2 * 0.31984375
// 10^2 * 0.32
// 10^2 * 0.3203125
check_shortest!(f(ldexp_f16(1.0, 5)) => b"32", 2);
check_shortest!(f(crate::num::ldexp_f16(1.0, 5)) => b"32", 2);

// 10^5 * 0.65472
// 10^5 * 0.65504
Expand All @@ -283,7 +267,7 @@ where
// 10^-9 * 0
// 10^-9 * 0.59604644775390625
// 10^-8 * 0.11920928955078125
let minf16 = ldexp_f16(1.0, -24);
let minf16 = crate::num::ldexp_f16(1.0, -24);
check_shortest!(f(minf16) => b"6", -7);
}

Expand All @@ -292,7 +276,7 @@ pub fn f16_exact_sanity_test<F>(mut f: F)
where
F: for<'a> FnMut(&Decoded, &'a mut [MaybeUninit<u8>], i16) -> (&'a [u8], i16),
{
let minf16 = ldexp_f16(1.0, -24);
let minf16 = crate::num::ldexp_f16(1.0, -24);

check_exact!(f(0.1f16) => b"999755859375 ", -1);
check_exact!(f(0.5f16) => b"5 ", 0);
Expand Down Expand Up @@ -642,7 +626,7 @@ where
assert_eq!(to_string(f, f16::MAX, Minus, 1), "65500.0");
assert_eq!(to_string(f, f16::MAX, Minus, 8), "65500.00000000");

let minf16 = ldexp_f16(1.0, -24);
let minf16 = crate::num::ldexp_f16(1.0, -24);
assert_eq!(to_string(f, minf16, Minus, 0), "0.00000006");
assert_eq!(to_string(f, minf16, Minus, 8), "0.00000006");
assert_eq!(to_string(f, minf16, Minus, 9), "0.000000060");
Expand Down Expand Up @@ -766,7 +750,7 @@ where
assert_eq!(to_string(f, f16::MAX, Minus, (-4, 4), false), "6.55e4");
assert_eq!(to_string(f, f16::MAX, Minus, (-5, 5), false), "65500");

let minf16 = ldexp_f16(1.0, -24);
let minf16 = crate::num::ldexp_f16(1.0, -24);
assert_eq!(to_string(f, minf16, Minus, (-2, 2), false), "6e-8");
assert_eq!(to_string(f, minf16, Minus, (-7, 7), false), "6e-8");
assert_eq!(to_string(f, minf16, Minus, (-8, 8), false), "0.00000006");
Expand Down Expand Up @@ -922,7 +906,7 @@ where
assert_eq!(to_string(f, f16::MAX, Minus, 6, false), "6.55040e4");
assert_eq!(to_string(f, f16::MAX, Minus, 16, false), "6.550400000000000e4");

let minf16 = ldexp_f16(1.0, -24);
let minf16 = crate::num::ldexp_f16(1.0, -24);
assert_eq!(to_string(f, minf16, Minus, 1, false), "6e-8");
assert_eq!(to_string(f, minf16, Minus, 2, false), "6.0e-8");
assert_eq!(to_string(f, minf16, Minus, 4, false), "5.960e-8");
Expand Down Expand Up @@ -1229,7 +1213,7 @@ where

#[cfg(target_has_reliable_f16)]
{
let minf16 = ldexp_f16(1.0, -24);
let minf16 = crate::num::ldexp_f16(1.0, -24);
assert_eq!(to_string(f, minf16, Minus, 0), "0");
assert_eq!(to_string(f, minf16, Minus, 1), "0.0");
assert_eq!(to_string(f, minf16, Minus, 2), "0.00");
Expand Down
21 changes: 21 additions & 0 deletions library/coretests/tests/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@ macro_rules! assume_usize_width {
}
}

/// Return `a * 2^b`.
#[cfg(target_has_reliable_f16)]
fn ldexp_f16(a: f16, b: i32) -> f16 {
ldexp_f64(a as f64, b) as f16
}

/// Return `a * 2^b`.
fn ldexp_f32(a: f32, b: i32) -> f32 {
ldexp_f64(a as f64, b) as f32
}

/// Return `a * 2^b`.
fn ldexp_f64(a: f64, b: i32) -> f64 {
unsafe extern "C" {
fn ldexp(x: f64, n: i32) -> f64;
}
// SAFETY: assuming a correct `ldexp` has been supplied, the given arguments cannot possibly
// cause undefined behavior
unsafe { ldexp(a, b) }
}

/// Helper function for testing numeric operations
pub fn test_num<T>(ten: T, two: T)
where
Expand Down
Loading