Skip to content

Commit

Permalink
Check std feature instead of libm, run no_std builds
Browse files Browse the repository at this point in the history
  • Loading branch information
ajtribick committed Apr 6, 2023
1 parent 3cfcfa6 commit a077932
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ jobs:
fail-fast: false
matrix:
rust: [stable, nightly]
features:
- std,math_funcs,serde
- math_funcs
platform:
- target: x86_64-pc-windows-msvc
os: windows-latest
Expand All @@ -35,7 +38,6 @@ jobs:
RUST_BACKTRACE: 1
CARGO_INCREMENTAL: 0
CARGO_TERM_COLOR: always
OPTIONS: --all-features
RUSTFLAGS: "-C debuginfo=0 --deny warnings"

runs-on: ${{ matrix.platform.os }}
Expand Down Expand Up @@ -63,14 +65,18 @@ jobs:
- name: Build tests
shell: bash
run: |
cargo test --no-run --verbose --target ${{ matrix.platform.target }} $OPTIONS
cargo test --no-run --verbose --target ${{ matrix.platform.target }} \
--no-default-features --features=${{ matrix.features }}
- name: Run tests
shell: bash
run: |
cargo test --verbose --target ${{ matrix.platform.target }} $OPTIONS
cargo test --verbose --target ${{ matrix.platform.target }} \
--no-default-features --features=${{ matrix.features }}
- name: Run clippy
shell: bash
run: |
cargo clippy --target ${{ matrix.platform.target }} $OPTIONS -- -Dwarnings
cargo clippy --target ${{ matrix.platform.target }} \
--no-default-features --features=${{ matrix.features }} \
-- -Dwarnings
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ std = ["num-traits/std"]

[dependencies]
hexf = "0.2"
libm = { version = "0.2.6", optional = true }
libm = { version = "0.2.6" }
num-traits = { version = "0.2.14", default-features = false }
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }

Expand Down
11 changes: 9 additions & 2 deletions src/math_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
///
/// It uses "libm" if it's enabled, which is required for "no_std".
/// Fallbacks to "std" otherwise.
#[cfg(feature = "libm")]
#[cfg(not(feature = "std"))]
pub(crate) mod mathfn {
#[inline(always)]
pub fn abs(x: f64) -> f64 {
Expand Down Expand Up @@ -42,7 +42,7 @@ pub(crate) mod mathfn {
}
}

#[cfg(not(feature = "libm"))]
#[cfg(feature = "std")]
pub(crate) mod mathfn {
#[inline(always)]
pub fn abs(x: f64) -> f64 {
Expand All @@ -60,10 +60,17 @@ pub(crate) mod mathfn {
pub fn floor(x: f64) -> f64 {
x.floor()
}
#[cfg(not(all(windows, target_env = "gnu")))]
#[inline(always)]
pub fn fma(a: f64, b: f64, c: f64) -> f64 {
a.mul_add(b, c)
}
// The built-in FMA on MinGW is inaccurate, so always use the libm version
#[cfg(all(windows, target_env = "gnu"))]
#[inline(always)]
pub fn fma(a: f64, b: f64, c: f64) -> f64 {
libm::fma(a, b, c)
}
#[inline(always)]
pub fn fract(x: f64) -> f64 {
x.fract()
Expand Down

0 comments on commit a077932

Please sign in to comment.