Average Error: 31.5 → 0.0
Time: 390.0ms
Precision: 64
\[\sqrt{re \cdot re + im \cdot im}\]
\[\mathsf{hypot}\left(re, im\right)\]
\sqrt{re \cdot re + im \cdot im}
\mathsf{hypot}\left(re, im\right)
double code(double re, double im) {
	return sqrt(((re * re) + (im * im)));
}
double code(double re, double im) {
	return hypot(re, im);
}

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 31.5

    \[\sqrt{re \cdot re + im \cdot im}\]
  2. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{hypot}\left(re, im\right)}\]
  3. Final simplification0.0

    \[\leadsto \mathsf{hypot}\left(re, im\right)\]

Reproduce

herbie shell --seed 2020053 +o rules:numerics
(FPCore (re im)
  :name "math.abs on complex"
  :precision binary64
  (sqrt (+ (* re re) (* im im))))