Auto merge of #125188 - tgross35:f16-f128-powi, r=Nilstrieb
Add `powi` fo `f16` and `f128` This will unblock adding support to compiler_builtins (<https://github.com/rust-lang/compiler-builtins/pull/614>), which will then unblock adding tests for these new functions.
This commit is contained in:
commit
ddba1dc97e
6 changed files with 100 additions and 1 deletions
|
@ -1594,6 +1594,12 @@ extern "rust-intrinsic" {
|
||||||
#[rustc_nounwind]
|
#[rustc_nounwind]
|
||||||
pub fn sqrtf64(x: f64) -> f64;
|
pub fn sqrtf64(x: f64) -> f64;
|
||||||
|
|
||||||
|
/// Raises an `f16` to an integer power.
|
||||||
|
///
|
||||||
|
/// The stabilized version of this intrinsic is
|
||||||
|
/// [`f16::powi`](../../std/primitive.f16.html#method.powi)
|
||||||
|
#[rustc_nounwind]
|
||||||
|
pub fn powif16(a: f16, x: i32) -> f16;
|
||||||
/// Raises an `f32` to an integer power.
|
/// Raises an `f32` to an integer power.
|
||||||
///
|
///
|
||||||
/// The stabilized version of this intrinsic is
|
/// The stabilized version of this intrinsic is
|
||||||
|
@ -1606,6 +1612,12 @@ extern "rust-intrinsic" {
|
||||||
/// [`f64::powi`](../../std/primitive.f64.html#method.powi)
|
/// [`f64::powi`](../../std/primitive.f64.html#method.powi)
|
||||||
#[rustc_nounwind]
|
#[rustc_nounwind]
|
||||||
pub fn powif64(a: f64, x: i32) -> f64;
|
pub fn powif64(a: f64, x: i32) -> f64;
|
||||||
|
/// Raises an `f128` to an integer power.
|
||||||
|
///
|
||||||
|
/// The stabilized version of this intrinsic is
|
||||||
|
/// [`f128::powi`](../../std/primitive.f128.html#method.powi)
|
||||||
|
#[rustc_nounwind]
|
||||||
|
pub fn powif128(a: f128, x: i32) -> f128;
|
||||||
|
|
||||||
/// Returns the sine of an `f32`.
|
/// Returns the sine of an `f32`.
|
||||||
///
|
///
|
||||||
|
|
|
@ -228,6 +228,16 @@ impl f128 {
|
||||||
/// the bit pattern of NaNs are conserved over arithmetic operations, the result of
|
/// the bit pattern of NaNs are conserved over arithmetic operations, the result of
|
||||||
/// `is_sign_positive` on a NaN might produce an unexpected result in some cases.
|
/// `is_sign_positive` on a NaN might produce an unexpected result in some cases.
|
||||||
/// See [explanation of NaN as a special value](f32) for more info.
|
/// See [explanation of NaN as a special value](f32) for more info.
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// #![feature(f128)]
|
||||||
|
///
|
||||||
|
/// let f = 7.0_f128;
|
||||||
|
/// let g = -7.0_f128;
|
||||||
|
///
|
||||||
|
/// assert!(f.is_sign_positive());
|
||||||
|
/// assert!(!g.is_sign_positive());
|
||||||
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[unstable(feature = "f128", issue = "116909")]
|
#[unstable(feature = "f128", issue = "116909")]
|
||||||
|
@ -241,6 +251,16 @@ impl f128 {
|
||||||
/// the bit pattern of NaNs are conserved over arithmetic operations, the result of
|
/// the bit pattern of NaNs are conserved over arithmetic operations, the result of
|
||||||
/// `is_sign_negative` on a NaN might produce an unexpected result in some cases.
|
/// `is_sign_negative` on a NaN might produce an unexpected result in some cases.
|
||||||
/// See [explanation of NaN as a special value](f32) for more info.
|
/// See [explanation of NaN as a special value](f32) for more info.
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// #![feature(f128)]
|
||||||
|
///
|
||||||
|
/// let f = 7.0_f128;
|
||||||
|
/// let g = -7.0_f128;
|
||||||
|
///
|
||||||
|
/// assert!(!f.is_sign_negative());
|
||||||
|
/// assert!(g.is_sign_negative());
|
||||||
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[unstable(feature = "f128", issue = "116909")]
|
#[unstable(feature = "f128", issue = "116909")]
|
||||||
|
|
|
@ -224,6 +224,16 @@ impl f16 {
|
||||||
/// the bit pattern of NaNs are conserved over arithmetic operations, the result of
|
/// the bit pattern of NaNs are conserved over arithmetic operations, the result of
|
||||||
/// `is_sign_positive` on a NaN might produce an unexpected result in some cases.
|
/// `is_sign_positive` on a NaN might produce an unexpected result in some cases.
|
||||||
/// See [explanation of NaN as a special value](f32) for more info.
|
/// See [explanation of NaN as a special value](f32) for more info.
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// #![feature(f16)]
|
||||||
|
///
|
||||||
|
/// let f = 7.0_f16;
|
||||||
|
/// let g = -7.0_f16;
|
||||||
|
///
|
||||||
|
/// assert!(f.is_sign_positive());
|
||||||
|
/// assert!(!g.is_sign_positive());
|
||||||
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[unstable(feature = "f16", issue = "116909")]
|
#[unstable(feature = "f16", issue = "116909")]
|
||||||
|
@ -237,6 +247,16 @@ impl f16 {
|
||||||
/// the bit pattern of NaNs are conserved over arithmetic operations, the result of
|
/// the bit pattern of NaNs are conserved over arithmetic operations, the result of
|
||||||
/// `is_sign_negative` on a NaN might produce an unexpected result in some cases.
|
/// `is_sign_negative` on a NaN might produce an unexpected result in some cases.
|
||||||
/// See [explanation of NaN as a special value](f32) for more info.
|
/// See [explanation of NaN as a special value](f32) for more info.
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// #![feature(f16)]
|
||||||
|
///
|
||||||
|
/// let f = 7.0_f16;
|
||||||
|
/// let g = -7.0_f16;
|
||||||
|
///
|
||||||
|
/// assert!(!f.is_sign_negative());
|
||||||
|
/// assert!(g.is_sign_negative());
|
||||||
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[unstable(feature = "f16", issue = "116909")]
|
#[unstable(feature = "f16", issue = "116909")]
|
||||||
|
|
|
@ -1111,7 +1111,6 @@ impl f64 {
|
||||||
/// ```
|
/// ```
|
||||||
/// assert!((1f64).to_bits() != 1f64 as u64); // to_bits() is not casting!
|
/// assert!((1f64).to_bits() != 1f64 as u64); // to_bits() is not casting!
|
||||||
/// assert_eq!((12.5f64).to_bits(), 0x4029000000000000);
|
/// assert_eq!((12.5f64).to_bits(), 0x4029000000000000);
|
||||||
///
|
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "this returns the result of the operation, \
|
#[must_use = "this returns the result of the operation, \
|
||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
|
|
|
@ -7,5 +7,29 @@
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
|
#[cfg(not(test))]
|
||||||
|
use crate::intrinsics;
|
||||||
|
|
||||||
#[unstable(feature = "f128", issue = "116909")]
|
#[unstable(feature = "f128", issue = "116909")]
|
||||||
pub use core::f128::consts;
|
pub use core::f128::consts;
|
||||||
|
|
||||||
|
#[cfg(not(test))]
|
||||||
|
impl f128 {
|
||||||
|
/// Raises a number to an integer power.
|
||||||
|
///
|
||||||
|
/// Using this function is generally faster than using `powf`.
|
||||||
|
/// It might have a different sequence of rounding operations than `powf`,
|
||||||
|
/// so the results are not guaranteed to agree.
|
||||||
|
///
|
||||||
|
/// # Unspecified precision
|
||||||
|
///
|
||||||
|
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
|
||||||
|
/// can even differ within the same execution from one invocation to the next.
|
||||||
|
#[inline]
|
||||||
|
#[rustc_allow_incoherent_impl]
|
||||||
|
#[unstable(feature = "f128", issue = "116909")]
|
||||||
|
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||||
|
pub fn powi(self, n: i32) -> f128 {
|
||||||
|
unsafe { intrinsics::powif128(self, n) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -7,5 +7,29 @@
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
|
#[cfg(not(test))]
|
||||||
|
use crate::intrinsics;
|
||||||
|
|
||||||
#[unstable(feature = "f16", issue = "116909")]
|
#[unstable(feature = "f16", issue = "116909")]
|
||||||
pub use core::f16::consts;
|
pub use core::f16::consts;
|
||||||
|
|
||||||
|
#[cfg(not(test))]
|
||||||
|
impl f16 {
|
||||||
|
/// Raises a number to an integer power.
|
||||||
|
///
|
||||||
|
/// Using this function is generally faster than using `powf`.
|
||||||
|
/// It might have a different sequence of rounding operations than `powf`,
|
||||||
|
/// so the results are not guaranteed to agree.
|
||||||
|
///
|
||||||
|
/// # Unspecified precision
|
||||||
|
///
|
||||||
|
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
|
||||||
|
/// can even differ within the same execution from one invocation to the next.
|
||||||
|
#[inline]
|
||||||
|
#[rustc_allow_incoherent_impl]
|
||||||
|
#[unstable(feature = "f16", issue = "116909")]
|
||||||
|
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||||
|
pub fn powi(self, n: i32) -> f16 {
|
||||||
|
unsafe { intrinsics::powif16(self, n) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue