Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dasp_sample/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//! are based.

#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(core_intrinsics))]

#[cfg(not(feature = "std"))]
extern crate alloc;
Expand Down
12 changes: 10 additions & 2 deletions dasp_sample/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ pub mod f32 {

#[cfg(not(feature = "std"))]
pub fn sqrt(x: f32) -> f32 {
unsafe { core::intrinsics::sqrtf32(x) }
if x >= 0.0 {
f32::from_bits((x.to_bits() + 0x3f80_0000) >> 1)
} else {
f32::NAN
}
}
#[cfg(feature = "std")]
pub fn sqrt(x: f32) -> f32 {
Expand All @@ -18,7 +22,11 @@ pub mod f64 {

#[cfg(not(feature = "std"))]
pub fn sqrt(x: f64) -> f64 {
unsafe { core::intrinsics::sqrtf64(x) }
if x >= 0.0 {
f64::from_bits((x.to_bits() + 0x3f80_0000) >> 1)
} else {
f64::NAN
}
}
#[cfg(feature = "std")]
pub fn sqrt(x: f64) -> f64 {
Expand Down