Skip to content

Commit

Permalink
fix type errors due to libm crate not being generic
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz-meier committed Jan 10, 2023
1 parent 1f60e9a commit dde1217
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 27 deletions.
34 changes: 24 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,21 @@ autotests = true
autobenches = true

[package.metadata.docs.rs]
features = ["usize", "u32", "u64", "isize", "i32", "i64", "bigint", "biguint", "rational", "rational32", "rational64", "bigrational", "use_serde"]
features = [
"usize",
"u32",
"u64",
"isize",
"i32",
"i64",
"bigint",
"biguint",
"rational",
"rational32",
"rational64",
"bigrational",
"use_serde",
]

[package.metadata]
msrv = "1.43.0"
Expand All @@ -26,23 +40,23 @@ msrv = "1.43.0"
maintenance = { status = "actively-developed" }

[workspace]
members = [
"tests/feature_check",
"uom-macros",
"tests/edition_check",
]
members = ["tests/feature_check", "uom-macros", "tests/edition_check"]

[dependencies]
num-traits = { version = "0.2", default-features = false }
num-rational = { version = "0.4", optional = true, default-features = false }
num-bigint = { version = "0.4", optional = true, default-features = false, features = ["std"] }
num-complex = { version = "0.4", optional = true, default-features = false, features = ["std"] }
num-bigint = { version = "0.4", optional = true, default-features = false, features = [
"std",
] }
num-complex = { version = "0.4", optional = true, default-features = false, features = [
"std",
] }
serde = { version = "1.0", optional = true, default-features = false }
typenum = "1.13"

[dev-dependencies]
approx = "0.5"
libm = "0.2"
libm = { git = "https://github.com/moritz-meier/libm.git", branch = "feature/add-generic-helper" }
quickcheck = "1.0"
serde_json = "1.0"
static_assertions = "1.1"
Expand Down Expand Up @@ -87,7 +101,7 @@ rational-support = ["num-rational"]
bigint-support = ["num-bigint", "num-rational/num-bigint-std"]
complex-support = ["num-complex"]
# enable sin/cos for no_std builds, via libm
libm = [ "num-traits/libm" ]
libm = ["num-traits/libm"]

[[example]]
name = "base"
Expand Down
2 changes: 1 addition & 1 deletion src/si/angle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ mod tests {
#[allow(trivial_casts)]
fn atan2(y: V, x: V) -> bool {
let desired_value = if cfg!(feature = "libm"){
libm::atan2f(y, x)
libm::Libm::<V>::atan2(y, x)
} else {
y.atan2(x)
};
Expand Down
28 changes: 14 additions & 14 deletions src/si/ratio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ mod tests {
quickcheck! {
fn acos(x: V) -> bool {
let desired_value = if cfg!(feature = "libm") {
libm::acosf(x)
libm::Libm::<V>::acos(x)
} else {
x.acos()
};
Expand All @@ -242,7 +242,7 @@ mod tests {

fn acosh(x: V) -> bool {
let desired_value = if cfg!(feature = "libm") {
libm::acoshf(x)
libm::Libm::<V>::acosh(x)
} else {
x.acosh()
};
Expand All @@ -251,7 +251,7 @@ mod tests {

fn asin(x: V) -> bool {
let desired_value = if cfg!(feature = "libm") {
libm::asinf(x)
libm::Libm::<V>::asin(x)
} else {
x.asin()
};
Expand All @@ -260,7 +260,7 @@ mod tests {

fn asinh(x: V) -> bool {
let desired_value = if cfg!(feature = "libm") {
libm::asinhf(x)
libm::Libm::<V>::asinh(x)
} else {
x.asinh()
};
Expand All @@ -269,7 +269,7 @@ mod tests {

fn atan(x: V) -> bool {
let desired_value = if cfg!(feature = "libm") {
libm::atanf(x)
libm::Libm::<V>::atan(x)
} else {
x.atan()
};
Expand All @@ -278,7 +278,7 @@ mod tests {

fn atanh(x: V) -> bool {
let desired_value = if cfg!(feature = "libm") {
libm::atanhf(x)
libm::Libm::<V>::atanh(x)
} else {
x.atanh()
};
Expand All @@ -287,7 +287,7 @@ mod tests {

fn exp(x: V) -> bool {
let desired_value = if cfg!(feature = "libm"){
libm::expf(x)
libm::Libm::<V>::exp(x)
} else {
x.exp()
};
Expand All @@ -296,7 +296,7 @@ mod tests {

fn exp2(x: V) -> bool {
let desired_value = if cfg!(feature = "libm"){
libm::exp2f(x)
libm::Libm::<V>::exp2(x)
} else {
x.exp2()
};
Expand All @@ -305,7 +305,7 @@ mod tests {

fn ln(x: V) -> bool {
let desired_value = if cfg!(feature = "libm"){
libm::logf(x)
libm::Libm::<V>::log(x)
} else {
x.ln()
};
Expand All @@ -314,7 +314,7 @@ mod tests {

fn log(x: V, y: V) -> bool {
let desired_value = if cfg!(feature = "libm"){
libm::logf(x) / libm::logf(y)
libm::Libm::<V>::log(x) / libm::Libm::<V>::log(y)
} else {
x.log(y)
};
Expand All @@ -323,7 +323,7 @@ mod tests {

fn log2(x: V) -> bool {
let desired_value = if cfg!(feature = "libm"){
libm::log2f(x)
libm::Libm::<V>::log2(x)
} else {
x.log2()
};
Expand All @@ -332,7 +332,7 @@ mod tests {

fn log10(x: V) -> bool {
let desired_value = if cfg!(feature = "libm"){
libm::log10f(x)
libm::Libm::<V>::log10(x)
} else {
x.log10()
};
Expand All @@ -341,7 +341,7 @@ mod tests {

fn exp_m1(x: V) -> bool {
let desired_value = if cfg!(feature = "libm"){
libm::expm1f(x)
libm::Libm::<V>::expm1(x)
} else {
x.exp_m1()
};
Expand All @@ -350,7 +350,7 @@ mod tests {

fn ln_1p(x: V) -> bool {
let desired_value = if cfg!(feature = "libm"){
libm::log1pf(x)
libm::Libm::<V>::log1p(x)
} else {
x.ln_1p()
};
Expand Down
2 changes: 1 addition & 1 deletion src/tests/quantity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ mod float {
#[allow(trivial_casts)]
fn hypot_same(l: V, r: V) -> bool {
let desired_value = if cfg!(feature="libm") && ! cfg!(feature="std") {
libm::hypotf(l, r)
libm::Libm::<V>::hypot(l, r)
} else {
l.hypot(r)
};
Expand Down
2 changes: 1 addition & 1 deletion src/tests/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ mod float {
#[allow(trivial_casts)]
fn hypot(l: A<V>, r: A<V>) -> bool {
let desired_value = if cfg!(feature="libm"){
libm::hypotf(*l, *r)
libm::Libm::<V>::hypot(*l, *r)
} else {
l.hypot(*r)
};
Expand Down

0 comments on commit dde1217

Please sign in to comment.