Average Error: 26.0 → 12.8
Time: 1.1m
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 r4882295 = x_im;
        double r4882296 = y_re;
        double r4882297 = r4882295 * r4882296;
        double r4882298 = x_re;
        double r4882299 = y_im;
        double r4882300 = r4882298 * r4882299;
        double r4882301 = r4882297 - r4882300;
        double r4882302 = r4882296 * r4882296;
        double r4882303 = r4882299 * r4882299;
        double r4882304 = r4882302 + r4882303;
        double r4882305 = r4882301 / r4882304;
        return r4882305;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r4882306 = y_re;
        double r4882307 = -1.01458341645274e+165;
        bool r4882308 = r4882306 <= r4882307;
        double r4882309 = x_im;
        double r4882310 = -r4882309;
        double r4882311 = y_im;
        double r4882312 = hypot(r4882306, r4882311);
        double r4882313 = r4882310 / r4882312;
        double r4882314 = 2.0408764461888536e+156;
        bool r4882315 = r4882306 <= r4882314;
        double r4882316 = 1.0;
        double r4882317 = r4882309 * r4882306;
        double r4882318 = x_re;
        double r4882319 = r4882318 * r4882311;
        double r4882320 = r4882317 - r4882319;
        double r4882321 = r4882312 / r4882320;
        double r4882322 = r4882316 / r4882321;
        double r4882323 = r4882322 / r4882312;
        double r4882324 = r4882309 / r4882312;
        double r4882325 = r4882315 ? r4882323 : r4882324;
        double r4882326 = r4882308 ? r4882313 : r4882325;
        return r4882326;
}

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 - x.re \cdot y.im}}}}{\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))))