return fixed length array and len to avoid heap allocation

This commit is contained in:
Quaternions 2023-10-26 18:09:58 -07:00
parent 08d4e7d997
commit 01a8efe4d4

View File

@ -2,7 +2,7 @@
use crate::integer::Planar64; use crate::integer::Planar64;
#[inline] #[inline]
pub fn zeroes2(a0:Planar64,a1:Planar64,a2:Planar64) -> Vec<Planar64>{ pub fn zeroes2<'a>(a0:Planar64,a1:Planar64,a2:Planar64)->&'a [Planar64]{
if a2==Planar64::ZERO{ if a2==Planar64::ZERO{
return zeroes1(a0,a1); return zeroes1(a0,a1);
} }
@ -12,21 +12,21 @@ pub fn zeroes2(a0:Planar64,a1:Planar64,a2:Planar64) -> Vec<Planar64>{
let planar_radicand=Planar64::raw(unsafe{(radicand as f64).sqrt().to_int_unchecked()}); let planar_radicand=Planar64::raw(unsafe{(radicand as f64).sqrt().to_int_unchecked()});
//TODO: one or two newtons //TODO: one or two newtons
if Planar64::ZERO<a2{ if Planar64::ZERO<a2{
return vec![(-a1-planar_radicand)/(a2*2),(-a1+planar_radicand)/(a2*2)]; &[(-a1-planar_radicand)/(a2*2),(-a1+planar_radicand)/(a2*2)]
}else{ }else{
return vec![(-a1+planar_radicand)/(a2*2),(-a1-planar_radicand)/(a2*2)]; &[(-a1+planar_radicand)/(a2*2),(-a1-planar_radicand)/(a2*2)]
} }
}else if radicand==0{ }else if radicand==0{
return vec![a1/(a2*-2)]; &[a1/(a2*-2)]
}else{ }else{
return vec![]; &[]
} }
} }
#[inline] #[inline]
pub fn zeroes1(a0:Planar64,a1:Planar64) -> Vec<Planar64> { pub fn zeroes1<'a>(a0:Planar64,a1:Planar64)->&'a [Planar64]{
if a1==Planar64::ZERO{ if a1==Planar64::ZERO{
return vec![]; &[]
}else{ }else{
return vec![-a0/a1]; &[-a0/a1]
} }
} }