use alternate quadratic equation in poor accuracy cases
This commit is contained in:
parent
43e62e8f1d
commit
44540853dd
@ -11,10 +11,12 @@ pub fn zeroes2(a0:Planar64,a1:Planar64,a2:Planar64) -> Vec<Planar64>{
|
|||||||
//start with f64 sqrt
|
//start with f64 sqrt
|
||||||
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 {
|
//sort roots ascending and avoid taking the difference of large numbers
|
||||||
return vec![(-a1-planar_radicand)/(a2*2),(-a1+planar_radicand)/(a2*2)];
|
match (Planar64::ZERO<a2,Planar64::ZERO<a1){
|
||||||
} else {
|
(true, true )=>vec![(-a1-planar_radicand)/(a2*2),(a0*2)/(-a1-planar_radicand)],
|
||||||
return vec![(-a1+planar_radicand)/(a2*2),(-a1-planar_radicand)/(a2*2)];
|
(true, false)=>vec![(a0*2)/(-a1+planar_radicand),(-a1+planar_radicand)/(a2*2)],
|
||||||
|
(false,true )=>vec![(a0*2)/(-a1-planar_radicand),(-a1-planar_radicand)/(a2*2)],
|
||||||
|
(false,false)=>vec![(-a1+planar_radicand)/(a2*2),(a0*2)/(-a1+planar_radicand)],
|
||||||
}
|
}
|
||||||
} else if radicand==0 {
|
} else if radicand==0 {
|
||||||
return vec![a1/(a2*-2)];
|
return vec![a1/(a2*-2)];
|
||||||
|
Loading…
Reference in New Issue
Block a user