diff --git a/CHANGELOG.md b/CHANGELOG.md index ed1a32e0c174d094c0e1999c89193650e1faab13..97f8056a3723d4c0c2f863ae7b51e211894ba41d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## Unreleased +* Update libm -> `0.2.1`. + ## 0.3 * Support no-std usage by disabling new default feature `std`. ```rust diff --git a/Cargo.toml b/Cargo.toml index 03204a29b2b72fe3e63b821ae5e610ab4d114761..6365797849600295aa2bcd7f058918f58b525b6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ exclude = ["/fonts/**"] [dependencies] byteorder = { version = "1.1", default-features = false } -libm = { version = "0.1.4", optional = true } +libm = { version = "0.2.1", optional = true } [features] default = ["std"] diff --git a/src/lib.rs b/src/lib.rs index 55df885e8a9d06bccb9be8f26bd44b2ee9c6f5d3..58a529dcc30175b5c4a21698aeddf31ce8586d10 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,12 +11,32 @@ extern crate alloc; use alloc::vec::Vec; use byteorder::{BigEndian as BE, ByteOrder}; use core::ops::Deref; -#[cfg(all(feature = "libm", not(feature = "std")))] -use libm::F32Ext; #[cfg(not(any(feature = "libm", feature = "std")))] compile_error!("You need to activate either the `std` or `libm` feature."); +#[cfg(all(feature = "libm", not(feature = "std")))] +trait FloatExt { + fn floor(self) -> Self; + fn ceil(self) -> Self; + fn sqrt(self) -> Self; +} +#[cfg(all(feature = "libm", not(feature = "std")))] +impl FloatExt for f32 { + #[inline] + fn floor(self) -> Self { + libm::floorf(self) + } + #[inline] + fn ceil(self) -> Self { + libm::ceilf(self) + } + #[inline] + fn sqrt(self) -> Self { + libm::sqrtf(self) + } +} + #[derive(Copy, Clone, Debug)] pub struct FontInfo> { data: Data, // pointer to .ttf file