Skip to content

Commit

Permalink
Add nodiscard attribute (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
acodcha committed Apr 12, 2024
1 parent 371a894 commit 689d601
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions include/cpp-utilities/constexpr_sqrt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ namespace internal {
// Efficient square root solver. This function is a constant expression, unlike std::sqrt. This
// function is an internal implementation detail and is not intended to be used except by the
// utility::constexpr_sqrt function.
inline constexpr double constexpr_sqrt_solver(const double number, const double factor) {
[[nodiscard]] inline constexpr double constexpr_sqrt_solver(
const double number, const double factor) {
// Recursively factor the input number until it falls within the [0.25, 4] interval, which greatly
// reduces the number of Newton-Raphson iterations needed to numerically compute the square root.
// When solving s = sqrt(x), if x can be expressed as x = n^2 * y such that y is geometrically
Expand Down Expand Up @@ -130,7 +131,7 @@ inline constexpr double constexpr_sqrt_solver(const double number, const double

// Returns the square root of a double-precision floating-point number. This function is a constant
// expression, unlike std::sqrt.
inline constexpr double constexpr_sqrt(const double number) {
[[nodiscard]] inline constexpr double constexpr_sqrt(const double number) {
// The square root of zero is zero. Notably, the square root solver does not handle this value, so
// it must be treated separately.
if (number == 0.0) {
Expand Down

0 comments on commit 689d601

Please sign in to comment.