pub(crate) trait AlgebraicFloat: Copy {
fn alg_add(self, rhs: Self) -> Self;
fn alg_sub(self, rhs: Self) -> Self;
fn alg_mul(self, rhs: Self) -> Self;
fn alg_div(self, rhs: Self) -> Self;
fn alg_rem(self, rhs: Self) -> Self;
}
#[cfg(any(not(feature = "algebraic-scalar"), feature = "strict_ieee754"))]
macro_rules! impl_algebraic_float {
($($t:ty),* $(,)?) => {$(
impl AlgebraicFloat for $t {
#[inline(always)] fn alg_add(self, rhs: Self) -> Self { self + rhs }
#[inline(always)] fn alg_sub(self, rhs: Self) -> Self { self - rhs }
#[inline(always)] fn alg_mul(self, rhs: Self) -> Self { self * rhs }
#[inline(always)] fn alg_div(self, rhs: Self) -> Self { self / rhs }
#[inline(always)] fn alg_rem(self, rhs: Self) -> Self { self % rhs }
}
)*};
}
#[cfg(all(feature = "algebraic-scalar", not(feature = "strict_ieee754"), feature = "nightly"))]
macro_rules! impl_algebraic_float {
($($t:ty),* $(,)?) => {$(
impl AlgebraicFloat for $t {
#[inline(always)] fn alg_add(self, rhs: Self) -> Self { core::intrinsics::fadd_algebraic(self, rhs) }
#[inline(always)] fn alg_sub(self, rhs: Self) -> Self { core::intrinsics::fsub_algebraic(self, rhs) }
#[inline(always)] fn alg_mul(self, rhs: Self) -> Self { core::intrinsics::fmul_algebraic(self, rhs) }
#[inline(always)] fn alg_div(self, rhs: Self) -> Self { core::intrinsics::fdiv_algebraic(self, rhs) }
#[inline(always)] fn alg_rem(self, rhs: Self) -> Self { core::intrinsics::frem_algebraic(self, rhs) }
}
)*};
}
#[cfg(all(
feature = "algebraic-scalar",
not(feature = "strict_ieee754"),
not(feature = "nightly")
))]
macro_rules! impl_algebraic_float {
($($t:ty),* $(,)?) => {$(
impl AlgebraicFloat for $t {
#[inline(always)] fn alg_add(self, rhs: Self) -> Self { self.algebraic_add(rhs) }
#[inline(always)] fn alg_sub(self, rhs: Self) -> Self { self.algebraic_sub(rhs) }
#[inline(always)] fn alg_mul(self, rhs: Self) -> Self { self.algebraic_mul(rhs) }
#[inline(always)] fn alg_div(self, rhs: Self) -> Self { self.algebraic_div(rhs) }
#[inline(always)] fn alg_rem(self, rhs: Self) -> Self { self.algebraic_rem(rhs) }
}
)*};
}
impl_algebraic_float!(f32, f64);
#[cfg(all(
feature = "algebraic-scalar",
not(feature = "strict_ieee754"),
not(feature = "nightly")
))]
#[rustversion::before(1.98)]
fn algebraic_scalar_version_check() {
compile_error!(
"the `algebraic-scalar` feature needs Rust 1.98+ for the stable `algebraic_*` float \
methods; until then, enable the `nightly` feature to use `core::intrinsics` instead."
);
}