include/crbn/solver/quadratic.hpp

00001 #ifndef __quadratic_hpp__
00002 #define __quadratic_hpp__
00003 
00004 #include <crbn/basic/scalar.hpp>
00005 
00006 // Solve a quadratic equation. It only returns real roots.
00007 inline int quadratic_r(const float& a, const float& b, const float& c, float& x0, float& x1) {
00008   float delta = (b * b) - (4.0 * a * c);
00009   
00010   if(delta < 0) return 0;
00011 
00012   if(delta > 0) {
00013     delta = sqrt(delta);
00014     x0 = (-b - delta) / (2.0 * a);
00015     x1 = (-b + delta) / (2.0 * a);
00016     
00017     return 2;
00018   }
00019 
00020   x0 = x1 = - b / (2.0 * a);
00021   return 1;
00022 }
00023 
00024 #endif

Generated on Tue Nov 14 15:40:08 2006 for libcrbn by  doxygen 1.5.0