Skip to content

Commit 58c562e

Browse files
committed
Auto merge of rust-lang#138087 - tgross35:core-float-math, r=<try>
Initial implementation of `core_float_math` Since [1], `compiler-builtins` makes a certain set of math symbols weakly available on all platforms. This means we can begin exposing some of the related functions in `core`, so begin this process here. It is not possible to provide inherent methods in both `core` and `std` while giving them different stability gates, so standalone functions are added instead. This provides a way to experiment with the functionality while unstable; once it is time to stabilize, they can be converted to inherent. For `f16` and `f128`, everything is unstable so we can move the inherent methods. The following are included to start: * floor * ceil * round * round_ties_even * trunc * fract * mul_add * div_euclid * rem_euclid * powi * sqrt * abs_sub * cbrt These mirror the set of functions that we have in `compiler-builtins` since [1], with the exception of `powi` that has been there longer. Details for each of the changes is in the commit messages. Tracking issue: rust-lang#137578 [1]: rust-lang/compiler-builtins#763 try-job: aarch64-apple try-job: aarch64-gnu try-job: arm-android tru-job: armhf-gnu try-job: dist-various-1 try-job: dist-various-2 try-job: i686-msvc-1 try-job: test-various try-job: x86_64-apple-1 try-job: x86_64-msvc-ext2
2 parents 1b8ab72 + ec5735b commit 58c562e

File tree

24 files changed

+4756
-3767
lines changed

24 files changed

+4756
-3767
lines changed

library/core/src/num/f128.rs

+421
Large diffs are not rendered by default.

library/core/src/num/f16.rs

+457
Large diffs are not rendered by default.

library/core/src/num/f32.rs

+409-1
Large diffs are not rendered by default.

library/core/src/num/f64.rs

+402-1
Large diffs are not rendered by default.

library/core/src/num/libm.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! Bindings to math functions provided by the system `libm` or by the `libm` crate, exposed
2+
//! via `compiler-builtins`.
3+
4+
// SAFETY: These symbols have standard interfaces in C and are defined by `libm`, or are
5+
// provided by `compiler-builtins` on unsupported platforms.
6+
unsafe extern "C" {
7+
pub(crate) safe fn cbrt(n: f64) -> f64;
8+
pub(crate) safe fn cbrtf(n: f32) -> f32;
9+
pub(crate) safe fn fdim(a: f64, b: f64) -> f64;
10+
pub(crate) safe fn fdimf(a: f32, b: f32) -> f32;
11+
}

library/core/src/num/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ mod uint_macros; // import uint_impl!
4646
mod error;
4747
mod int_log10;
4848
mod int_sqrt;
49+
pub(crate) mod libm;
4950
mod nonzero;
5051
mod overflow_panic;
5152
mod saturating;

library/coretests/build.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
mod build_shared {
2+
include!("../std/build_shared.rs");
3+
}
4+
5+
fn main() {
6+
println!("cargo:rerun-if-changed=../std/build_shared.rs");
7+
8+
let cfg = build_shared::Config::from_env();
9+
build_shared::configure_f16_f128(&cfg);
10+
}

0 commit comments

Comments
 (0)