Skip to content

Commit 9cc8ffd

Browse files
committed
Move float tests from std to core where applicable
A lot of float functionality lives in `core` but only gets tested in `std`. Split tests between `std` and `core` to reflect this and ensure as much as possible also can also get tested on no-std targets.
1 parent ce911ff commit 9cc8ffd

File tree

14 files changed

+1215
-1328
lines changed

14 files changed

+1215
-1328
lines changed

library/core/src/num/f32.rs

+15-91
Original file line numberDiff line numberDiff line change
@@ -1508,9 +1508,7 @@ impl f32 {
15081508
}
15091509
}
15101510

1511-
/// Returns the largest integer less than or equal to `self`.
1512-
///
1513-
/// This function always returns the precise result.
1511+
/// Experimental version of `floor` in `core`. See [`f32::floor`] for details.
15141512
///
15151513
/// # Examples
15161514
///
@@ -1537,9 +1535,7 @@ pub fn floor(x: f32) -> f32 {
15371535
unsafe { intrinsics::floorf32(x) }
15381536
}
15391537

1540-
/// Returns the smallest integer greater than or equal to `self`.
1541-
///
1542-
/// This function always returns the precise result.
1538+
/// Experimental version of `ceil` in `core`. See [`f32::ceil`] for details.
15431539
///
15441540
/// # Examples
15451541
///
@@ -1565,10 +1561,7 @@ pub fn ceil(x: f32) -> f32 {
15651561
unsafe { intrinsics::ceilf32(x) }
15661562
}
15671563

1568-
/// Returns the nearest integer to `self`. If a value is half-way between two
1569-
/// integers, round away from `0.0`.
1570-
///
1571-
/// This function always returns the precise result.
1564+
/// Experimental version of `round` in `core`. See [`f32::round`] for details.
15721565
///
15731566
/// # Examples
15741567
///
@@ -1599,10 +1592,7 @@ pub fn round(x: f32) -> f32 {
15991592
unsafe { intrinsics::roundf32(x) }
16001593
}
16011594

1602-
/// Returns the nearest integer to a number. Rounds half-way cases to the number
1603-
/// with an even least significant digit.
1604-
///
1605-
/// This function always returns the precise result.
1595+
/// Experimental version of `round_ties_even` in `core`. See [`f32::round_ties_even`] for details.
16061596
///
16071597
/// # Examples
16081598
///
@@ -1630,10 +1620,7 @@ pub fn round_ties_even(x: f32) -> f32 {
16301620
intrinsics::round_ties_even_f32(x)
16311621
}
16321622

1633-
/// Returns the integer part of `self`.
1634-
/// This means that non-integer numbers are always truncated towards zero.
1635-
///
1636-
/// This function always returns the precise result.
1623+
/// Experimental version of `trunc` in `core`. See [`f32::trunc`] for details.
16371624
///
16381625
/// # Examples
16391626
///
@@ -1661,9 +1648,7 @@ pub fn trunc(x: f32) -> f32 {
16611648
unsafe { intrinsics::truncf32(x) }
16621649
}
16631650

1664-
/// Returns the fractional part of `self`.
1665-
///
1666-
/// This function always returns the precise result.
1651+
/// Experimental version of `fract` in `core`. See [`f32::fract`] for details.
16671652
///
16681653
/// # Examples
16691654
///
@@ -1689,19 +1674,7 @@ pub fn fract(x: f32) -> f32 {
16891674
x - trunc(x)
16901675
}
16911676

1692-
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
1693-
/// error, yielding a more accurate result than an unfused multiply-add.
1694-
///
1695-
/// Using `mul_add` *may* be more performant than an unfused multiply-add if
1696-
/// the target architecture has a dedicated `fma` CPU instruction. However,
1697-
/// this is not always true, and will be heavily dependant on designing
1698-
/// algorithms with specific target hardware in mind.
1699-
///
1700-
/// # Precision
1701-
///
1702-
/// The result of this operation is guaranteed to be the rounded
1703-
/// infinite-precision result. It is specified by IEEE 754 as
1704-
/// `fusedMultiplyAdd` and guaranteed not to change.
1677+
/// Experimental version of `mul_add` in `core`. See [`f32::mul_add`] for details.
17051678
///
17061679
/// # Examples
17071680
///
@@ -1737,17 +1710,7 @@ pub fn mul_add(x: f32, y: f32, z: f32) -> f32 {
17371710
unsafe { intrinsics::fmaf32(x, y, z) }
17381711
}
17391712

1740-
/// Calculates Euclidean division, the matching method for `rem_euclid`.
1741-
///
1742-
/// This computes the integer `n` such that
1743-
/// `self = n * rhs + self.rem_euclid(rhs)`.
1744-
/// In other words, the result is `self / rhs` rounded to the integer `n`
1745-
/// such that `self >= n * rhs`.
1746-
///
1747-
/// # Precision
1748-
///
1749-
/// The result of this operation is guaranteed to be the rounded
1750-
/// infinite-precision result.
1713+
/// Experimental version of `div_euclid` in `core`. See [`f32::div_euclid`] for details.
17511714
///
17521715
/// # Examples
17531716
///
@@ -1776,21 +1739,7 @@ pub fn div_euclid(x: f32, rhs: f32) -> f32 {
17761739
q
17771740
}
17781741

1779-
/// Calculates the least nonnegative remainder of `self (mod rhs)`.
1780-
///
1781-
/// In particular, the return value `r` satisfies `0.0 <= r < rhs.abs()` in
1782-
/// most cases. However, due to a floating point round-off error it can
1783-
/// result in `r == rhs.abs()`, violating the mathematical definition, if
1784-
/// `self` is much smaller than `rhs.abs()` in magnitude and `self < 0.0`.
1785-
/// This result is not an element of the function's codomain, but it is the
1786-
/// closest floating point number in the real numbers and thus fulfills the
1787-
/// property `self == self.div_euclid(rhs) * rhs + self.rem_euclid(rhs)`
1788-
/// approximately.
1789-
///
1790-
/// # Precision
1791-
///
1792-
/// The result of this operation is guaranteed to be the rounded
1793-
/// infinite-precision result.
1742+
/// Experimental version of `rem_euclid` in `core`. See [`f32::rem_euclid`] for details.
17941743
///
17951744
/// # Examples
17961745
///
@@ -1819,16 +1768,7 @@ pub fn rem_euclid(x: f32, rhs: f32) -> f32 {
18191768
if r < 0.0 { r + rhs.abs() } else { r }
18201769
}
18211770

1822-
/// Raises a number to an integer power.
1823-
///
1824-
/// Using this function is generally faster than using `powf`.
1825-
/// It might have a different sequence of rounding operations than `powf`,
1826-
/// so the results are not guaranteed to agree.
1827-
///
1828-
/// # Unspecified precision
1829-
///
1830-
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
1831-
/// can even differ within the same execution from one invocation to the next.
1771+
/// Experimental version of `powi` in `core`. See [`f32::powi`] for details.
18321772
///
18331773
/// # Examples
18341774
///
@@ -1853,15 +1793,7 @@ pub fn powi(x: f32, n: i32) -> f32 {
18531793
unsafe { intrinsics::powif32(x, n) }
18541794
}
18551795

1856-
/// Returns the square root of a number.
1857-
///
1858-
/// Returns NaN if `self` is a negative number other than `-0.0`.
1859-
///
1860-
/// # Precision
1861-
///
1862-
/// The result of this operation is guaranteed to be the rounded
1863-
/// infinite-precision result. It is specified by IEEE 754 as `squareRoot`
1864-
/// and guaranteed not to change.
1796+
/// Experimental version of `sqrt` in `core`. See [`f32::sqrt`] for details.
18651797
///
18661798
/// # Examples
18671799
///
@@ -1889,17 +1821,7 @@ pub fn sqrt(x: f32) -> f32 {
18891821
unsafe { intrinsics::sqrtf32(x) }
18901822
}
18911823

1892-
/// The positive difference of two numbers.
1893-
///
1894-
/// * If `self <= other`: `0.0`
1895-
/// * Else: `self - other`
1896-
///
1897-
/// # Unspecified precision
1898-
///
1899-
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
1900-
/// can even differ within the same execution from one invocation to the next.
1901-
/// This function currently corresponds to the `fdimf` from libc on Unix
1902-
/// and Windows. Note that this might change in the future.
1824+
/// Experimental version of `abs_sub` in `core`. See [`f32::abs_sub`] for details.
19031825
///
19041826
/// # Examples
19051827
///
@@ -1937,7 +1859,7 @@ pub fn abs_sub(x: f32, other: f32) -> f32 {
19371859
unsafe { libm::fdimf(x, other) }
19381860
}
19391861

1940-
/// Returns the cube root of a number.
1862+
/// Experimental version of `cbrt` in `core`. See [`f32::cbrt`] for details.
19411863
///
19421864
/// # Unspecified precision
19431865
///
@@ -1956,6 +1878,8 @@ pub fn abs_sub(x: f32, other: f32) -> f32 {
19561878
///
19571879
/// assert!(abs_difference <= f32::EPSILON);
19581880
/// ```
1881+
///
1882+
/// _This standalone function is for testing only. It will be stabilized as an inherent method._
19591883
#[inline]
19601884
#[must_use = "method returns a new number and does not mutate the original value"]
19611885
#[unstable(feature = "core_float_math", issue = "137578")]

0 commit comments

Comments
 (0)