dsp: move abs to lib.rs
This commit is contained in:
parent
e89db65722
commit
17f9f0750e
|
@ -2,23 +2,13 @@ use core::ops::{Add, Mul, Neg};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use core::f32;
|
use core::f32;
|
||||||
|
use super::abs;
|
||||||
|
|
||||||
// These are implemented here because core::f32 doesn't have them (yet).
|
// These are implemented here because core::f32 doesn't have them (yet).
|
||||||
// They are naive and don't handle inf/nan.
|
// They are naive and don't handle inf/nan.
|
||||||
// `compiler-intrinsics`/llvm should have better (robust, universal, and
|
// `compiler-intrinsics`/llvm should have better (robust, universal, and
|
||||||
// faster) implementations.
|
// faster) implementations.
|
||||||
|
|
||||||
fn abs<T>(x: T) -> T
|
|
||||||
where
|
|
||||||
T: PartialOrd + Default + Neg<Output = T>,
|
|
||||||
{
|
|
||||||
if x >= T::default() {
|
|
||||||
x
|
|
||||||
} else {
|
|
||||||
-x
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn copysign<T>(x: T, y: T) -> T
|
fn copysign<T>(x: T, y: T) -> T
|
||||||
where
|
where
|
||||||
T: PartialOrd + Default + Neg<Output = T>,
|
T: PartialOrd + Default + Neg<Output = T>,
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#![cfg_attr(not(test), no_std)]
|
#![cfg_attr(not(test), no_std)]
|
||||||
#![cfg_attr(feature = "nightly", feature(asm, core_intrinsics))]
|
#![cfg_attr(feature = "nightly", feature(asm, core_intrinsics))]
|
||||||
|
|
||||||
|
use core::ops::Neg;
|
||||||
|
|
||||||
pub type Complex<T> = (T, T);
|
pub type Complex<T> = (T, T);
|
||||||
|
|
||||||
/// Round up half.
|
/// Round up half.
|
||||||
|
@ -18,6 +20,17 @@ pub fn shift_round(x: i32, shift: usize) -> i32 {
|
||||||
(x + (1 << (shift - 1))) >> shift
|
(x + (1 << (shift - 1))) >> shift
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn abs<T>(x: T) -> T
|
||||||
|
where
|
||||||
|
T: PartialOrd + Default + Neg<Output = T>,
|
||||||
|
{
|
||||||
|
if x >= T::default() {
|
||||||
|
x
|
||||||
|
} else {
|
||||||
|
-x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub mod atan2;
|
pub mod atan2;
|
||||||
pub mod cossin;
|
pub mod cossin;
|
||||||
pub mod iir;
|
pub mod iir;
|
||||||
|
|
Loading…
Reference in New Issue