From 3ccc19f768c3a8858eacc34b4467826d02ee1669 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Fri, 23 Aug 2024 16:49:05 -0700 Subject: [PATCH] fix wide_dot and wide_length_squared --- src/macros/wide.rs | 8 ++++---- src/tests/mod.rs | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/macros/wide.rs b/src/macros/wide.rs index 3b348a2..7e12358 100644 --- a/src/macros/wide.rs +++ b/src/macros/wide.rs @@ -11,15 +11,15 @@ macro_rules! impl_wide_operations { } } } - impl+std::ops::Add> $struct { + impl,T:Copy+fixed_wide::wide::WideMul> $struct { #[inline] - pub fn wide_dot(&self, other: &Self) -> ::Output { + pub fn wide_dot(self, other: Self) -> U { $crate::sum_repeating!( $( + (self.$field.wide_mul(other.$field)) ) + ) } - pub fn length_squared(&self) -> ::Output { - let squared = Self { + pub fn wide_length_squared(&self) -> U { + let squared = $struct { $( $field: self.$field.wide_mul(self.$field) ), + }; diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 945b406..24a8b66 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -34,3 +34,23 @@ fn wide_vec3(){ assert_eq!(v3,Vector3::from_value(Planar64Wide3::from(3i128.pow(8)))); } + +#[test] +fn wide_vec3_dot(){ + let v=Vector3::from_value(Planar64::from(3)); + let v1=v.wide_mul(v); + let v2=v1.wide_mul(v1); + let v3=v2.wide_dot(v2); + + assert_eq!(v3,Planar64Wide3::from(3i128.pow(8)*3)); +} + +#[test] +fn wide_vec3_length_squared(){ + let v=Vector3::from_value(Planar64::from(3)); + let v1=v.wide_mul(v); + let v2=v1.wide_mul(v1); + let v3=v2.wide_length_squared(); + + assert_eq!(v3,Planar64Wide3::from(3i128.pow(8)*3)); +}