7#include "../utility/utility.hpp"
8#include "../macros.hpp"
16template<
typename T, std::
size_t N>
21 using const_iterator =
typename array_type::const_iterator;
23 constexpr results() noexcept : _size(0), _v() {}
29 constexpr results(value_type a) noexcept : _size(1), _v()
34 constexpr results(value_type a, value_type b) noexcept : _size(2), _v()
40 constexpr results(value_type a, value_type b, value_type c) noexcept : _size(3), _v()
47 template<std::
size_t O>
48 constexpr results(
results<T, O> const& other)
noexcept requires(O < N) : _size(other._size), _v()
50 if constexpr (O > 0) {
51 for (
auto i = 0_uz; i < other._size; i++) {
57 [[nodiscard]]
constexpr std::size_t capacity()
const noexcept
62 [[nodiscard]]
constexpr std::size_t size()
const noexcept
67 [[nodiscard]]
constexpr const_iterator begin()
const noexcept
72 [[nodiscard]]
constexpr const_iterator end()
const noexcept
74 return _v.begin() + size();
77 [[nodiscard]]
constexpr value_type
const& operator[](
std::size_t index)
const noexcept
79 hi_axiom(index < _size);
83 [[nodiscard]]
constexpr value_type& operator[](
std::size_t index)
noexcept
85 hi_axiom(index < _size);
89 constexpr void add(T a)
noexcept
91 hi_axiom(_size < _capacity);
95 [[nodiscard]]
constexpr friend results operator-(
results lhs, value_type rhs)
noexcept
99 for (
auto i = 0_uz; i < lhs._capacity; i++) {
111 template<
typename O, std::
size_t M>
116template<
typename T, std::
size_t N>
120 hi_assert(r.size() <= r.capacity());
121 for (
auto i = 0
_uz; i < r.size(); i++) {
176 hilet D = b * b -
static_cast<T
>(4) * a * c;
180 return {-b / (
static_cast<T
>(2) * a)};
182 hilet
Dsqrt = sqrt(D);
183 return {(-b -
Dsqrt) / (
static_cast<T
>(2) * a), (-b +
Dsqrt) / (
static_cast<T
>(2) * a)};
193 constexpr T
oneThird =
static_cast<T
>(1) /
static_cast<T
>(3);
194 constexpr T
pi2_3 = (
static_cast<T
>(2) /
static_cast<T
>(3)) * std::numbers::pi_v<T>;
195 constexpr T
pi4_3 = (
static_cast<T
>(4) /
static_cast<T
>(3)) * std::numbers::pi_v<T>;
197 hilet U =
oneThird * acos(((
static_cast<T
>(3) *
q) / (
static_cast<T
>(2) * p)) * sqrt(
static_cast<T
>(-3) / p));
198 hilet V =
static_cast<T
>(2) * sqrt(-
oneThird * p);
200 hilet
t0 = V * cos(U);
207hi_force_inline
results<T, 3> solveDepressedCubicCardano(T
const& p, T
const&
q, T
const& D)
noexcept
209 hilet
sqrtD = sqrt(D);
235 constexpr T
oneForth =
static_cast<T
>(1) /
static_cast<T
>(4);
238 if (p == 0.0 &&
q == 0.0) {
239 return {
static_cast<T
>(0)};
244 if (D < 0 && p != 0.0) {
248 }
else if (D == 0 && p != 0.0) {
250 hilet
t0 = (
static_cast<T
>(3) *
q) / p;
251 hilet
t1 = (
static_cast<T
>(-3) *
q) / (
static_cast<T
>(2) * p);
256 return solveDepressedCubicCardano(p,
q, D);
276 hilet p = (
static_cast<T
>(3) * a * c - b * b) / (
static_cast<T
>(3) * a * a);
277 hilet
q = (
static_cast<T
>(2) * b * b * b -
static_cast<T
>(9) * a * b * c +
static_cast<T
>(27) * a * a * d) /
278 (
static_cast<T
>(27) * a * a * a);
282 hilet
b_3a = b / (
static_cast<T
>(3) * a);
DOXYGEN BUG.
Definition algorithm.hpp:16
hi_force_inline results< T, 3 > solveDepressedCubicTrig(T const &p, T const &q) noexcept
Definition polynomial.hpp:191
hi_force_inline constexpr results< T, 1 > solvePolynomial(T const &a, T const &b) noexcept
Definition polynomial.hpp:144
hi_force_inline results< T, 3 > solveDepressedCubic(T const &p, T const &q) noexcept
Definition polynomial.hpp:233
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Definition polynomial.hpp:17