Is there a way to perform calculations of Mandelbrot set using only integer numbers?

1.2k Views Asked by At

I would like to create program in JavaScript (JS) which draws Mandelbrot set with arbitrary precision (zoom). In JS there is build in integer type BigInt which support simple operations like +,*,/,power on arbitrary precision integer numbers. JS not support calculations on arbitrary precision floating point numbers.

Question: Is there a way to perform calculations of Mandelbrot set using calculations based only on integers (with arbitrary precision) - if yes how to do it?

1

There are 1 best solutions below

2
On

You can just define a scaling of your integers. As we know that if the magnitude of $z$ ever exceeds $2$ the iteration will go off to infinity, you only need to support numbers up to, say, $4$ in both dimensions. You are essentially implementing floating point as pairs of integers. Represent a real number as $a\cdot 2^{-n}$ and store $a$ and $n$ as integers. A complex number would be $(a+bi)2^{-n}$. Now write routines that add and multiply these numbers, so if you want $(a+bi)2^{-n} \cdot (c+di)2^{-m}$ you get $(ac-bd+a(ad+bc)i)2^{-(n+m)}$. Now rescale appropriately and go on.