pub fn find_roots_cubic_normalized<F: FloatType>(a2: F, a1: F, a0: F) -> Roots<F> {
    let q = (F::three() * a1 - a2 * a2) / F::nine();
    let r = (F::nine() * a2 * a1 - F::twenty_seven() * a0 - F::two() * a2 * a2 * a2) /
            (F::two() * F::twenty_seven());
    let q3 = q * q * q;
    let d = q3 + r * r;
    let a2_div_3 = a2 / F::three();

    if d < F::zero() {
        let phi_3 = (r / (-q3).sqrt()).acos() / F::three();
        let sqrt_q_2 = F::two() * (-q).sqrt();

        Roots::One([sqrt_q_2 * phi_3.cos() - a2_div_3])
            .add_new_root(sqrt_q_2 * (phi_3 - F::two_third_pi()).cos() - a2_div_3)
            .add_new_root(sqrt_q_2 * (phi_3 + F::two_third_pi()).cos() - a2_div_3)
    } else {
        let sqrt_d = d.sqrt();
        let s = (r + sqrt_d).cbrt();
        let t = (r - sqrt_d).cbrt();

        if s == t {
            if s + t == F::zero() {
                Roots::One([s + t - a2_div_3])
            } else {
                Roots::One([s + t - a2_div_3]).add_new_root(-(s + t) / F::two() - a2_div_3)
            }
        } else {
            Roots::One([s + t - a2_div_3])
        }
    }
}
/// Solves a normalized cubic equation x^3 + a2*x^2 + a1*x + a0 = 0.
///
/// In case more than one roots are present, they are returned in the increasing order.
///
/// # Examples
///
/// ```
/// use roots::find_roots_cubic_normalized;
///
/// let one_root = find_roots_cubic_normalized(0f64, 0f64, 0f64);
/// // Returns Roots::One([0f64]) as 'x^3 = 0' has one root 0
///
/// let three_roots = find_roots_cubic_normalized(0f32, -1f32, 0f32);
/// // Returns Roots::Three([-1f32, -0f32, 1f32]) as 'x^3 - x = 0' has roots -1, 0, and 1
/// ```
Solves a normalized cubic equation x^3 + a2*x^2 + a1*x + a0 = 0.
In case more than one roots are present, they are returned in the increasing order.
Solves a normalized cubic equation x^3 + a2 * x^2 + a1 * x + a0 = 0 . In case more than one roots are present they are returned in the increasing order .
pub fn find_roots_cubic_normalized<F: FloatType>(a2: F, a1: F, a0: F) -> Roots<F> {
    let q = (F::three() * a1 - a2 * a2) / F::nine();
    let r = (F::nine() * a2 * a1 - F::twenty_seven() * a0 - F::two() * a2 * a2 * a2) /
            (F::two() * F::twenty_seven());
    let q3 = q * q * q;
    let d = q3 + r * r;
    let a2_div_3 = a2 / F::three();
    if d < F::zero() {
        let phi_3 = (r / (-q3).sqrt()).acos() / F::three();
        let sqrt_q_2 = F::two() * (-q).sqrt();
        Roots::One([sqrt_q_2 * phi_3.cos() - a2_div_3])
            .add_new_root(sqrt_q_2 * (phi_3 - F::two_third_pi()).cos() - a2_div_3)
            .add_new_root(sqrt_q_2 * (phi_3 + F::two_third_pi()).cos() - a2_div_3)
    } else {
        let sqrt_d = d.sqrt();
        let s = (r + sqrt_d).cbrt();
        let t = (r - sqrt_d).cbrt();
        if s == t {
            if s + t == F::zero() {
                Roots::One([s + t - a2_div_3])
            } else {
                Roots::One([s + t - a2_div_3]).add_new_root(-(s + t) / F::two() - a2_div_3)
            }
        } else {
            Roots::One([s + t - a2_div_3])
        }
    }
}
pub fn find_roots_cubic_normalized < F : FloatType > ( a2 : F , a1 : F , a0 : F ) -> Roots < F > { let q = ( F :: three ( ) * a1 - a2 * a2 ) / F :: nine ( ) ; let r = ( F :: nine ( ) * a2 * a1 - F :: twenty_seven ( ) * a0 - F :: two ( ) * a2 * a2 * a2 ) / ( F :: two ( ) * F :: twenty_seven ( ) ) ; let q3 = q * q * q ; let d = q3 + r * r ; let a2_div_3 = a2 / F :: three ( ) ; if d < F :: zero ( ) { let phi_3 = ( r / ( - q3 ) . sqrt ( ) ) . acos ( ) / F :: three ( ) ; let sqrt_q_2 = F :: two ( ) * ( - q ) . sqrt ( ) ; Roots :: One ( [ sqrt_q_2 * phi_3 . cos ( ) - a2_div_3 ] ) . add_new_root ( sqrt_q_2 * ( phi_3 - F :: two_third_pi ( ) ) . cos ( ) - a2_div_3 ) . add_new_root ( sqrt_q_2 * ( phi_3 + F :: two_third_pi ( ) ) . cos ( ) - a2_div_3 ) } else { let sqrt_d = d . sqrt ( ) ; let s = ( r + sqrt_d ) . cbrt ( ) ; let t = ( r - sqrt_d ) . cbrt ( ) ; if s == t { if s + t == F :: zero ( ) { Roots :: One ( [ s + t - a2_div_3 ] ) } else { Roots :: One ( [ s + t - a2_div_3 ] ) . add_new_root ( - ( s + t ) / F :: two ( ) - a2_div_3 ) } } else { Roots :: One ( [ s + t - a2_div_3 ] ) } } }
Solves a normalized cubic equation x^3 + a2*x^2 + a1*x + a0 = 0.
Solves a normalized cubic equation x^3 + a2 * x^2 + a1 * x + a0 = 0 .
a2
F
a1
F
a0
F
a2
F
a1
F
a0
F
examples
```
use roots::find_roots_cubic_normalized.

let one_root = find_roots_cubic_normalized(0f64, 0f64, 0f64);
Returns Roots::One([0f64]) as 'x^3 = 0' has one root 0


` ` ` use roots :: find_roots_cubic_normalized . let one_root = find_roots_cubic_normalized ( 0f64 0f64 0f64 ) ; Returns Roots :: One ( [ 0f64 ] ) as ' x^3 = 0 ' has one root 0