<spanclass="comment">// Values exceeding 4 usually diverge. If the number</span>
<spanclass="comment">// does not diverge after `max_iterations`, it probably</span>
<spanclass="comment">// never will.</span>
<spanclass="keyword control repeat">while</span><spanclass="variable">squared</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">re</span><spanclass="operator">+</span><spanclass="variable">squared</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">im</span><spanclass="operator"><=</span><spanclass="constant numeric float">4.0</span><spanclass="operator">&&</span>
<spanclass="keyword storage">let</span><spanclass="variable">im</span><spanclass="operator">=</span><spanclass="constant numeric float">2.0</span><spanclass="operator">*</span><spanclass="variable">last</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">re</span><spanclass="operator">*</span><spanclass="variable">last</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">im</span><spanclass="operator">+</span><spanclass="variable parameter">val</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">im</span><spanclass="punctuation delimiter">;</span>
<spanclass="keyword storage">let</span><spanclass="variable">re</span><spanclass="operator">=</span><spanclass="variable">squared</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">re</span><spanclass="operator">-</span><spanclass="variable">squared</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">im</span><spanclass="operator">+</span><spanclass="variable parameter">val</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">re</span><spanclass="punctuation delimiter">;</span>
<spanclass="variable">last</span><spanclass="operator">=</span><spanclass="constructor">Complex</span><spanclass="punctuation bracket">{</span><spanclass="variable other member">re</span><spanclass="punctuation delimiter">,</span><spanclass="variable other member">im</span><spanclass="punctuation bracket">}</span><spanclass="punctuation delimiter">;</span>
<spanclass="variable">squared</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">re</span><spanclass="operator">=</span><spanclass="variable">re</span><spanclass="punctuation delimiter">.</span><spanclass="function">powi</span><spanclass="punctuation bracket">(</span><spanclass="constant numeric integer">2</span><spanclass="punctuation bracket">)</span><spanclass="punctuation delimiter">;</span>
<spanclass="variable">squared</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">im</span><spanclass="operator">=</span><spanclass="variable">im</span><spanclass="punctuation delimiter">.</span><spanclass="function">powi</span><spanclass="punctuation bracket">(</span><spanclass="constant numeric integer">2</span><spanclass="punctuation bracket">)</span><spanclass="punctuation delimiter">;</span>
<spanclass="keyword control repeat">while</span><spanclass="variable">squared</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">re</span><spanclass="operator">+</span><spanclass="variable">squared</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">im</span><spanclass="operator"><=</span><spanclass="constant numeric float">4.0</span>
<spanclass="operator">&&</span><spanclass="variable">deriv</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">re</span><spanclass="punctuation delimiter">.</span><spanclass="function">powi</span><spanclass="punctuation bracket">(</span><spanclass="constant numeric integer">2</span><spanclass="punctuation bracket">)</span><spanclass="operator">+</span><spanclass="variable">deriv</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">im</span><spanclass="punctuation delimiter">.</span><spanclass="function">powi</span><spanclass="punctuation bracket">(</span><spanclass="constant numeric integer">2</span><spanclass="punctuation bracket">)</span><spanclass="operator"><=</span><spanclass="variable parameter">max_dvt</span>
<spanclass="variable">deriv</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">re</span><spanclass="operator">=</span><spanclass="constant numeric float">2.0</span><spanclass="operator">*</span><spanclass="punctuation bracket">(</span><spanclass="variable">deriv</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">re</span><spanclass="operator">*</span><spanclass="variable parameter">val</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">re</span><spanclass="operator">-</span><spanclass="variable">deriv</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">im</span><spanclass="operator">*</span><spanclass="variable parameter">val</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">im</span><spanclass="punctuation bracket">)</span><spanclass="punctuation delimiter">;</span>
<spanclass="variable">deriv</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">im</span><spanclass="operator">=</span><spanclass="constant numeric float">2.0</span><spanclass="operator">*</span><spanclass="punctuation bracket">(</span><spanclass="variable">deriv</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">re</span><spanclass="operator">*</span><spanclass="variable parameter">val</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">im</span><spanclass="operator">+</span><spanclass="variable">deriv</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">im</span><spanclass="operator">*</span><spanclass="variable parameter">val</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">re</span><spanclass="punctuation bracket">)</span><spanclass="punctuation delimiter">;</span>
<spanclass="keyword storage">let</span><spanclass="variable">im</span><spanclass="operator">=</span><spanclass="constant numeric float">2.0</span><spanclass="operator">*</span><spanclass="variable">last</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">re</span><spanclass="operator">*</span><spanclass="variable">last</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">im</span><spanclass="operator">+</span><spanclass="variable parameter">val</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">im</span><spanclass="punctuation delimiter">;</span>
<spanclass="keyword storage">let</span><spanclass="variable">re</span><spanclass="operator">=</span><spanclass="variable">squared</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">re</span><spanclass="operator">-</span><spanclass="variable">squared</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">im</span><spanclass="operator">+</span><spanclass="variable parameter">val</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">re</span><spanclass="punctuation delimiter">;</span>
<spanclass="variable">last</span><spanclass="operator">=</span><spanclass="constructor">Complex</span><spanclass="punctuation bracket">{</span><spanclass="variable other member">re</span><spanclass="punctuation delimiter">,</span><spanclass="variable other member">im</span><spanclass="punctuation bracket">}</span><spanclass="punctuation delimiter">;</span>
<spanclass="variable">squared</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">re</span><spanclass="operator">=</span><spanclass="variable">re</span><spanclass="punctuation delimiter">.</span><spanclass="function">powi</span><spanclass="punctuation bracket">(</span><spanclass="constant numeric integer">2</span><spanclass="punctuation bracket">)</span><spanclass="punctuation delimiter">;</span>
<spanclass="variable">squared</span><spanclass="punctuation delimiter">.</span><spanclass="variable other member">im</span><spanclass="operator">=</span><spanclass="variable">im</span><spanclass="punctuation delimiter">.</span><spanclass="function">powi</span><spanclass="punctuation bracket">(</span><spanclass="constant numeric integer">2</span><spanclass="punctuation bracket">)</span><spanclass="punctuation delimiter">;</span>