-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Polyfill around rust floating point handling.
- Loading branch information
1 parent
354486e
commit 0fb10c2
Showing
7 changed files
with
60 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
pub(crate) trait FloatPolyfill { | ||
#[cfg(not(feature = "std"))] | ||
fn abs(self) -> Self; | ||
#[cfg(not(feature = "std"))] | ||
fn signum(self) -> Self; | ||
#[cfg(not(feature = "std"))] | ||
fn sqrt(self) -> Self; | ||
#[cfg(not(feature = "std"))] | ||
fn powi(self, n: i32) -> Self; | ||
#[cfg(not(feature = "std"))] | ||
fn exp(self) -> Self; | ||
} | ||
|
||
impl FloatPolyfill for f64 { | ||
#[cfg(not(feature = "std"))] | ||
fn abs(self) -> Self { | ||
libm::fabs(self) | ||
} | ||
|
||
#[cfg(not(feature = "std"))] | ||
fn signum(self) -> Self { | ||
if self < 0.0 { | ||
-1.0 | ||
} else if self > 0.0 { | ||
1.0 | ||
} else { | ||
0.0 | ||
} | ||
} | ||
|
||
#[cfg(not(feature = "std"))] | ||
fn sqrt(self) -> Self { | ||
libm::sqrt(self) | ||
} | ||
|
||
#[cfg(not(feature = "std"))] | ||
fn powi(self, n: i32) -> Self { | ||
libm::pow(self, n as f64) | ||
} | ||
|
||
#[cfg(not(feature = "std"))] | ||
fn exp(self) -> Self { | ||
libm::exp(self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters