From 9ba9c47a952ce6966b333af579bd39c636080fbc Mon Sep 17 00:00:00 2001 From: JP Appel Date: Tue, 23 Apr 2024 15:58:54 -0400 Subject: added preprocessor to change precision at compile time --- src/shared-fractals.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/shared-fractals.c') diff --git a/src/shared-fractals.c b/src/shared-fractals.c index 49a034e..c44224a 100644 --- a/src/shared-fractals.c +++ b/src/shared-fractals.c @@ -2,16 +2,17 @@ #include #include "fractals.h" +#include "precision.h" /* * Computes the number of iterations it takes for a point z0 to diverge * if the return value is equal to max_iterations, the point lies within the mandelbrot set * This should be identical to the version found in serial-fractals.c */ -size_t mandelbrot(const long double complex z0, const size_t max_iterations){ - long double complex z = z0; +size_t mandelbrot(const CBASE complex z0, const size_t max_iterations){ + CBASE complex z = z0; size_t iteration = 0; - while(cabsl(z) <= 2 && iteration < max_iterations){ + while(CABS(z) <= 2 && iteration < max_iterations){ z = z*z + z0; iteration++; } @@ -22,7 +23,7 @@ size_t mandelbrot(const long double complex z0, const size_t max_iterations){ /* * Fills a grid with mandelbrot values */ -void mandelbrot_grid(grid_t* grid, const size_t max_iterations){ +void mandelbrot_grid(grid_t* restrict grid, const size_t max_iterations){ const size_t size = grid->size; size_t* data = grid->data; @@ -37,11 +38,11 @@ void mandelbrot_grid(grid_t* grid, const size_t max_iterations){ * if the return value is equal to max_iterations, the point lies within the multibrot set * This should be identical to the version found in serial-fractals.c */ -size_t multibrot(const long double complex z0, const size_t max_iterations, const double d){ - long double complex z = z0; +size_t multibrot(const CBASE complex z0, const size_t max_iterations, const double d){ + CBASE complex z = z0; size_t iteration = 0; - while(cabsl(z) <= 2 && iteration < max_iterations){ - z = cpowl(z, d) + z0; + while(CABS(z) <= 2 && iteration < max_iterations){ + z = CPOW(z, d) + z0; iteration++; } return iteration; @@ -51,7 +52,7 @@ size_t multibrot(const long double complex z0, const size_t max_iterations, cons /* * Fills a grid with multibrot values */ -void multibrot_grid(grid_t* grid, const size_t max_iterations, const double d){ +void multibrot_grid(grid_t* restrict grid, const size_t max_iterations, const double d){ const size_t size = grid->size; size_t* data = grid->data; @@ -68,22 +69,22 @@ void multibrot_grid(grid_t* grid, const size_t max_iterations, const double d){ * This behaves weirdly, needs a very small number of iterations to be visibile */ -size_t julia(const long double complex z0, const long double complex c, const size_t max_iterations, const double R){ - long double complex z = z0; +size_t julia(const CBASE complex z0, const CBASE complex c, const size_t max_iterations, const double R){ + double complex z = z0; size_t iteration = 0; - while(cabsl(z) < R && iteration < max_iterations){ + while(CABS(z) < R && iteration < max_iterations){ z = z * z + c; iteration++; } return iteration; } -void julia_grid(grid_t* grid, const size_t max_iterations, const long double complex c, const double R){ +void julia_grid(grid_t* restrict grid, const size_t max_iterations, const CBASE complex c, const double R){ const size_t size = grid->size; size_t* data = grid->data; #pragma omp parallel for default(none) shared(data, size, grid, max_iterations, c, R) schedule(dynamic) - for(size_t i = 0; i