From fc50c017f2db3cefbe301c32e2514fe6014a0b75 Mon Sep 17 00:00:00 2001 From: tehforsch Date: Fri, 21 Jun 2024 10:43:12 +0200 Subject: [PATCH] fix sqrt/cbrt impls being feature gated inside quote --- .../src/codegen/float_methods.rs | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/crates/diman_unit_system/src/codegen/float_methods.rs b/crates/diman_unit_system/src/codegen/float_methods.rs index 4720ad4..f544edf 100644 --- a/crates/diman_unit_system/src/codegen/float_methods.rs +++ b/crates/diman_unit_system/src/codegen/float_methods.rs @@ -97,6 +97,32 @@ impl Codegen { let float_type = &float_type.name; let dimension_type = &self.defs.dimension_type; let quantity_type = &self.defs.quantity_type; + + #[cfg(any(feature = "std", feature = "num-traits-libm"))] + let roots = quote! { + pub fn sqrt(&self) -> #quantity_type<#float_type, { D.div_2() }> + { + #quantity_type::<#float_type, { D.div_2() }>(self.0.sqrt()) + } + + pub fn cbrt(&self) -> #quantity_type<#float_type, { D.div_3() }> + { + #quantity_type::<#float_type, { D.div_3() }>(self.0.cbrt()) + } + }; + #[cfg(all(not(feature = "std"), not(feature = "num-traits-libm")))] + let roots = quote! { + pub fn sqrt(&self) -> #quantity_type<#float_type, { D.div_2() }> + { + #quantity_type::<#float_type, { D.div_2() }>(self.0.sqrt()) + } + + pub fn cbrt(&self) -> #quantity_type<#float_type, { D.div_3() }> + { + #quantity_type::<#float_type, { D.div_3() }>(self.0.cbrt()) + } + }; + quote! { impl #quantity_type<#float_type, D> { pub fn squared(&self) -> #quantity_type<#float_type, { D.mul(2) }> @@ -113,6 +139,7 @@ impl Codegen { #quantity_type::<#float_type, { D.mul(3) }>(self.0.powi(3)) } + pub fn powi(&self) -> #quantity_type<#float_type, { D.mul(I) }> where #quantity_type::<#float_type, { D.mul(I) }>: @@ -120,17 +147,7 @@ impl Codegen { #quantity_type::<#float_type, { D.mul(I) }>(self.0.powi(I)) } - #[cfg(any(feature = "std", feature = "num-traits-libm"))] - pub fn sqrt(&self) -> #quantity_type<#float_type, { D.div_2() }> - { - #quantity_type::<#float_type, { D.div_2() }>(self.0.sqrt()) - } - - #[cfg(any(feature = "std", feature = "num-traits-libm"))] - pub fn cbrt(&self) -> #quantity_type<#float_type, { D.div_3() }> - { - #quantity_type::<#float_type, { D.div_3() }>(self.0.cbrt()) - } + #roots pub fn min>(self, other: Q) -> Self { Self(self.0.min(other.into().0))