Skip to content

Instantly share code, notes, and snippets.


Alex Shtof alexshtf

View GitHub Profile
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);