forked from StrafesNET/strafe-client
zeroes
This commit is contained in:
parent
943c3ca1c2
commit
5cac0e6153
@ -1,3 +1,4 @@
|
||||
pub mod framework;
|
||||
pub mod body;
|
||||
pub mod zeroes;
|
||||
pub mod instruction;
|
||||
|
27
src/zeroes.rs
Normal file
27
src/zeroes.rs
Normal 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];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user