/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Copyright 2015 Danny Robson */ #ifndef CRUFT_UTIL_POLYNOMIAL_HPP #define CRUFT_UTIL_POLYNOMIAL_HPP #include #include namespace cruft::polynomial { // Invalid solutions are represented by NaN. They are guaranteed to // be at the end of the solution list, so they are safe to skip on the // first instance. template std::array roots (std::array); template T eval (std::array coeffs, U x) { U x_ = 1.f; T sum {0.f}; for (size_t i = 0; i < S; ++i) { sum += coeffs[S-i-1] * x_; x_ *= x; } return sum; } } #endif