Merge rust-lang/libm#93
93: fdimf r=japaric a=jackmott closes rust-lang/libm#47 Co-authored-by: Jack Mott <jack.mott@gmail.com>
This commit is contained in:
@@ -42,6 +42,8 @@ pub trait F32Ext: private::Sealed {
|
|||||||
|
|
||||||
fn trunc(self) -> Self;
|
fn trunc(self) -> Self;
|
||||||
|
|
||||||
|
fn fdim(self, rhs: Self) -> Self;
|
||||||
|
|
||||||
#[cfg(todo)]
|
#[cfg(todo)]
|
||||||
fn fract(self) -> Self;
|
fn fract(self) -> Self;
|
||||||
|
|
||||||
@@ -155,6 +157,11 @@ impl F32Ext for f32 {
|
|||||||
truncf(self)
|
truncf(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn fdim(self, rhs: Self) -> Self {
|
||||||
|
fdimf(self, rhs)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(todo)]
|
#[cfg(todo)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn fract(self) -> Self {
|
fn fract(self) -> Self {
|
||||||
@@ -353,6 +360,8 @@ pub trait F64Ext: private::Sealed {
|
|||||||
|
|
||||||
fn trunc(self) -> Self;
|
fn trunc(self) -> Self;
|
||||||
|
|
||||||
|
fn fdim(self, rhs: Self) -> Self;
|
||||||
|
|
||||||
#[cfg(todo)]
|
#[cfg(todo)]
|
||||||
fn fract(self) -> Self;
|
fn fract(self) -> Self;
|
||||||
|
|
||||||
@@ -468,6 +477,10 @@ impl F64Ext for f64 {
|
|||||||
trunc(self)
|
trunc(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn fdim(self, rhs: Self) -> Self {
|
||||||
|
fdim(self, rhs)
|
||||||
|
}
|
||||||
#[cfg(todo)]
|
#[cfg(todo)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn fract(self) -> Self {
|
fn fract(self) -> Self {
|
||||||
|
|||||||
15
library/compiler-builtins/libm/src/math/fdim.rs
Normal file
15
library/compiler-builtins/libm/src/math/fdim.rs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
use core::f64;
|
||||||
|
|
||||||
|
pub fn fdim(x: f64, y: f64) -> f64 {
|
||||||
|
if x.is_nan() {
|
||||||
|
x
|
||||||
|
} else if y.is_nan() {
|
||||||
|
y
|
||||||
|
} else {
|
||||||
|
if x > y {
|
||||||
|
x - y
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
library/compiler-builtins/libm/src/math/fdimf.rs
Normal file
15
library/compiler-builtins/libm/src/math/fdimf.rs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
use core::f32;
|
||||||
|
|
||||||
|
pub fn fdimf(x: f32, y: f32) -> f32 {
|
||||||
|
if x.is_nan() {
|
||||||
|
x
|
||||||
|
} else if y.is_nan() {
|
||||||
|
y
|
||||||
|
} else {
|
||||||
|
if x > y {
|
||||||
|
x - y
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
|
use core::f32;
|
||||||
use core::u32;
|
use core::u32;
|
||||||
|
|
||||||
use super::isnanf;
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn fmodf(x: f32, y: f32) -> f32 {
|
pub fn fmodf(x: f32, y: f32) -> f32 {
|
||||||
let mut uxi = x.to_bits();
|
let mut uxi = x.to_bits();
|
||||||
@@ -11,7 +10,7 @@ pub fn fmodf(x: f32, y: f32) -> f32 {
|
|||||||
let sx = uxi & 0x80000000;
|
let sx = uxi & 0x80000000;
|
||||||
let mut i;
|
let mut i;
|
||||||
|
|
||||||
if uyi << 1 == 0 || isnanf(y) || ex == 0xff {
|
if uyi << 1 == 0 || y.is_nan() || ex == 0xff {
|
||||||
return (x * y) / (x * y);
|
return (x * y) / (x * y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ mod exp;
|
|||||||
mod expf;
|
mod expf;
|
||||||
mod fabs;
|
mod fabs;
|
||||||
mod fabsf;
|
mod fabsf;
|
||||||
|
mod fdim;
|
||||||
|
mod fdimf;
|
||||||
mod floor;
|
mod floor;
|
||||||
mod floorf;
|
mod floorf;
|
||||||
mod fmodf;
|
mod fmodf;
|
||||||
@@ -44,6 +46,8 @@ pub use self::exp::exp;
|
|||||||
pub use self::expf::expf;
|
pub use self::expf::expf;
|
||||||
pub use self::fabs::fabs;
|
pub use self::fabs::fabs;
|
||||||
pub use self::fabsf::fabsf;
|
pub use self::fabsf::fabsf;
|
||||||
|
pub use self::fdim::fdim;
|
||||||
|
pub use self::fdimf::fdimf;
|
||||||
pub use self::floor::floor;
|
pub use self::floor::floor;
|
||||||
pub use self::floorf::floorf;
|
pub use self::floorf::floorf;
|
||||||
pub use self::fmodf::fmodf;
|
pub use self::fmodf::fmodf;
|
||||||
@@ -73,7 +77,3 @@ mod rem_pio2_large;
|
|||||||
mod rem_pio2f;
|
mod rem_pio2f;
|
||||||
|
|
||||||
use self::{k_cosf::k_cosf, k_sinf::k_sinf, rem_pio2_large::rem_pio2_large, rem_pio2f::rem_pio2f};
|
use self::{k_cosf::k_cosf, k_sinf::k_sinf, rem_pio2_large::rem_pio2_large, rem_pio2f::rem_pio2f};
|
||||||
|
|
||||||
fn isnanf(x: f32) -> bool {
|
|
||||||
x.to_bits() & 0x7fffffff > 0x7f800000
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -662,7 +662,6 @@ f32_f32! {
|
|||||||
// coshf,
|
// coshf,
|
||||||
// exp2f,
|
// exp2f,
|
||||||
expf,
|
expf,
|
||||||
// fdimf,
|
|
||||||
log10f,
|
log10f,
|
||||||
log1pf,
|
log1pf,
|
||||||
log2f,
|
log2f,
|
||||||
@@ -679,6 +678,7 @@ f32_f32! {
|
|||||||
// With signature `fn(f32, f32) -> f32`
|
// With signature `fn(f32, f32) -> f32`
|
||||||
f32f32_f32! {
|
f32f32_f32! {
|
||||||
// atan2f,
|
// atan2f,
|
||||||
|
fdimf,
|
||||||
hypotf,
|
hypotf,
|
||||||
fmodf,
|
fmodf,
|
||||||
powf,
|
powf,
|
||||||
@@ -724,7 +724,7 @@ f64_f64! {
|
|||||||
// With signature `fn(f64, f64) -> f64`
|
// With signature `fn(f64, f64) -> f64`
|
||||||
f64f64_f64! {
|
f64f64_f64! {
|
||||||
// atan2,
|
// atan2,
|
||||||
// fdim,
|
fdim,
|
||||||
// fmod,
|
// fmod,
|
||||||
hypot,
|
hypot,
|
||||||
// pow,
|
// pow,
|
||||||
|
|||||||
Reference in New Issue
Block a user