Skip to content

Commit 715c94d

Browse files
committed
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]. Tracking issue: rust-lang#137578 [1]: rust-lang/compiler-builtins#763
1 parent 1b8ab72 commit 715c94d

File tree

12 files changed

+1730
-892
lines changed

12 files changed

+1730
-892
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;

0 commit comments

Comments
 (0)