Fixed the math in SIMD and normal version to be compliant with the assignment

Checking for convergence before calculating next value and z0 = 0
This commit is contained in:
Nikola
2026-07-03 14:24:56 +02:00
parent 03d8253206
commit d2ba15339d
2 changed files with 8 additions and 7 deletions
+6 -5
View File
@@ -13,7 +13,7 @@ void tricorn(float complex start, size_t width, ssize_t height, float res, unsig
for(size_t i = 0; i < width; i++){
for(ssize_t j = 0; j < height; j++){
unsigned value = converge(start + (i*res - I*j*res),n);
unsigned value = converge(start + (i*res - I*j*res),n+1);
// Pixel value position in the output array
size_t position = (j*width +i) * bytesPerColor;
@@ -37,14 +37,15 @@ static unsigned converge(float complex position,unsigned n){
complex float result = 0;
for(unsigned i = 0; i < n; i++){
// Application of the given complex equation with m = 2
result = cpowf(conjf(result),2) + position;
// Detection of unbounded behaviour
// Detection of unbounded behaviour
// If the magnitude of the result vector is greater than the convergence limit, we know that the function will grow unbounded
// Current convergence limit taken from mandelbrot set
if(sqrtf(powf (crealf(result),2)+powf(cimagf(result),2)) > convergenceLimit)
return 255-4*(i % 64);
// Application of the given complex equation with m = 2
result = cpowf(conjf(result),2) + position;
}
return 0;
}
+2 -2
View File
@@ -26,8 +26,8 @@ void tricorn_simd(float complex start, size_t width, ssize_t height, float res,
float c_real = c_start_real + (x*res);
__m128 c_real_vector = _mm_setr_ps(c_real,c_real+1.0f*res,c_real+2.0f*res,c_real+3.0f*res);
__m128 real = c_real_vector;
__m128 imag = c_imag_vector;
__m128 real = _mm_setzero_ps();
__m128 imag = _mm_setzero_ps();
__m128i iterations = _mm_setzero_si128();
__m128i active_mask = _mm_set1_epi32(-1);