speed up code by 10 times replacing hypot with sqrt

This commit is contained in:
LDprg 2022-09-06 09:25:23 +02:00 committed by Vittorio Romeo
parent 45986c6400
commit 0584448a06
2 changed files with 3 additions and 3 deletions

View File

@ -107,7 +107,7 @@ T Vector2<T>::length() const
{
static_assert(std::is_floating_point_v<T>, "Vector2::length() is only supported for floating point types");
return std::hypot(x, y);
return std::sqrt(x*x + y*y);
}
} // namespace sf

View File

@ -48,7 +48,7 @@ T Vector3<T>::length() const
{
static_assert(std::is_floating_point_v<T>, "Vector3::length() is only supported for floating point types");
return std::hypot(x, y, z);
return std::sqrt(x*x + y*y + z*z);
}
} // namespace sf