62template <
typename I>
constexpr bool isBetween(I n, sal_Int64 min, sal_Int64 max)
64 assert(
max > 0 &&
min < 0);
65 if constexpr (std::is_signed_v<I>)
68 return n <= sal_uInt64(
max);
72template <
typename I, std::enable_if_t<std::is_
integral_v<I>,
int> = 0>
73constexpr sal_Int64
MulDiv(I n, sal_Int64 m, sal_Int64 d)
75 assert(
m > 0 &&
d > 0);
77 return (
n >= 0 ? (
n *
m +
d / 2) : (
n *
m -
d / 2)) /
d;
79template <
typename F, std::enable_if_t<std::is_
floating_po
int_v<F>,
int> = 0>
80constexpr double MulDiv(F f, sal_Int64 m, sal_Int64 d)
82 assert(
m > 0 &&
d > 0);
83 return f * (double(
m) /
d);
86template <
typename I, std::enable_if_t<std::is_
integral_v<I>,
int> = 0>
87constexpr sal_Int64
MulDiv(I n, sal_Int64 m, sal_Int64 d,
bool& bOverflow, sal_Int64 nDefault)
98template <
typename I, std::enable_if_t<std::is_
integral_v<I>,
int> = 0>
107 return saturating_add<sal_uInt64>(
n, d_2) /
d *
m;
109 else if constexpr (std::is_signed_v<I>)
113 return saturating_sub<sal_Int64>(
n, d_2) /
d *
m;
119template <
class M,
class N>
constexpr std::common_type_t<M, N>
asserting_gcd(M m, N n)
121 auto ret = std::gcd(
m,
n);
135 assert(_m > 0 && _d > 0);
144 std::array<std::array<sal_Int64, N>,
N>
a{};
145 for (
int i = 0;
i <
N; ++
i)
148 for (
int j = 0; j <
i; ++j)
152 const sal_Int64
m = mdBase[
i].m * mdBase[j].d,
d = mdBase[
i].d * mdBase[j].m;
162template <
typename U>
constexpr sal_Int64
md(U i, U ) {
return i; }
185 { 254 * 12 * 5280, 10 },
187 { 254 * 15, 10 * 1440 },
188 { 254 * 210, 10 * 1440 },
189 { 254 * 312, 10 * 1440 },
192 "mdBaseL must have an entry for each unit in o3tl::Length");
200 const int nI =
static_cast<int>(
i), nJ =
static_cast<int>(j);
210template <
typename N>
constexpr auto convert(N n, sal_Int64 mul, sal_Int64 div)
216template <
typename N,
typename U>
constexpr auto convert(N n, U from, U to)
229template <
typename N,
typename U>
230constexpr auto convert(N n, U from, U to,
bool& bOverflow, sal_Int64 nDefault = 0)
248template <
typename Out,
auto from,
auto to,
typename N,
250 std::is_integral_v<N> && std::is_integral_v<Out> &&
sizeof(
Out) <
sizeof(sal_Int64),
252constexpr Out convertNarrowing(N n)
254 constexpr sal_Int64 nMin =
convertSaturate(std::numeric_limits<Out>::min(), to, from);
255 constexpr sal_Int64 nMax =
convertSaturate(std::numeric_limits<Out>::max(), to, from);
256 if (
static_cast<sal_Int64
>(n) > nMax)
257 return std::numeric_limits<Out>::max();
258 if (
static_cast<sal_Int64
>(n) < nMin)
259 return std::numeric_limits<Out>::min();
264template <
typename U>
constexpr std::pair<sal_Int64, sal_Int64> getConversionMulDiv(U from, U to)
constexpr m_and_d mdBaseLen[]
constexpr bool isBetween(I n, sal_Int64 min, sal_Int64 max)
constexpr sal_Int64 MulDiv(I n, sal_Int64 m, sal_Int64 d)
constexpr auto prepareMDArray(const m_and_d(&mdBase)[N])
constexpr std::common_type_t< M, N > asserting_gcd(M m, N n)
constexpr sal_Int64 MulDivSaturate(I n, sal_Int64 m, sal_Int64 d)
constexpr sal_Int64 md(U i, U)
constexpr auto aLengthMDArray
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
constexpr auto convertSaturate(N n, U from, U to)
constexpr auto toTwips(N number, Length from)
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
double div(const double &fNumerator, const double &fDenominator)
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
constexpr m_and_d(sal_Int64 _m, sal_Int64 _d)
SwHTMLWriter & Out(const SwAttrFnTab, const SfxPoolItem &, SwHTMLWriter &)