Skip to content
Snippets Groups Projects
Commit c5e2b13e authored by Mathias Paulin's avatar Mathias Paulin :speech_balloon:
Browse files

Merge branch 'fix-sqrt' into 'master'

add constexpr sqrt implementation

See merge request MathiasPaulin/Radium-RenderingApp!3
parents 9ddf2107 4ca856e7
Branches
No related tags found
No related merge requests found
...@@ -9,12 +9,24 @@ ...@@ -9,12 +9,24 @@
#include <random> #include <random>
namespace RadiumNBR { namespace RadiumNBR {
Scalar constexpr sqrtNewtonRaphsonhelper(Scalar x, Scalar curr, Scalar prev)
{
return curr == prev
? curr
: sqrtNewtonRaphsonhelper(x, 0.5_ra * (curr + x / curr), curr);
}
Scalar constexpr ct_sqrt(Scalar x){
return sqrtNewtonRaphsonhelper( x, x, 0_ra );
}
/// Implements the 2D fibonacci sequence /// Implements the 2D fibonacci sequence
/// (i, N) => [i / phi, i / N] /// (i, N) => [i / phi, i / N]
/// where phi = (1 + sqrt(5)) / 2 /// where phi = (1 + sqrt(5)) / 2
class NodeBasedRenderer_LIBRARY_API FibonacciSequence class NodeBasedRenderer_LIBRARY_API FibonacciSequence
{ {
static constexpr Scalar phi = ( 1_ra + std::sqrt( 5_ra ) ) / 2_ra;
static constexpr Scalar phi = ( 1_ra + ct_sqrt( 5_ra ) ) / 2_ra;
int n; int n;
public: public:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment