Skip to content

Commit 7685734

Browse files
committed
Add powi to f16 and f128
This will unblock adding support to compiler_builtins (<rust-lang/compiler-builtins#614>), which will then unblock adding tests for these new functions.
1 parent a7ca099 commit 7685734

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

library/core/src/intrinsics.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,12 @@ extern "rust-intrinsic" {
15941594
#[rustc_nounwind]
15951595
pub fn sqrtf64(x: f64) -> f64;
15961596

1597+
/// Raises an `f16` to an integer power.
1598+
///
1599+
/// The stabilized version of this intrinsic is
1600+
/// [`f16::powi`](../../std/primitive.f16.html#method.powi)
1601+
#[rustc_nounwind]
1602+
pub fn powif16(a: f16, x: i32) -> f16;
15971603
/// Raises an `f32` to an integer power.
15981604
///
15991605
/// The stabilized version of this intrinsic is
@@ -1606,6 +1612,12 @@ extern "rust-intrinsic" {
16061612
/// [`f64::powi`](../../std/primitive.f64.html#method.powi)
16071613
#[rustc_nounwind]
16081614
pub fn powif64(a: f64, x: i32) -> f64;
1615+
/// Raises an `f128` to an integer power.
1616+
///
1617+
/// The stabilized version of this intrinsic is
1618+
/// [`f128::powi`](../../std/primitive.f128.html#method.powi)
1619+
#[rustc_nounwind]
1620+
pub fn powif128(a: f128, x: i32) -> f128;
16091621

16101622
/// Returns the sine of an `f32`.
16111623
///

library/std/src/f128.rs

+24
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,29 @@
77
#[cfg(test)]
88
mod tests;
99

10+
#[cfg(not(test))]
11+
use crate::intrinsics;
12+
1013
#[unstable(feature = "f128", issue = "116909")]
1114
pub use core::f128::consts;
15+
16+
#[cfg(not(test))]
17+
impl f128 {
18+
/// Raises a number to an integer power.
19+
///
20+
/// Using this function is generally faster than using `powf`.
21+
/// It might have a different sequence of rounding operations than `powf`,
22+
/// so the results are not guaranteed to agree.
23+
///
24+
/// # Unspecified precision
25+
///
26+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
27+
/// can even differ within the same execution from one invocation to the next.
28+
#[inline]
29+
#[rustc_allow_incoherent_impl]
30+
#[unstable(feature = "f128", issue = "116909")]
31+
#[must_use = "method returns a new number and does not mutate the original value"]
32+
pub fn powi(self, n: i32) -> f128 {
33+
unsafe { intrinsics::powif128(self, n) }
34+
}
35+
}

library/std/src/f16.rs

+24
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,29 @@
77
#[cfg(test)]
88
mod tests;
99

10+
#[cfg(not(test))]
11+
use crate::intrinsics;
12+
1013
#[unstable(feature = "f16", issue = "116909")]
1114
pub use core::f16::consts;
15+
16+
#[cfg(not(test))]
17+
impl f16 {
18+
/// Raises a number to an integer power.
19+
///
20+
/// Using this function is generally faster than using `powf`.
21+
/// It might have a different sequence of rounding operations than `powf`,
22+
/// so the results are not guaranteed to agree.
23+
///
24+
/// # Unspecified precision
25+
///
26+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
27+
/// can even differ within the same execution from one invocation to the next.
28+
#[inline]
29+
#[rustc_allow_incoherent_impl]
30+
#[unstable(feature = "f16", issue = "116909")]
31+
#[must_use = "method returns a new number and does not mutate the original value"]
32+
pub fn powi(self, n: i32) -> f16 {
33+
unsafe { intrinsics::powif16(self, n) }
34+
}
35+
}

0 commit comments

Comments
 (0)