11namespace hi::inline v1 {
13template<
typename T, std::
size_t N>
18 using const_iterator =
typename array_type::const_iterator;
20 constexpr results() noexcept : _size(0), _v() {}
26 constexpr results(value_type a) noexcept : _size(1), _v()
31 constexpr results(value_type a, value_type b) noexcept : _size(2), _v()
37 constexpr results(value_type a, value_type b, value_type c) noexcept : _size(3), _v()
44 template<std::
size_t O>
45 constexpr results(
results<T, O> const& other)
noexcept requires(O < N) : _size(other._size), _v()
47 if constexpr (O > 0) {
48 for (
auto i = 0_uz; i < other._size; i++) {
54 [[nodiscard]]
constexpr std::size_t capacity()
const noexcept
59 [[nodiscard]]
constexpr std::size_t size()
const noexcept
64 [[nodiscard]]
constexpr const_iterator begin()
const noexcept
69 [[nodiscard]]
constexpr const_iterator end()
const noexcept
71 return _v.begin() + size();
74 [[nodiscard]]
constexpr value_type
const& operator[](
std::size_t index)
const noexcept
76 hi_axiom(index < _size);
80 [[nodiscard]]
constexpr value_type& operator[](
std::size_t index)
noexcept
82 hi_axiom(index < _size);
86 constexpr void add(T a)
noexcept
88 hi_axiom(_size < _capacity);
92 [[nodiscard]]
constexpr friend results operator-(
results lhs, value_type rhs)
noexcept
96 for (
auto i = 0_uz; i < lhs._capacity; i++) {
108 template<
typename O, std::
size_t M>
113template<
typename T, std::
size_t N>
117 hi_assert(r.size() <= r.capacity());
118 for (
auto i = 0_uz; i < r.size(); i++) {
141hi_force_inline
constexpr results<T, 1> solvePolynomial(T
const& a, T
const& b)
noexcept
168hi_force_inline
constexpr results<T, 2> solvePolynomial(T
const& a, T
const& b, T
const& c)
noexcept
171 return solvePolynomial(b, c);
173 hilet D = b * b -
static_cast<T
>(4) * a * c;
177 return {-b / (
static_cast<T
>(2) * a)};
180 return {(-b - Dsqrt) / (
static_cast<T
>(2) * a), (-b + Dsqrt) / (
static_cast<T
>(2) * a)};
188hi_force_inline results<T, 3> solveDepressedCubicTrig(T
const& p, T
const& q)
noexcept
190 constexpr T oneThird =
static_cast<T
>(1) /
static_cast<T
>(3);
191 constexpr T pi2_3 = (
static_cast<T
>(2) /
static_cast<T
>(3)) * std::numbers::pi_v<T>;
192 constexpr T pi4_3 = (
static_cast<T
>(4) /
static_cast<T
>(3)) * std::numbers::pi_v<T>;
194 hilet U = oneThird *
acos(((
static_cast<T
>(3) * q) / (
static_cast<T
>(2) * p)) *
sqrt(
static_cast<T
>(-3) / p));
195 hilet V =
static_cast<T
>(2) *
sqrt(-oneThird * p);
204hi_force_inline results<T, 3> solveDepressedCubicCardano(T
const& p, T
const& q, T
const& D)
noexcept
207 hilet minusHalfQ =
static_cast<T
>(-0.5) * q;
230hi_force_inline results<T, 3> solveDepressedCubic(T
const& p, T
const& q)
noexcept
232 constexpr T oneForth =
static_cast<T
>(1) /
static_cast<T
>(4);
233 constexpr T oneTwentySeventh =
static_cast<T
>(1) /
static_cast<T
>(27);
235 if (p == 0.0 && q == 0.0) {
236 return {
static_cast<T
>(0)};
239 hilet D = oneForth * q * q + oneTwentySeventh * p * p * p;
241 if (D < 0 && p != 0.0) {
243 return solveDepressedCubicTrig(p, q);
245 }
else if (D == 0 && p != 0.0) {
247 hilet t0 = (
static_cast<T
>(3) * q) / p;
248 hilet t1 = (
static_cast<T
>(-3) * q) / (
static_cast<T
>(2) * p);
253 return solveDepressedCubicCardano(p, q, D);
267hi_force_inline
constexpr results<T, 3> solvePolynomial(T
const& a, T
const& b, T
const& c, T
const& d)
noexcept
270 return solvePolynomial(b, c, d);
273 hilet p = (
static_cast<T
>(3) * a * c - b * b) / (
static_cast<T
>(3) * a * a);
274 hilet q = (
static_cast<T
>(2) * b * b * b -
static_cast<T
>(9) * a * b * c +
static_cast<T
>(27) * a * a * d) /
275 (
static_cast<T
>(27) * a * a * a);
277 hilet r = solveDepressedCubic(p, q);
279 hilet b_3a = b / (
static_cast<T
>(3) * a);
#define hilet
Invariant should be the default for variables.
Definition required.hpp:23
Definition polynomial.hpp:14