Skip to content

Instantly share code, notes, and snippets.

View alexshtf's full-sized avatar

Alex Shtof alexshtf

View GitHub Profile
@alexshtf
alexshtf / constexpr_sqrt.cpp
Last active June 7, 2023 11:19
Constexpr version of c++ square root (for doubles)
#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);
}