# More accurate evalpoly

**URL:** https://discourse.julialang.org/t/more-accurate-evalpoly/45932
**Category:** Numerics
**Tags:** precision
**Created:** [September 2, 2020, 4:33am UTC](https://discourse.julialang.org/t/more-accurate-evalpoly/45932 "2020-09-02T04:33:48Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [September 2, 2020, 3:54pm UTC](https://discourse.julialang.org/t/more-accurate-evalpoly/45932/6 "2020-09-02T15:54:48Z")

</div>

The fully accurate version is

```julia
@inline function two_sum(a, b)
    hi = a + b
    a1 = hi - b
    b1 = hi - a1
    lo = (a - a1) + (b - b1)
    return hi, lo
end

@inline function exthorner(x, p::Tuple)
    hi, lo = p[end], zero(x)
    for i in length(p)-1:-1:1
        pi = p[i]
        prod = hi*x
        err1 = fma(hi, x, -prod)
        hi,err2 = two_sum(pi,prod)
        lo = fma(lo, x, err1 + err2)
    end
    return hi, lo
end

```

It should be about another 2x slowdown, but will retain precision for polynomials where high order terms are bigger.

---

_[View the full topic](https://discourse.julialang.org/t/more-accurate-evalpoly/45932)._
