Average Error: 26.8 → 12.2
Time: 8.4s
Precision: binary64
\[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
\[\begin{array}{l} t_0 := \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}\\ t_1 := \frac{y.im \cdot x.re}{y.re}\\ \mathbf{if}\;y.re \leq -3.6431575460204783 \cdot 10^{+168}:\\ \;\;\;\;t_0 \cdot \left(t_1 - x.im\right)\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_2 := \frac{\frac{y.re \cdot x.im - y.im \cdot x.re}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{if}\;y.re \leq -4.650305513891855 \cdot 10^{-126}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y.re \leq 1.184468592590644 \cdot 10^{-129}:\\ \;\;\;\;\frac{y.re \cdot x.im}{y.im \cdot y.im} - \frac{x.re}{y.im}\\ \mathbf{elif}\;y.re \leq 2.4176762365015643 \cdot 10^{+126}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \left(x.im - t_1\right)\\ \end{array}\\ \end{array} \]
\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}\\
t_1 := \frac{y.im \cdot x.re}{y.re}\\
\mathbf{if}\;y.re \leq -3.6431575460204783 \cdot 10^{+168}:\\
\;\;\;\;t_0 \cdot \left(t_1 - x.im\right)\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_2 := \frac{\frac{y.re \cdot x.im - y.im \cdot x.re}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\
\mathbf{if}\;y.re \leq -4.650305513891855 \cdot 10^{-126}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;y.re \leq 1.184468592590644 \cdot 10^{-129}:\\
\;\;\;\;\frac{y.re \cdot x.im}{y.im \cdot y.im} - \frac{x.re}{y.im}\\

\mathbf{elif}\;y.re \leq 2.4176762365015643 \cdot 10^{+126}:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;t_0 \cdot \left(x.im - t_1\right)\\


\end{array}\\


\end{array}
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (/ (- (* x.im y.re) (* x.re y.im)) (+ (* y.re y.re) (* y.im y.im))))
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (let* ((t_0 (/ 1.0 (hypot y.im y.re))) (t_1 (/ (* y.im x.re) y.re)))
   (if (<= y.re -3.6431575460204783e+168)
     (* t_0 (- t_1 x.im))
     (let* ((t_2
             (/
              (/ (- (* y.re x.im) (* y.im x.re)) (hypot y.im y.re))
              (hypot y.im y.re))))
       (if (<= y.re -4.650305513891855e-126)
         t_2
         (if (<= y.re 1.184468592590644e-129)
           (- (/ (* y.re x.im) (* y.im y.im)) (/ x.re y.im))
           (if (<= y.re 2.4176762365015643e+126)
             t_2
             (* t_0 (- x.im t_1)))))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return ((x_46_im * y_46_re) - (x_46_re * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
}
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double t_0 = 1.0 / hypot(y_46_im, y_46_re);
	double t_1 = (y_46_im * x_46_re) / y_46_re;
	double tmp;
	if (y_46_re <= -3.6431575460204783e+168) {
		tmp = t_0 * (t_1 - x_46_im);
	} else {
		double t_2 = (((y_46_re * x_46_im) - (y_46_im * x_46_re)) / hypot(y_46_im, y_46_re)) / hypot(y_46_im, y_46_re);
		double tmp_1;
		if (y_46_re <= -4.650305513891855e-126) {
			tmp_1 = t_2;
		} else if (y_46_re <= 1.184468592590644e-129) {
			tmp_1 = ((y_46_re * x_46_im) / (y_46_im * y_46_im)) - (x_46_re / y_46_im);
		} else if (y_46_re <= 2.4176762365015643e+126) {
			tmp_1 = t_2;
		} else {
			tmp_1 = t_0 * (x_46_im - t_1);
		}
		tmp = tmp_1;
	}
	return tmp;
}

Error

Bits error versus x.re

Bits error versus x.im

Bits error versus y.re

Bits error versus y.im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 4 regimes
  2. if y.re < -3.6431575460204783e168

    1. Initial program 45.0

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Applied add-sqr-sqrt_binary6445.0

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}} \]
    3. Applied *-un-lft-identity_binary6445.0

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \cdot y.im\right)}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}} \]
    4. Applied times-frac_binary6445.0

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}} \]
    5. Simplified45.0

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \]
    6. Simplified29.3

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \color{blue}{\frac{y.re \cdot x.im - x.re \cdot y.im}{\mathsf{hypot}\left(y.im, y.re\right)}} \]
    7. Taylor expanded in y.re around -inf 11.3

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \color{blue}{\left(\frac{x.re \cdot y.im}{y.re} - x.im\right)} \]

    if -3.6431575460204783e168 < y.re < -4.65030551389185485e-126 or 1.18446859259064399e-129 < y.re < 2.4176762365015643e126

    1. Initial program 18.1

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Applied add-sqr-sqrt_binary6418.1

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}} \]
    3. Applied *-un-lft-identity_binary6418.1

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \cdot y.im\right)}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}} \]
    4. Applied times-frac_binary6418.1

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}} \]
    5. Simplified18.1

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \]
    6. Simplified13.0

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \color{blue}{\frac{y.re \cdot x.im - x.re \cdot y.im}{\mathsf{hypot}\left(y.im, y.re\right)}} \]
    7. Applied associate-*l/_binary6412.9

      \[\leadsto \color{blue}{\frac{1 \cdot \frac{y.re \cdot x.im - x.re \cdot y.im}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}} \]

    if -4.65030551389185485e-126 < y.re < 1.18446859259064399e-129

    1. Initial program 24.0

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Applied add-sqr-sqrt_binary6424.0

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}} \]
    3. Applied *-un-lft-identity_binary6424.0

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \cdot y.im\right)}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}} \]
    4. Applied times-frac_binary6424.0

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}} \]
    5. Simplified24.0

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \]
    6. Simplified13.1

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \color{blue}{\frac{y.re \cdot x.im - x.re \cdot y.im}{\mathsf{hypot}\left(y.im, y.re\right)}} \]
    7. Applied *-un-lft-identity_binary6413.1

      \[\leadsto \color{blue}{\left(1 \cdot \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}\right)} \cdot \frac{y.re \cdot x.im - x.re \cdot y.im}{\mathsf{hypot}\left(y.im, y.re\right)} \]
    8. Applied associate-*l*_binary6413.1

      \[\leadsto \color{blue}{1 \cdot \left(\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \frac{y.re \cdot x.im - x.re \cdot y.im}{\mathsf{hypot}\left(y.im, y.re\right)}\right)} \]
    9. Simplified24.0

      \[\leadsto 1 \cdot \color{blue}{\frac{y.re \cdot x.im - x.re \cdot y.im}{\mathsf{hypot}\left(y.im, y.re\right) \cdot \mathsf{hypot}\left(y.im, y.re\right)}} \]
    10. Taylor expanded in y.re around 0 10.4

      \[\leadsto 1 \cdot \color{blue}{\left(\frac{y.re \cdot x.im}{{y.im}^{2}} - \frac{x.re}{y.im}\right)} \]
    11. Simplified10.4

      \[\leadsto 1 \cdot \color{blue}{\left(\frac{y.re \cdot x.im}{y.im \cdot y.im} - \frac{x.re}{y.im}\right)} \]

    if 2.4176762365015643e126 < y.re

    1. Initial program 42.7

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Applied add-sqr-sqrt_binary6442.7

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}} \]
    3. Applied *-un-lft-identity_binary6442.7

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \cdot y.im\right)}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}} \]
    4. Applied times-frac_binary6442.7

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}} \]
    5. Simplified42.7

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \]
    6. Simplified29.2

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \color{blue}{\frac{y.re \cdot x.im - x.re \cdot y.im}{\mathsf{hypot}\left(y.im, y.re\right)}} \]
    7. Taylor expanded in y.re around inf 13.9

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \color{blue}{\left(x.im - \frac{x.re \cdot y.im}{y.re}\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification12.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \leq -3.6431575460204783 \cdot 10^{+168}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \left(\frac{y.im \cdot x.re}{y.re} - x.im\right)\\ \mathbf{elif}\;y.re \leq -4.650305513891855 \cdot 10^{-126}:\\ \;\;\;\;\frac{\frac{y.re \cdot x.im - y.im \cdot x.re}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \leq 1.184468592590644 \cdot 10^{-129}:\\ \;\;\;\;\frac{y.re \cdot x.im}{y.im \cdot y.im} - \frac{x.re}{y.im}\\ \mathbf{elif}\;y.re \leq 2.4176762365015643 \cdot 10^{+126}:\\ \;\;\;\;\frac{\frac{y.re \cdot x.im - y.im \cdot x.re}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \left(x.im - \frac{y.im \cdot x.re}{y.re}\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022068 
(FPCore (x.re x.im y.re y.im)
  :name "_divideComplex, imaginary part"
  :precision binary64
  (/ (- (* x.im y.re) (* x.re y.im)) (+ (* y.re y.re) (* y.im y.im))))