4#ifndef QCALENDARMATH_P_H
5#define QCALENDARMATH_P_H
18#include <QtCore/private/qglobal_p.h>
19#include <QtCore/QtAlgorithms>
25namespace QRoundingDownPrivate {
28#define QCALMATH_ISPOW2(b) ((b > 0) && !(b & (b - 1)))
35template <
typename Int>
37#define QCALMATH_ISPOW2(b) QRoundingDownPrivate::isPowerOfTwo(b)
61template <
unsigned b,
typename Int, std::enable_if_t<(
int(b) < 2),
bool> = true>
62constexpr auto qDivMod(Int)
64 static_assert(b, "Division by 0 is undefined");
66 static_assert(!b ||
int(b) > 0,
"Denominator is too big");
67 static_assert(int(
b) < 1 ||
b > 1,
"Division by 1 is fautous");
68 struct R {
Int quotient;
Int remainder; };
72template <
unsigned b,
typename Int,
77 struct R {
Int quotient;
Int remainder; };
78 if constexpr (std::is_signed_v<Int>) {
81 return R {
Int(
a /
int(
b) - 1),
Int(
a %
int(
b) - 1 +
int(
b)) };
87template <
unsigned b,
typename Int,
93 struct R {
Int quotient;
Int remainder; };
94 if constexpr (std::is_signed_v<Int>) {
96 return R {
Int((
a + 1) /
int(
b) - 1),
Int(
a &
int(
b - 1)) };
101#undef QCALMATH_ISPOW2
104template <
unsigned b,
typename Int>
constexpr Int qDiv(
Int a) {
return qDivMod<b>(
a).quotient; }
105template <
unsigned b,
typename Int>
constexpr Int qMod(
Int a) {
return qDivMod<b>(
a).remainder; }
127 return R { year, QRoundingDown::qDiv<5>(
FiveMonths * month + 2) };
133 struct R {
int year;
int month;
int day; };
136 const auto month5Day = qDivMod<FiveMonths>(5 * dayInYear + 2);
138 const auto yearMonth = qDivMod<12>(month5Day.quotient + 2);
139 return R { yearMonth.quotient, yearMonth.remainder + 1, qDiv<5>(month5Day.remainder) + 1 };
constexpr qint64 LeapDayGregorian1Bce
constexpr auto dayInYearToYmd(int dayInYear)
constexpr auto yearMonthToYearDays(int year, int month)
constexpr unsigned FourYears
constexpr unsigned FiveMonths
constexpr bool isPowerOfTwo(Int b)
constexpr Int qDiv(Int a)
constexpr Int qMod(Int a)
constexpr auto qDivMod(Int)
Combined button and popup list for selecting options.
constexpr uint qConstexprCountTrailingZeroBits(quint32 v) noexcept
#define QCALMATH_ISPOW2(b)
GLboolean GLboolean GLboolean b
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]