mirror of https://github.com/CGAL/cgal
Sanitize result of square root
This commit is contained in:
parent
056e846e0d
commit
f882c5d3a6
|
|
@ -146,8 +146,11 @@ public:
|
|||
static
|
||||
FT to_ft(const Sqrt_3& x)
|
||||
{
|
||||
FT sqrt_e = compute_sqrt( to_ft(x.e()), FT_Has_sqrt() );
|
||||
FT sqrt_f = compute_sqrt( to_ft(x.f()), FT_Has_sqrt() );
|
||||
// If the number type does not offer a square root, x.e() and x.f() (which are of type sqrt_1)
|
||||
// might be negative after (approximately) evaluating them. Taking the max sanitize these values
|
||||
// to ensure that we do not take the square root of a negative number.
|
||||
FT sqrt_e = compute_sqrt( (std::max)(FT(0), to_ft(x.e())), FT_Has_sqrt() );
|
||||
FT sqrt_f = compute_sqrt( (std::max)(FT(0), to_ft(x.f())), FT_Has_sqrt() );
|
||||
FT sqrt_ef = sqrt_e * sqrt_f;
|
||||
return to_ft(x.a()) + to_ft(x.b()) * sqrt_e
|
||||
+ to_ft(x.c()) * sqrt_f + to_ft(x.d()) * sqrt_ef;
|
||||
|
|
|
|||
Loading…
Reference in New Issue