Audacity 3.2.0
Functions
RoundUpUnsafe.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename LType , typename RType >
auto RoundUpUnsafe (LType numerator, RType denominator) noexcept
 Returns a rounded up integer result for numerator / denominator. More...
 

Function Documentation

◆ RoundUpUnsafe()

template<typename LType , typename RType >
auto RoundUpUnsafe ( LType  numerator,
RType  denominator 
)
noexcept

Returns a rounded up integer result for numerator / denominator.

RoundUpUnsafe(4, 2) == 2; RoundUpUnsafe(3, 2) == 2; RoundUpUnsafe(-3, 2) == -1;

This function does not check if denominator is 0 of if there is an integer overflow.

Definition at line 21 of file RoundUpUnsafe.h.

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}

Referenced by anonymous_namespace{WaveDataCache.cpp}::AppendBufferHelper::FillBlocksFromAppendBuffer(), anonymous_namespace{WaveDataCache.cpp}::AppendBufferHelper::FillBuffer(), anonymous_namespace{WaveDataCache.cpp}::MakeDefaultDataProvider(), GraphicsDataCacheBase::PerformCleanup(), and anonymous_namespace{WaveDataCache.cpp}::processBlock().

Here is the caller graph for this function: