This commit is contained in:
Quaternions 2023-09-18 13:20:34 -07:00
parent 4f5c9afed3
commit 8daf432991
2 changed files with 28 additions and 0 deletions

View File

@ -1,3 +1,4 @@
pub mod framework; pub mod framework;
pub mod body; pub mod body;
pub mod zeroes;
pub mod instruction; pub mod instruction;

27
src/zeroes.rs Normal file
View File

@ -0,0 +1,27 @@
//find roots of polynomials
pub fn zeroes2(a0:f32,a1:f32,a2:f32) -> Vec<f32>{
if a2==0f32{
return zeroes1(a0, a1);
}
let mut radicand=a1*a1-4f32*a2*a0;
if 0f32<radicand {
radicand=radicand.sqrt();
if 0f32<a2 {
return vec![(-a1-radicand)/(2f32*a2),(-a1+radicand)/(2f32*a2)];
} else {
return vec![(-a1+radicand)/(2f32*a2),(-a1-radicand)/(2f32*a2)];
}
} else if radicand==0f32 {
return vec![-a1/(2f32*a2)];
} else {
return vec![];
}
}
#[inline]
pub fn zeroes1(a0:f32,a1:f32) -> Vec<f32> {
if a1==0f32{
return vec![];
} else {
return vec![-a0/a1];
}
}