Skip to content

Commit

Permalink
Add a compilation error if neither std nor libm features are spec…
Browse files Browse the repository at this point in the history
…ified (#595)
  • Loading branch information
LikeLakers2 authored Jan 9, 2025
1 parent e8a53c6 commit 717f05d
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 4 deletions.
84 changes: 82 additions & 2 deletions src/f32/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ mod libm_math {
}
}

#[cfg(not(feature = "libm"))]
#[cfg(all(not(feature = "libm"), feature = "std"))]
mod std_math {
#[inline(always)]
pub(crate) fn abs(f: f32) -> f32 {
Expand Down Expand Up @@ -234,8 +234,88 @@ mod std_math {
}
}

// Used to reduce the number of compilation errors, in the event that no other
// math backend is specified.
#[cfg(all(not(feature = "libm"), not(feature = "std")))]
mod no_backend_math {
pub(crate) fn abs(_: f32) -> f32 {
unimplemented!()
}

pub(crate) fn acos_approx(_: f32) -> f32 {
unimplemented!()
}

pub(crate) fn atan2(_: f32, _: f32) -> f32 {
unimplemented!()
}

pub(crate) fn sin(_: f32) -> f32 {
unimplemented!()
}

pub(crate) fn sin_cos(_: f32) -> (f32, f32) {
unimplemented!()
}

pub(crate) fn tan(_: f32) -> f32 {
unimplemented!()
}

pub(crate) fn sqrt(_: f32) -> f32 {
unimplemented!()
}

pub(crate) fn copysign(_: f32, _: f32) -> f32 {
unimplemented!()
}

pub(crate) fn signum(_: f32) -> f32 {
unimplemented!()
}

pub(crate) fn round(_: f32) -> f32 {
unimplemented!()
}

pub(crate) fn trunc(_: f32) -> f32 {
unimplemented!()
}

pub(crate) fn ceil(_: f32) -> f32 {
unimplemented!()
}

pub(crate) fn floor(_: f32) -> f32 {
unimplemented!()
}

pub(crate) fn exp(_: f32) -> f32 {
unimplemented!()
}

pub(crate) fn powf(_: f32, _: f32) -> f32 {
unimplemented!()
}

pub(crate) fn mul_add(_: f32, _: f32, _: f32) -> f32 {
unimplemented!()
}

pub fn div_euclid(_: f32, _: f32) -> f32 {
unimplemented!()
}

pub fn rem_euclid(_: f32, _: f32) -> f32 {
unimplemented!()
}
}

#[cfg(feature = "libm")]
pub(crate) use libm_math::*;

#[cfg(not(feature = "libm"))]
#[cfg(all(not(feature = "libm"), feature = "std"))]
pub(crate) use std_math::*;

#[cfg(all(not(feature = "libm"), not(feature = "std")))]
pub(crate) use no_backend_math::*;
84 changes: 82 additions & 2 deletions src/f64/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ mod libm_math {
}
}

#[cfg(not(feature = "libm"))]
#[cfg(all(not(feature = "libm"), feature = "std"))]
mod std_math {
#[inline(always)]
pub(crate) fn abs(f: f64) -> f64 {
Expand Down Expand Up @@ -198,8 +198,88 @@ mod std_math {
}
}

// Used to reduce the number of compilation errors, in the event that no other
// math backend is specified.
#[cfg(all(not(feature = "libm"), not(feature = "std")))]
mod no_backend_math {
pub(crate) fn abs(_: f64) -> f64 {
unimplemented!()
}

pub(crate) fn acos_approx(_: f64) -> f64 {
unimplemented!()
}

pub(crate) fn atan2(_: f64, _: f64) -> f64 {
unimplemented!()
}

pub(crate) fn sin(_: f64) -> f64 {
unimplemented!()
}

pub(crate) fn sin_cos(_: f64) -> (f64, f64) {
unimplemented!()
}

pub(crate) fn tan(_: f64) -> f64 {
unimplemented!()
}

pub(crate) fn sqrt(_: f64) -> f64 {
unimplemented!()
}

pub(crate) fn copysign(_: f64, _: f64) -> f64 {
unimplemented!()
}

pub(crate) fn signum(_: f64) -> f64 {
unimplemented!()
}

pub(crate) fn round(_: f64) -> f64 {
unimplemented!()
}

pub(crate) fn trunc(_: f64) -> f64 {
unimplemented!()
}

pub(crate) fn ceil(_: f64) -> f64 {
unimplemented!()
}

pub(crate) fn floor(_: f64) -> f64 {
unimplemented!()
}

pub(crate) fn exp(_: f64) -> f64 {
unimplemented!()
}

pub(crate) fn powf(_: f64, _: f64) -> f64 {
unimplemented!()
}

pub(crate) fn mul_add(_: f64, _: f64, _: f64) -> f64 {
unimplemented!()
}

pub fn div_euclid(_: f64, _: f64) -> f64 {
unimplemented!()
}

pub fn rem_euclid(_: f64, _: f64) -> f64 {
unimplemented!()
}
}

#[cfg(feature = "libm")]
pub(crate) use libm_math::*;

#[cfg(not(feature = "libm"))]
#[cfg(all(not(feature = "libm"), feature = "std"))]
pub(crate) use std_math::*;

#[cfg(all(not(feature = "libm"), not(feature = "std")))]
pub(crate) use no_backend_math::*;
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ The minimum supported Rust version is `1.68.2`.
feature(portable_simd)
)]

#[cfg(all(not(feature = "std"), not(feature = "libm")))]
compile_error!("You must specify a math backend using either the `std` feature or `libm` feature");

#[macro_use]
mod macros;

Expand Down

0 comments on commit 717f05d

Please sign in to comment.