Skip to content

Commit

Permalink
INCOMPLETE: Directly reference num sub-crates.
Browse files Browse the repository at this point in the history
Resolves #57.
  • Loading branch information
iliekturtles committed Mar 16, 2018
1 parent eb2ec08 commit 5941c90
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 20 deletions.
41 changes: 23 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ coveralls = { repository = "iliekturtles/uom" }
maintenance = { status = "actively-developed" }

[dependencies]
num = "0.1"
num-traits = { version = "0.2", default-features = false }
num-rational = { version = "0.1", optional = true, default-features = false }
num-bigint = { version = "0.1", optional = true, default-features = false }
serde = { version = "1.0", optional = true, default-features = false }
typenum = "1.9.0"

Expand All @@ -33,31 +35,34 @@ static_assertions = "0.2.5"

[features]
default = ["f32", "f64", "si", "std"]
usize = []
u8 = []
u16 = []
u32 = []
u64 = []
isize = []
i8 = []
i16 = []
i32 = []
i64 = []
bigint = []
biguint = []
rational = []
rational32 = []
rational64 = []
bigrational = []
usize = ["rational-support"]
u8 = ["rational-support"]
u16 = ["rational-support"]
u32 = ["rational-support"]
u64 = ["rational-support"]
isize = ["rational-support"]
i8 = ["rational-support"]
i16 = ["rational-support"]
i32 = ["rational-support"]
i64 = ["rational-support"]
bigint = ["bigint-support"]
biguint = ["bigint-support"]
rational = ["rational-support"]
rational32 = ["rational-support"]
rational64 = ["rational-support"]
bigrational = ["bigint-support"]
f32 = []
f64 = []
si = []
std = []
std = ["num-traits/std"]
# The `use_serde` feature exists so that, in the future, other dependency features like num/serde
# can be added. However, num/serde is currently left out because it has not yet been updated to
# Serde 1.0. It is also necessary to name the feature something other than `serde` because of a
# cargo bug: https://github.com/rust-lang/cargo/issues/1286
use_serde = ["serde"]
# Internal features to include appropriate num-* crates.
rational-support = ["num-rational"]
bigint-support = ["num-bigint", "num-rational/bigint"]

[[example]]
name = "base"
Expand Down
38 changes: 36 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,15 @@ compile_error!("A least one underlying storage type must be enabled. See the fea
uom documentation for available underlying storage type options.");

#[doc(hidden)]
pub extern crate num;
pub extern crate num_traits;

#[doc(hidden)]
#[cfg(feature = "bigint-support")]
pub extern crate num_bigint;

#[doc(hidden)]
#[cfg(any(feature = "rational-support", feature = "bigint-support"))]
pub extern crate num_rational;

#[doc(hidden)]
#[cfg(feature = "serde")]
Expand Down Expand Up @@ -210,6 +218,31 @@ pub mod lib {
}
}

// Conditionally import num sub-crate types based on feature selection.
#[doc(hidden)]
pub mod num {
#[cfg(not(feature = "std"))]
pub use num_traits::float::FloatCore as Float;
#[cfg(feature = "std")]
pub use num_traits::float::Float;

pub use num_traits::{FromPrimitive, Num, One, pow, Saturating, Signed, Zero};

#[cfg(feature = "bigint-support")]
pub use num_bigint::{BigInt, BigUint};

#[cfg(feature = "rational-support")]
pub use num_rational::Rational;

#[cfg(feature = "bigint-support")]
pub use num_rational::BigRational;

#[cfg(any(feature = "rational-support", feature = "bigint-support"))]
pub mod rational {
pub use num_rational::*;
}
}

#[macro_use]
mod storage_types;

Expand Down Expand Up @@ -288,7 +321,8 @@ storage_types! {
impl ::ConversionFactor<V> for V {
#[inline(always)]
fn powi(self, e: i32) -> Self {
self.powi(e)
//<V as ::num::Float>::powi(self, e)
V::powi(self, e)
}

#[inline(always)]
Expand Down
1 change: 1 addition & 0 deletions src/si/length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ where
V: ::num::Float + ::Conversion<V>,
{
/// Calculates the length of the hypotenuse of a right-angle triangle given the legs.
#[cfg(feature = "std")]
#[inline(always)]
pub fn hypot(self, other: Self) -> Self {
Length {
Expand Down
3 changes: 3 additions & 0 deletions src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ macro_rules! system {
/// // error[E0271]: type mismatch resolving ...
/// let r = Area::new::<square_meter>(8.0).cbrt();
/// ```
#[cfg(feature = "std")]
#[inline(always)]
pub fn cbrt(
self
Expand Down Expand Up @@ -595,6 +596,7 @@ macro_rules! system {
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding error.
/// This produces a more accurate result with better performance than a separate
/// multiplication operation followed by an add.
#[cfg(feature = "std")]
#[inline(always)]
pub fn mul_add<Da, Ua, Ub>(
self,
Expand Down Expand Up @@ -682,6 +684,7 @@ macro_rules! system {
/// // error[E0271]: type mismatch resolving ...
/// let r = Length::new::<meter>(4.0).sqrt();
/// ```
#[cfg(feature = "std")]
#[inline(always)]
pub fn sqrt(
self
Expand Down

0 comments on commit 5941c90

Please sign in to comment.