From a2d5e8618859f22d4ebe33d32d74c65948d40cd7 Mon Sep 17 00:00:00 2001 From: koma Date: Tue, 5 Jul 2022 23:27:06 +0200 Subject: [PATCH] add optimized iteration algorithm --- mandelbrot.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mandelbrot.cpp b/mandelbrot.cpp index 2142c0b..3fa63ba 100644 --- a/mandelbrot.cpp +++ b/mandelbrot.cpp @@ -67,15 +67,15 @@ uint32_t Mandelbrotc::mandelbrot(const Vec2mp &n) // y.setValue(0.0); mpreal x = mpreal(0.0); - mpreal xtemp = mpreal(0.0); mpreal y = mpreal(0.0); mpreal x2 = mpreal(0.0); mpreal y2 = mpreal(0.0); - while (x*x + y*y <= 4 && iter < max_iter) { - xtemp = x*x - y*y + n.x; - y = 2*x*y+n.y; - x = xtemp; + while (x2 + y2 <= 4 && iter < max_iter) { + y = 2.0 * x * y + n.y; + x = x2 - y2 + n.x; + x2 = x * x; + y2 = y * y; iter++; }