src/util/func_fp/lib.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "../consts/lib.hpp" | ||
| 4 | #include "../traits/math/lib.hpp" | ||
| 5 | |||
| 6 | namespace tifa_libs { | ||
| 7 | |||
| 8 | template <sint_c T> | ||
| 9 | 1067403974 | CEXP int sgn(T x) NE { return (!!x) | (x >> (sizeof(T) * 8 - 1)); } | |
| 10 | CEXP int sgn(uint_c auto x) NE { return !!x; } | ||
| 11 | template <std::floating_point FP> | ||
| 12 | 4464778473 | CEXP int sgn(FP x) NE { return (x > eps_v<FP>)-(x < -eps_v<FP>); } | |
| 13 | |||
| 14 | template <class FP> | ||
| 15 | 666992 | CEXP bool is_neg(FP x) NE { return sgn(x) < 0; } | |
| 16 | template <class FP> | ||
| 17 | 43986016 | CEXP bool is_zero(FP x) NE { return !sgn(x); } | |
| 18 | template <class FP> | ||
| 19 | 68599855 | CEXP bool is_pos(FP x) NE { return sgn(x) > 0; } | |
| 20 | |||
| 21 | 693931900 | CEXP int comp(sint_c auto l, sint_c auto r) NE { return sgn(l - r); } | |
| 22 | 20000000 | CEXP int comp(uint_c auto l, uint_c auto r) NE { return (!!(l - r)) | -(l < r); } | |
| 23 | template <std::floating_point FP> | ||
| 24 | 3182136907 | CEXP int comp(FP l, FP r) NE { return sgn((l - r) / max({abs(l), abs(r), FP(1)})); } | |
| 25 | |||
| 26 | template <class FP> | ||
| 27 | 96425043 | CEXP bool is_lt(FP l, FP r) NE { return comp(l, r) < 0; } | |
| 28 | template <class FP> | ||
| 29 | 102754775 | CEXP bool is_eq(FP l, FP r) NE { return !comp(l, r); } | |
| 30 | template <class FP> | ||
| 31 | 3772131 | CEXP bool is_gt(FP l, FP r) NE { return comp(l, r) > 0; } | |
| 32 | |||
| 33 | //! containing endpoints | ||
| 34 |
9/12bool tifa_libs::is_in_middle<double, double, double>(double, double, double):
✓ Branch 1 taken 18649 times.
✓ Branch 2 taken 1937 times.
✓ Branch 4 taken 18606 times.
✓ Branch 5 taken 43 times.
✓ Branch 6 taken 4441 times.
✓ Branch 7 taken 14165 times.
bool tifa_libs::is_in_middle<long double, long double, long double>(long double, long double, long double):
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
|
20598 | CEXP bool is_in_middle(arithm_c auto l, arithm_c auto mid, arithm_c auto r) NE { return is_eq(l, mid) || is_eq(r, mid) || ((l < mid) ^ (r < mid)); } |
| 35 | |||
| 36 | //! containing endpoints | ||
| 37 | template <class FP> | ||
| 38 | 16862 | CEXP bool is_intersect(FP l1, FP r1, FP l2, FP r2) NE { | |
| 39 |
2/2✓ Branch 0 taken 7532 times.
✓ Branch 1 taken 9330 times.
|
16862 | if (l1 > r1) swap(l1, r1); |
| 40 |
2/2✓ Branch 0 taken 8411 times.
✓ Branch 1 taken 8451 times.
|
16862 | if (l2 > r2) swap(l2, r2); |
| 41 |
4/4✓ Branch 1 taken 11521 times.
✓ Branch 2 taken 5341 times.
✓ Branch 4 taken 8326 times.
✓ Branch 5 taken 3195 times.
|
16862 | return !(is_lt(r1, l2) || is_lt(r2, l1)); |
| 42 | } | ||
| 43 | |||
| 44 | } // namespace tifa_libs | ||
| 45 |