dsp: move abs to lib.rs

This commit is contained in:
Matt Huszagh 2020-12-16 16:01:50 -08:00
parent e89db65722
commit 17f9f0750e
2 changed files with 14 additions and 11 deletions

View File

@ -2,23 +2,13 @@ use core::ops::{Add, Mul, Neg};
use serde::{Deserialize, Serialize};
use core::f32;
use super::abs;
// These are implemented here because core::f32 doesn't have them (yet).
// They are naive and don't handle inf/nan.
// `compiler-intrinsics`/llvm should have better (robust, universal, and
// 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
where
T: PartialOrd + Default + Neg<Output = T>,

View File

@ -1,6 +1,8 @@
#![cfg_attr(not(test), no_std)]
#![cfg_attr(feature = "nightly", feature(asm, core_intrinsics))]
use core::ops::Neg;
pub type Complex<T> = (T, T);
/// Round up half.
@ -18,6 +20,17 @@ pub fn shift_round(x: i32, shift: usize) -> i32 {
(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 cossin;
pub mod iir;