Average Error: 26.0 → 12.8
Time: 13.9s
Precision: 64
\[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
\[\begin{array}{l} \mathbf{if}\;y.re \le -1.01458341645274 \cdot 10^{+165}:\\ \;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 2.0408764461888536 \cdot 10^{+156}:\\ \;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{x.im \cdot y.re - x.re \cdot y.im}}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \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}
\mathbf{if}\;y.re \le -1.01458341645274 \cdot 10^{+165}:\\
\;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\

\mathbf{elif}\;y.re \le 2.0408764461888536 \cdot 10^{+156}:\\
\;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{x.im \cdot y.re - x.re \cdot y.im}}}{\mathsf{hypot}\left(y.re, y.im\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\

\end{array}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r1269781 = x_im;
        double r1269782 = y_re;
        double r1269783 = r1269781 * r1269782;
        double r1269784 = x_re;
        double r1269785 = y_im;
        double r1269786 = r1269784 * r1269785;
        double r1269787 = r1269783 - r1269786;
        double r1269788 = r1269782 * r1269782;
        double r1269789 = r1269785 * r1269785;
        double r1269790 = r1269788 + r1269789;
        double r1269791 = r1269787 / r1269790;
        return r1269791;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r1269792 = y_re;
        double r1269793 = -1.01458341645274e+165;
        bool r1269794 = r1269792 <= r1269793;
        double r1269795 = x_im;
        double r1269796 = -r1269795;
        double r1269797 = y_im;
        double r1269798 = hypot(r1269792, r1269797);
        double r1269799 = r1269796 / r1269798;
        double r1269800 = 2.0408764461888536e+156;
        bool r1269801 = r1269792 <= r1269800;
        double r1269802 = 1.0;
        double r1269803 = r1269795 * r1269792;
        double r1269804 = x_re;
        double r1269805 = r1269804 * r1269797;
        double r1269806 = r1269803 - r1269805;
        double r1269807 = r1269798 / r1269806;
        double r1269808 = r1269802 / r1269807;
        double r1269809 = r1269808 / r1269798;
        double r1269810 = r1269795 / r1269798;
        double r1269811 = r1269801 ? r1269809 : r1269810;
        double r1269812 = r1269794 ? r1269799 : r1269811;
        return r1269812;
}

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 3 regimes
  2. if y.re < -1.01458341645274e+165

    1. Initial program 44.3

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt44.3

      \[\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}}}\]
    4. Applied associate-/r*44.3

      \[\leadsto \color{blue}{\frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    5. Using strategy rm
    6. Applied fma-neg44.3

      \[\leadsto \frac{\frac{\color{blue}{\mathsf{fma}\left(x.im, y.re, \left(-x.re \cdot y.im\right)\right)}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}\]
    7. Using strategy rm
    8. Applied hypot-def44.3

      \[\leadsto \frac{\frac{\mathsf{fma}\left(x.im, y.re, \left(-x.re \cdot y.im\right)\right)}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\color{blue}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    9. Taylor expanded around -inf 12.7

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

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

    if -1.01458341645274e+165 < y.re < 2.0408764461888536e+156

    1. Initial program 19.6

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt19.6

      \[\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}}}\]
    4. Applied associate-/r*19.5

      \[\leadsto \color{blue}{\frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    5. Using strategy rm
    6. Applied fma-neg19.5

      \[\leadsto \frac{\frac{\color{blue}{\mathsf{fma}\left(x.im, y.re, \left(-x.re \cdot y.im\right)\right)}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}\]
    7. Using strategy rm
    8. Applied hypot-def19.5

      \[\leadsto \frac{\frac{\mathsf{fma}\left(x.im, y.re, \left(-x.re \cdot y.im\right)\right)}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\color{blue}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    9. Using strategy rm
    10. Applied clear-num19.6

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

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

    if 2.0408764461888536e+156 < y.re

    1. Initial program 44.7

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt44.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}}}\]
    4. Applied associate-/r*44.7

      \[\leadsto \color{blue}{\frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    5. Using strategy rm
    6. Applied fma-neg44.7

      \[\leadsto \frac{\frac{\color{blue}{\mathsf{fma}\left(x.im, y.re, \left(-x.re \cdot y.im\right)\right)}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}\]
    7. Using strategy rm
    8. Applied hypot-def44.7

      \[\leadsto \frac{\frac{\mathsf{fma}\left(x.im, y.re, \left(-x.re \cdot y.im\right)\right)}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\color{blue}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    9. Taylor expanded around inf 14.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -1.01458341645274 \cdot 10^{+165}:\\ \;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 2.0408764461888536 \cdot 10^{+156}:\\ \;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{x.im \cdot y.re - x.re \cdot y.im}}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \end{array}\]

Reproduce

herbie shell --seed 2019128 +o rules:numerics
(FPCore (x.re x.im y.re y.im)
  :name "_divideComplex, imaginary part"
  (/ (- (* x.im y.re) (* x.re y.im)) (+ (* y.re y.re) (* y.im y.im))))