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 fdim(self, rhs: Self) -> Self;
|
||||
|
||||
#[cfg(todo)]
|
||||
fn fract(self) -> Self;
|
||||
|
||||
@@ -155,6 +157,11 @@ impl F32Ext for f32 {
|
||||
truncf(self)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn fdim(self, rhs: Self) -> Self {
|
||||
fdimf(self, rhs)
|
||||
}
|
||||
|
||||
#[cfg(todo)]
|
||||
#[inline]
|
||||
fn fract(self) -> Self {
|
||||
@@ -353,6 +360,8 @@ pub trait F64Ext: private::Sealed {
|
||||
|
||||
fn trunc(self) -> Self;
|
||||
|
||||
fn fdim(self, rhs: Self) -> Self;
|
||||
|
||||
#[cfg(todo)]
|
||||
fn fract(self) -> Self;
|
||||
|
||||
@@ -468,6 +477,10 @@ impl F64Ext for f64 {
|
||||
trunc(self)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn fdim(self, rhs: Self) -> Self {
|
||||
fdim(self, rhs)
|
||||
}
|
||||
#[cfg(todo)]
|
||||
#[inline]
|
||||
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 super::isnanf;
|
||||
|
||||
#[inline]
|
||||
pub fn fmodf(x: f32, y: f32) -> f32 {
|
||||
let mut uxi = x.to_bits();
|
||||
@@ -11,7 +10,7 @@ pub fn fmodf(x: f32, y: f32) -> f32 {
|
||||
let sx = uxi & 0x80000000;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ mod exp;
|
||||
mod expf;
|
||||
mod fabs;
|
||||
mod fabsf;
|
||||
mod fdim;
|
||||
mod fdimf;
|
||||
mod floor;
|
||||
mod floorf;
|
||||
mod fmodf;
|
||||
@@ -44,6 +46,8 @@ pub use self::exp::exp;
|
||||
pub use self::expf::expf;
|
||||
pub use self::fabs::fabs;
|
||||
pub use self::fabsf::fabsf;
|
||||
pub use self::fdim::fdim;
|
||||
pub use self::fdimf::fdimf;
|
||||
pub use self::floor::floor;
|
||||
pub use self::floorf::floorf;
|
||||
pub use self::fmodf::fmodf;
|
||||
@@ -73,7 +77,3 @@ mod rem_pio2_large;
|
||||
mod 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user