[Haskell-beginners] Error with floats in implementation of Horner's method.

Andrew Fleckenstein andrew.fleckenstein at gmail.com
Fri Dec 13 21:03:23 UTC 2013


Hi all,

I have implemented Horner's method for evaluating a polynomial as follows:

-- the nth horner element, given a list of coefficients and a value at
which it needs to be evaluated

horner_element l x n
    | n == (length l)-1 = last l
    | otherwise = (l !! n) + (horner_element l x (n+1))*x

-- compute a polynomial given as a list of coefficients at the value x
using horner's method.

horner l x = horner_element l x 0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20131213/5cdd2839/attachment.html>


More information about the Beginners mailing list