fdim
This commit is contained in:
parent
480531461c
commit
643287e1f1
6 changed files with 33 additions and 16 deletions
|
|
@ -363,6 +363,8 @@ pub trait F64Ext: private::Sealed {
|
|||
|
||||
fn trunc(self) -> Self;
|
||||
|
||||
fn fdim(self, rhs: Self) -> Self;
|
||||
|
||||
#[cfg(todo)]
|
||||
fn fract(self) -> Self;
|
||||
|
||||
|
|
@ -480,6 +482,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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
use super::isnanf;
|
||||
use core::f32;
|
||||
|
||||
pub fn fdimf(x: f32, y: f32) -> f32 {
|
||||
if isnanf(x) {
|
||||
if x.is_nan() {
|
||||
x
|
||||
} else if isnanf(y) {
|
||||
} else if y.is_nan() {
|
||||
y
|
||||
} else {
|
||||
if x > y {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ mod ceilf;
|
|||
mod expf;
|
||||
mod fabs;
|
||||
mod fabsf;
|
||||
mod fdim;
|
||||
mod fdimf;
|
||||
mod floor;
|
||||
mod floorf;
|
||||
|
|
@ -37,13 +38,9 @@ mod truncf;
|
|||
//mod service;
|
||||
|
||||
pub use self::{
|
||||
ceilf::ceilf, expf::expf, fabs::fabs, fabsf::fabsf, fdimf::fdimf, floor::floor, floorf::floorf,
|
||||
fmodf::fmodf, hypot::hypot, hypotf::hypotf, log::log, log10::log10, log10f::log10f,
|
||||
log1p::log1p, log1pf::log1pf, log2::log2, log2f::log2f, logf::logf, powf::powf, round::round,
|
||||
roundf::roundf, scalbn::scalbn, scalbnf::scalbnf, sqrt::sqrt, sqrtf::sqrtf, trunc::trunc,
|
||||
truncf::truncf,
|
||||
ceilf::ceilf, expf::expf, fabs::fabs, fabsf::fabsf, fdim::fdim, fdimf::fdimf, floor::floor,
|
||||
floorf::floorf, fmodf::fmodf, hypot::hypot, hypotf::hypotf, log::log, log10::log10,
|
||||
log10f::log10f, log1p::log1p, log1pf::log1pf, log2::log2, log2f::log2f, logf::logf, powf::powf,
|
||||
round::round, roundf::roundf, scalbn::scalbn, scalbnf::scalbnf, sqrt::sqrt, sqrtf::sqrtf,
|
||||
trunc::trunc, truncf::truncf,
|
||||
};
|
||||
|
||||
fn isnanf(x: f32) -> bool {
|
||||
x.to_bits() & 0x7fffffff > 0x7f800000
|
||||
}
|
||||
|
|
|
|||
|
|
@ -724,7 +724,7 @@ f64_f64! {
|
|||
// With signature `fn(f64, f64) -> f64`
|
||||
f64f64_f64! {
|
||||
// atan2,
|
||||
// fdim,
|
||||
fdim,
|
||||
// fmod,
|
||||
hypot,
|
||||
// pow,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue