(FPCore (x) :precision binary64 (- (/ x x) (* (/ 1.0 x) (sqrt (* x x)))))
(FPCore (x) :precision binary64 (- 1.0 (/ (fabs x) x)))
double code(double x) {
return (x / x) - ((1.0 / x) * sqrt((x * x)));
}
double code(double x) {
return 1.0 - (fabs(x) / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x / x) - ((1.0d0 / x) * sqrt((x * x)))
end function
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 - (abs(x) / x)
end function
public static double code(double x) {
return (x / x) - ((1.0 / x) * Math.sqrt((x * x)));
}
public static double code(double x) {
return 1.0 - (Math.abs(x) / x);
}
def code(x): return (x / x) - ((1.0 / x) * math.sqrt((x * x)))
def code(x): return 1.0 - (math.fabs(x) / x)
function code(x) return Float64(Float64(x / x) - Float64(Float64(1.0 / x) * sqrt(Float64(x * x)))) end
function code(x) return Float64(1.0 - Float64(abs(x) / x)) end
function tmp = code(x) tmp = (x / x) - ((1.0 / x) * sqrt((x * x))); end
function tmp = code(x) tmp = 1.0 - (abs(x) / x); end
code[x_] := N[(N[(x / x), $MachinePrecision] - N[(N[(1.0 / x), $MachinePrecision] * N[Sqrt[N[(x * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(1.0 - N[(N[Abs[x], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
1 - \frac{\left|x\right|}{x}




Bits error versus x
Results
| Original | 32.8 |
|---|---|
| Target | 0 |
| Herbie | 0 |
Initial program 32.8
Simplified0
Final simplification0
herbie shell --seed 2022150
(FPCore (x)
:name "sqrt sqr"
:precision binary64
:herbie-target
(if (< x 0.0) 2.0 0.0)
(- (/ x x) (* (/ 1.0 x) (sqrt (* x x)))))