lib/lib.rs
1// Returns the real solutions for the quadratic equation defined by aX²+bX+c
2//
3
4pub mod qeq_lib {
5
6 use std::f64;
7
8 pub fn solve(a: f64, b: f64, c: f64) -> (f64, f64) {
9
10 let discriminant = b*b - 4.0*a*c ;
11 if discriminant < 0.0 {
12 println!("Does not have any real solutions") ;
13 return (0.0,0.0) ;
14 };
15
16 let d = discriminant.sqrt() ;
17 let solution1 = (-b + d) / (2.0 * a) ;
18 let solution2 = (-b - d) / (2.0 * a) ;
19
20 (solution1, solution2)
21 }
22}