Annotate noexcept and constexpr with HEDLEY, and add interval containment, ChaCha, and the dyadic range tables.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
875f09fec1
commit
0d8a5a8131
97 changed files with 9212 additions and 1159 deletions
|
|
@ -1,10 +1,12 @@
|
|||
/// @file grotto/piecewise.hpp
|
||||
/// @brief Horner evaluation of a cubic and a bound-selected piece.
|
||||
/// @details `eval_horner` evaluates one polynomial. `piecewise_eval` selects
|
||||
/// the piece whose upper bound is the first entry of `bounds`
|
||||
/// strictly greater than `x`.
|
||||
/// @author Ryan Henry <ryan.henry@ucalgary.ca>
|
||||
/// @brief
|
||||
/// @details
|
||||
/// @copyright Copyright (c) 2019-2023 Ryan Henry and others
|
||||
/// @copyright Copyright (c) 2019-2026 Ryan Henry and [others](@ref authors)
|
||||
/// @license Released under a GNU General Public v2.0 (GPLv2) license;
|
||||
/// see [LICENSE.md](@ref GPLv2) for details.
|
||||
/// see [LICENSE.md](@ref license) for details.
|
||||
|
||||
#ifndef LIBDPF_INCLUDE_GROTTO_PIECEWISE_HPP__
|
||||
#define LIBDPF_INCLUDE_GROTTO_PIECEWISE_HPP__
|
||||
|
|
@ -13,6 +15,8 @@
|
|||
#include <iterator>
|
||||
#include <algorithm>
|
||||
|
||||
#include "hedley/hedley.h"
|
||||
|
||||
namespace grotto
|
||||
{
|
||||
|
||||
|
|
@ -25,16 +29,26 @@ template <typename T> using poly_quadratic = std::array<T, 3>;
|
|||
template <typename T> using poly_cubic = std::array<T, 4>;
|
||||
|
||||
template <typename T>
|
||||
constexpr auto eval_horner(const poly_constant<T> & f, T x) { return f[0]; }
|
||||
HEDLEY_PURE
|
||||
HEDLEY_NO_THROW
|
||||
constexpr auto eval_horner(const poly_constant<T> & f, T x) noexcept { return f[0]; }
|
||||
template <typename T>
|
||||
constexpr auto eval_horner(const poly_linear<T> & f, T x) { return f[1] * x + f[0]; }
|
||||
HEDLEY_PURE
|
||||
HEDLEY_NO_THROW
|
||||
constexpr auto eval_horner(const poly_linear<T> & f, T x) noexcept { return f[1] * x + f[0]; }
|
||||
template <typename T>
|
||||
constexpr auto eval_horner(const poly_quadratic<T> & f, T x) { return (f[2] * x + f[1]) * x + f[0]; }
|
||||
HEDLEY_PURE
|
||||
HEDLEY_NO_THROW
|
||||
constexpr auto eval_horner(const poly_quadratic<T> & f, T x) noexcept { return (f[2] * x + f[1]) * x + f[0]; }
|
||||
template <typename T>
|
||||
constexpr auto eval_horner(const poly_cubic<T> & f, T x) { return ((f[3] * x + f[2]) * x + f[1]) * x + f[0]; }
|
||||
HEDLEY_PURE
|
||||
HEDLEY_NO_THROW
|
||||
constexpr auto eval_horner(const poly_cubic<T> & f, T x) noexcept { return ((f[3] * x + f[2]) * x + f[1]) * x + f[0]; }
|
||||
|
||||
template <typename T, std::size_t D, std::size_t N1, std::size_t N2>
|
||||
auto piecewise_eval(const std::array<std::array<T, D>, N1> & polys, const std::array<T, N2> & bounds, T x)
|
||||
HEDLEY_PURE
|
||||
HEDLEY_NO_THROW
|
||||
auto piecewise_eval(const std::array<std::array<T, D>, N1> & polys, const std::array<T, N2> & bounds, T x) noexcept
|
||||
{
|
||||
auto it = std::upper_bound(std::cbegin(bounds), std::cend(bounds), x,
|
||||
[](const T & lhs, const T & rhs){ return lhs < rhs; });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue