Audacity 3.2.0
RoundUpUnsafe.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 RoundUpUnsafe.h
6
7 Dmitry Vedenko
8
9*******************************************************************/
10#pragma once
11
13
20template <typename LType, typename RType>
21auto RoundUpUnsafe(LType numerator, RType denominator) noexcept
22{
23 static_assert(std::is_integral_v<LType>);
24 static_assert(std::is_integral_v<RType>);
25
26 if constexpr (std::is_unsigned_v<LType> && std::is_unsigned_v<RType>)
27 {
28 return (numerator + denominator - 1) / denominator;
29 }
30 else
31 {
32 if (numerator > 0 && denominator > 0)
33 {
34 return (numerator + denominator - 1) / denominator;
35 }
36 else
37 {
38 const auto result = numerator / denominator;
39
40 if (result < 0 || result * denominator == numerator)
41 return result;
42 else
43 return result + 1;
44 }
45 }
46}
auto RoundUpUnsafe(LType numerator, RType denominator) noexcept
Returns a rounded up integer result for numerator / denominator.
Definition: RoundUpUnsafe.h:21