2015-12-08 04:51:55 +08:00
|
|
|
#pragma once
|
2015-09-13 17:34:17 +08:00
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
namespace num
|
|
|
|
{
|
|
|
|
|
|
|
|
template <class T,
|
|
|
|
typename std::enable_if<std::is_integral<T>::value>::type* = nullptr>
|
|
|
|
T iceil(T x, T y)
|
|
|
|
{
|
|
|
|
// this may seem inefficient, but on x86_64, when you already perform
|
|
|
|
// division (x / y) the remainder is already computed and therefore x % y
|
|
|
|
// is basically free!
|
|
|
|
return x / y + (x % y != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|