Does R have a known problem with uniroot and handling floating points?
>str(uniroot(function(x) x*(x^2-1) + .5, lower = -2, upper = 2,
+ tol = 0.0001))
List of 4
$ root : num -1.19
$ f.root : num -2.55e-07
$ iter : int 7
$ estim.prec: num 5e-05
> -1.19 * ( 1.19 ^ 2 - 1 ) + 0.5
[1] 0.004841
Clearly the value of f.root is not equal to the value of the function calculated by hand.
Your value of root is shown to only 2 s.f., but it estimates the precision at 5e-5. That suggests it “knows” other digits in the answer that you are not looking at. Try to print out
root-1.19and you will see what I mean.In particular,
stris intended as a quick way to view the structure of an R object, so it intentionally prints a limited number of digits: the default value ofdigits.dis 3 (see?str). Just printing the results (as inuniroot(...)oru1 <- uniroot(...); u1would have shown you more digits and perhaps have avoided the confusion.