If I am not mistaken, you have \text{val} = \frac{(x-1)^2}{2(x-1)} for x=1. That simplifies to \frac{0}{0}, which is often considered undefined.
EDIT: Technically, you could evaluate the expression in the limit as x \to 0. Then \lim_{x \to 0} \frac{(x-1)^2}{2(x-1)} = \lim_{x \to 0} \frac{2(x - 1)}{2} = 0 (L’Hôpital’s rule). But this is not done automatically.
Indeed, running 0.0 / 0.0 in the REPL will return NaN, as specified by IEEE 754. This is what happens here since f(1) == 0 and df(1) == 0 and the division promotes the values to Float64.
You can take the limit analytically yourself, do the algebraic simplification yourself (or via a computer-algebra system like Symbolics.jl), or take a limit numerically, e.g. with Richardson.jl:
(an estimated limit and an estimated error bar). So it correctly finds that the limit is zero. (Depending on the starting x, there may be some roundoff error, e.g. if you replace 0.5 with 0.1 it finds a limit of about -4.77e-17 due to roundoff errors).
Obviously, your particular example in this thread is so simple that you should just use the analytical form manually, but I’m presuming that you are also interested in other cases that can’t be handled analytically so easily.