Merge branch 'master' of https://github.com/burrbull/libm
This commit is contained in:
commit
95138576c8
5 changed files with 54 additions and 6 deletions
|
|
@ -44,7 +44,6 @@ pub trait F32Ext {
|
|||
#[cfg(todo)]
|
||||
fn round(self) -> Self;
|
||||
|
||||
#[cfg(todo)]
|
||||
fn trunc(self) -> Self;
|
||||
|
||||
#[cfg(todo)]
|
||||
|
|
@ -162,7 +161,6 @@ impl F32Ext for f32 {
|
|||
roundf(self)
|
||||
}
|
||||
|
||||
#[cfg(todo)]
|
||||
#[inline]
|
||||
fn trunc(self) -> Self {
|
||||
truncf(self)
|
||||
|
|
@ -370,7 +368,6 @@ pub trait F64Ext {
|
|||
|
||||
fn round(self) -> Self;
|
||||
|
||||
#[cfg(todo)]
|
||||
fn trunc(self) -> Self;
|
||||
|
||||
#[cfg(todo)]
|
||||
|
|
@ -492,7 +489,6 @@ impl F64Ext for f64 {
|
|||
round(self)
|
||||
}
|
||||
|
||||
#[cfg(todo)]
|
||||
#[inline]
|
||||
fn trunc(self) -> Self {
|
||||
trunc(self)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ mod logf;
|
|||
mod expf;
|
||||
mod floor;
|
||||
mod cosf;
|
||||
mod trunc;
|
||||
mod truncf;
|
||||
|
||||
pub use self::{
|
||||
fabs::fabs,
|
||||
|
|
@ -30,6 +32,8 @@ pub use self::{
|
|||
expf::expf,
|
||||
floor::floor,
|
||||
cosf::cosf,
|
||||
trunc::trunc,
|
||||
truncf::truncf,
|
||||
};
|
||||
|
||||
mod sindf;
|
||||
|
|
|
|||
24
library/compiler-builtins/libm/src/math/trunc.rs
Normal file
24
library/compiler-builtins/libm/src/math/trunc.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
use core::f64;
|
||||
|
||||
#[inline]
|
||||
pub fn trunc(x: f64) -> f64 {
|
||||
let x1p120 = f64::from_bits(0x4770000000000000); // 0x1p120f === 2 ^ 120
|
||||
|
||||
let mut i: u64 = x.to_bits();
|
||||
let mut e: i64 = (i >> 52 & 0x7ff) as i64 - 0x3ff + 12;
|
||||
let m: u64;
|
||||
|
||||
if e >= 52 + 12 {
|
||||
return x;
|
||||
}
|
||||
if e < 12 {
|
||||
e = 1;
|
||||
}
|
||||
m = -1i64 as u64 >> e;
|
||||
if (i & m) == 0 {
|
||||
return x;
|
||||
}
|
||||
force_eval!(x + x1p120);
|
||||
i &= !m;
|
||||
f64::from_bits(i)
|
||||
}
|
||||
24
library/compiler-builtins/libm/src/math/truncf.rs
Normal file
24
library/compiler-builtins/libm/src/math/truncf.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
use core::f32;
|
||||
|
||||
#[inline]
|
||||
pub fn truncf(x: f32) -> f32 {
|
||||
let x1p120 = f32::from_bits(0x7b800000); // 0x1p120f === 2 ^ 120
|
||||
|
||||
let mut i: u32 = x.to_bits();
|
||||
let mut e: i32 = (i >> 23 & 0xff) as i32 - 0x7f + 9;
|
||||
let m: u32;
|
||||
|
||||
if e >= 23 + 9 {
|
||||
return x;
|
||||
}
|
||||
if e < 9 {
|
||||
e = 1;
|
||||
}
|
||||
m = -1i32 as u32 >> e;
|
||||
if (i & m) == 0 {
|
||||
return x;
|
||||
}
|
||||
force_eval!(x + x1p120);
|
||||
i &= !m;
|
||||
f32::from_bits(i)
|
||||
}
|
||||
|
|
@ -562,7 +562,7 @@ fn main() -> Result<(), Box<Error>> {
|
|||
f32_f32! {
|
||||
// acosf,
|
||||
// floorf,
|
||||
// truncf
|
||||
truncf,
|
||||
// asinf,
|
||||
// atanf,
|
||||
// cbrtf,
|
||||
|
|
@ -625,7 +625,7 @@ f64_f64! {
|
|||
// sqrt,
|
||||
// tan,
|
||||
// tanh,
|
||||
// trunc,
|
||||
trunc,
|
||||
fabs,
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue