Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Shtof alexshtf

View GitHub Profile
@alexshtf
alexshtf / constexpr_sqrt.cpp
Last active Jun 23, 2022
Constexpr version of c++ square root (for doubles)
View constexpr_sqrt.cpp
#include <limits>
namespace Detail
{
double constexpr sqrtNewtonRaphson(double x, double curr, double prev)
{
return curr == prev
? curr
: sqrtNewtonRaphson(x, 0.5 * (curr + x / curr), curr);
}