From 7d80d3969ea006f97b8dc20091a375630fbd20a6 Mon Sep 17 00:00:00 2001 From: Alex Butler Date: Sat, 23 Nov 2019 13:25:02 +0000 Subject: [PATCH] Update libm -> 0.2.1 --- CHANGELOG.md | 3 +++ Cargo.toml | 2 +- src/lib.rs | 24 ++++++++++++++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed1a32e..97f8056 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 03204a2..6365797 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 55df885..58a529d 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 -- GitLab