Skip to content

Commit

Permalink
feat: add soft-float feature to optionally enable soft-float
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardosm committed Sep 17, 2024
1 parent 7cf53d4 commit fa71e8c
Show file tree
Hide file tree
Showing 40 changed files with 103 additions and 9 deletions.
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ keywords = ["float", "floating-point", "math"]
categories = ["science", "no-std", "mathematics"]
publish = false

[package.metadata.docs.rs]
features = ["soft-float"]

[features]
default = []
soft-float = ["dep:rustc_apfloat"]

[dependencies]
rustc_apfloat = "0.2.1"
rustc_apfloat = { optional = true, version = "0.2.1" }

[workspace]
members = [
Expand Down
12 changes: 7 additions & 5 deletions ci/build-and-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,28 @@ begin_group "Fetch dependencies"
cargo fetch --locked
end_group

features=(--features "soft-float")

begin_group "Build"
cargo build --workspace --all-targets --frozen
cargo build --frozen --workspace "${features[@]}" --all-targets
end_group

begin_group "Doc"
cargo doc --workspace --frozen
cargo doc --frozen --workspace "${features[@]}"
end_group

begin_group "Generate test data"
./run-all-test-data-gen.sh
end_group

begin_group "Test x86_64"
cargo test --workspace --target x86_64-unknown-linux-gnu --frozen
cargo test --frozen --workspace "${features[@]}" --target x86_64-unknown-linux-gnu
end_group

begin_group "Test i586 debug"
cargo test --workspace --target i586-unknown-linux-gnu --frozen
cargo test --frozen --workspace "${features[@]}" --target i586-unknown-linux-gnu
end_group

begin_group "Test i586 release"
cargo test --workspace --target i586-unknown-linux-gnu --release --frozen
cargo test --frozen --workspace "${features[@]}" --target i586-unknown-linux-gnu --release
end_group
12 changes: 10 additions & 2 deletions ci/clippy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ begin_group "Fetch dependencies"
cargo fetch --locked
end_group

begin_group "Run clippy"
cargo clippy --workspace --all-targets --frozen -- -D warnings
begin_group "Run clippy workspace"
cargo clippy --frozen --workspace --all-targets -- -D warnings
end_group

begin_group "Run clippy fpmath without soft-float"
cargo clippy --frozen -p fpmath --all-targets -- -D warnings
end_group

begin_group "Run clippy fpmath with soft-float"
cargo clippy --frozen -p fpmath --all-targets --features "soft-float" -- -D warnings
end_group
2 changes: 2 additions & 0 deletions src/generic/acosh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ mod tests {
test::<f32>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f32() {
test::<crate::SoftF32>();
Expand All @@ -88,6 +89,7 @@ mod tests {
test::<f64>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f64() {
test::<crate::SoftF64>();
Expand Down
2 changes: 2 additions & 0 deletions src/generic/asin_acos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ mod tests {
test_acos::<f32>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f32() {
test_asin::<crate::SoftF32>();
Expand All @@ -194,6 +195,7 @@ mod tests {
test_acos::<f64>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f64() {
test_asin::<crate::SoftF64>();
Expand Down
2 changes: 2 additions & 0 deletions src/generic/asind_acosd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ mod tests {
test_acosd::<f32>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f32() {
test_asind::<crate::SoftF32>();
Expand All @@ -102,6 +103,7 @@ mod tests {
test_acosd::<f64>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f64() {
test_asind::<crate::SoftF64>();
Expand Down
2 changes: 2 additions & 0 deletions src/generic/asinh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ mod tests {
test::<f32>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f32() {
test::<crate::SoftF32>();
Expand All @@ -78,6 +79,7 @@ mod tests {
test::<f64>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f64() {
test::<crate::SoftF64>();
Expand Down
2 changes: 2 additions & 0 deletions src/generic/asinpi_acospi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ mod tests {
test_acospi::<f32>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f32() {
test_asinpi::<crate::SoftF32>();
Expand All @@ -113,6 +114,7 @@ mod tests {
test_acospi::<f64>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f64() {
test_asinpi::<crate::SoftF64>();
Expand Down
2 changes: 2 additions & 0 deletions src/generic/atan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ mod tests {
test_atan2::<f32>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f32() {
test_atan::<crate::SoftF32>();
Expand All @@ -252,6 +253,7 @@ mod tests {
test_atan2::<f64>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f64() {
test_atan::<crate::SoftF64>();
Expand Down
2 changes: 2 additions & 0 deletions src/generic/atand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ mod tests {
test_atan2d::<f32>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f32() {
test_atand::<crate::SoftF32>();
Expand All @@ -173,6 +174,7 @@ mod tests {
test_atan2d::<f64>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f64() {
test_atand::<crate::SoftF64>();
Expand Down
2 changes: 2 additions & 0 deletions src/generic/atanh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ mod tests {
test::<f32>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f32() {
test::<crate::SoftF32>();
Expand All @@ -87,6 +88,7 @@ mod tests {
test::<f64>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f64() {
test::<crate::SoftF64>();
Expand Down
2 changes: 2 additions & 0 deletions src/generic/atanpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ mod tests {
test_atan2pi::<f32>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f32() {
test_atanpi::<crate::SoftF32>();
Expand All @@ -183,6 +184,7 @@ mod tests {
test_atan2pi::<f64>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f64() {
test_atanpi::<crate::SoftF64>();
Expand Down
2 changes: 2 additions & 0 deletions src/generic/cbrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ mod tests {
test::<f32>(0x80..=0xFF, core::iter::empty(), core::iter::empty());
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f32() {
test::<crate::SoftF32>(0x80..=0xFF, core::iter::empty(), core::iter::empty());
Expand All @@ -153,6 +154,7 @@ mod tests {
test::<f64>(0x100..=0x1FF, [-340, 0, 340].into_iter(), 0x10000..=0x1FFFF);
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f64() {
test::<crate::SoftF64>(0x100..=0x1FF, [-340, 0, 340].into_iter(), 0x10000..=0x1FFFF);
Expand Down
2 changes: 2 additions & 0 deletions src/generic/ceil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ mod tests {
test::<f32>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f32() {
test::<crate::SoftF32>();
Expand All @@ -77,6 +78,7 @@ mod tests {
test::<f64>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f64() {
test::<crate::SoftF64>();
Expand Down
2 changes: 2 additions & 0 deletions src/generic/exp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ mod tests {
test_exp_m1::<f32>("-87.9", "88.9");
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f32() {
test_exp::<crate::SoftF32>("-103.99", "88.9");
Expand All @@ -210,6 +211,7 @@ mod tests {
test_exp_m1::<f64>("-708.9", "709.9");
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f64() {
test_exp::<crate::SoftF64>("-745.9", "709.9");
Expand Down
2 changes: 2 additions & 0 deletions src/generic/exp10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ mod tests {
test::<f32>("-45.9", "38.9");
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f32() {
test::<crate::SoftF32>("-45.9", "38.9");
Expand All @@ -112,6 +113,7 @@ mod tests {
test::<f64>("-323.9", "308.9");
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f64() {
test::<crate::SoftF64>("-323.9", "308.9");
Expand Down
2 changes: 2 additions & 0 deletions src/generic/exp2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ mod tests {
test::<f32>("-150", "128");
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f32() {
test::<crate::SoftF32>("-150", "128");
Expand All @@ -114,6 +115,7 @@ mod tests {
test::<f64>("-1075", "1024");
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f64() {
test::<crate::SoftF64>("-1075", "1024");
Expand Down
2 changes: 2 additions & 0 deletions src/generic/floor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ mod tests {
test::<f32>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f32() {
test::<crate::SoftF32>();
Expand All @@ -77,6 +78,7 @@ mod tests {
test::<f64>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f64() {
test::<crate::SoftF64>();
Expand Down
2 changes: 2 additions & 0 deletions src/generic/frexp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ mod tests {
test::<f32>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f32() {
test::<crate::SoftF32>();
Expand All @@ -85,6 +86,7 @@ mod tests {
test::<f64>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f64() {
test::<crate::SoftF64>();
Expand Down
2 changes: 2 additions & 0 deletions src/generic/hypot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ mod tests {
test::<f32>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f32() {
test::<crate::SoftF32>();
Expand All @@ -118,6 +119,7 @@ mod tests {
test::<f64>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f64() {
test::<crate::SoftF64>();
Expand Down
2 changes: 2 additions & 0 deletions src/generic/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ mod tests {
test_log_1p::<f32>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f32() {
test_log::<crate::SoftF32>();
Expand All @@ -243,6 +244,7 @@ mod tests {
test_log_1p::<f64>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f64() {
test_log::<crate::SoftF64>();
Expand Down
2 changes: 2 additions & 0 deletions src/generic/log10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ mod tests {
test::<f32>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f32() {
test::<crate::SoftF32>();
Expand All @@ -105,6 +106,7 @@ mod tests {
test::<f64>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f64() {
test::<crate::SoftF64>();
Expand Down
2 changes: 2 additions & 0 deletions src/generic/log2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ mod tests {
test::<f32>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f32() {
test::<crate::SoftF32>();
Expand All @@ -98,6 +99,7 @@ mod tests {
test::<f64>();
}

#[cfg(feature = "soft-float")]
#[test]
fn test_soft_f64() {
test::<crate::SoftF64>();
Expand Down
Loading

0 comments on commit fa71e8c

Please sign in to comment.