mightymandel v16

GPU-based Mandelbrot set explorer

utility.c
Go to the documentation of this file.
1 // mightymandel -- GPU-based Mandelbrot Set explorer
2 // Copyright (C) 2012,2013,2014,2015 Claude Heiland-Allen
3 // License GPL3+ http://www.gnu.org/licenses/gpl.html
4 
10 #include <math.h>
11 #include <stdio.h>
12 
13 #include "utility.h"
14 
22 int min(int a, int b) { return a < b ? a : b; }
23 
31 int max(int a, int b) { return a > b ? a : b; }
32 
39 int ceil2n(int z) {
40  int n = 1;
41  while (0 < n && n < z) {
42  n <<= 1;
43  }
44  return n;
45 }
46 
54 int pxbits(const mpfr_t radius, double height) {
55  mpfr_t r;
56  mpfr_init2(r, 53);
57  mpfr_log2(r, radius, MPFR_RNDN);
58  int bits = 2 + ceil(log2(height)) - floor(mpfr_get_d(r, MPFR_RNDN));
59  mpfr_clear(r);
60  return bits;
61 }
62 
76 void pixel_coordinate(mpfr_t x, mpfr_t y, int width, int height, const mpfr_t centerx, const mpfr_t centery, const mpfr_t radius, double i, double j) {
77  mpfr_set_prec(x, mpfr_get_prec(centerx) + 8);
78  mpfr_set_prec(y, mpfr_get_prec(centery) + 8);
79  mpfr_mul_d(x, radius, 2.0 * (i - width / 2.0) / height, MPFR_RNDN);
80  mpfr_add(x, x, centerx, MPFR_RNDN);
81  mpfr_mul_d(y, radius, 2.0 * (height / 2.0 - j) / height, MPFR_RNDN);
82  mpfr_add(y, y, centery, MPFR_RNDN);
83 }