MCPcopy Create free account
hub / github.com/dengwirda/jigsaw / polyroots

Function polyroots

src/libcpp/mathutil.hpp:61–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59 typename real_type
60 >
61 __normal_call bool_type polyroots (
62 real_type _aa, // aa*xx^2+bb*xx+cc=0
63 real_type _bb,
64 real_type _cc,
65 __write_ptr (real_type) _xx
66 )
67 {
68 real_type _rt =
69 std::numeric_limits
70 <real_type>::epsilon() ;
71
72 bool_type _real = false ;
73
74 real_type _sq = _bb * _bb -
75 (real_type)+4. * _aa * _cc ;
76
77 if (_sq >= (real_type)+0.) // real roots
78 {
79 _sq = std::sqrt(_sq) ;
80
81 _xx[0] = (-_bb + _sq) ;
82 _xx[1] = (-_bb - _sq) ;
83
84 real_type _xm = std::max (
85 std::abs(_xx[0]),
86 std::abs(_xx[1])) ;
87
88 if (std::abs(_aa) >
89 std::abs(_xm) * _rt)
90 {
91 _real = true ;
92
93 _aa *=(real_type)+2. ;
94
95 _xx[0] /= _aa ;
96 _xx[1] /= _aa ;
97 }
98 else
99 if (std::abs(_bb) >
100 std::abs(_cc) * _rt)
101 {
102 _real = true ;
103
104 _xx[0] = -_cc / _bb ;
105 _xx[1] = -_cc / _bb ;
106 }
107 }
108
109 return _real ;
110 }
111
112 /*
113 --------------------------------------------------------

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected