This documentation is automatically generated by competitive-verifier/competitive-verifier
#include "tools/floor.hpp"
template <typename M, typename N>
constexpr std::common_type_t<M, N> floor(M x, N y) noexcept;
It returns $\left\lfloor \frac{x}{y} \right\rfloor$.
<M>
is a built-in integral type, tools::int128_t
or tools::uint128_t
.<N>
is a built-in integral type, tools::int128_t
or tools::uint128_t
.std::common_type_t<M, N>
.#ifndef TOOLS_FLOOR_HPP
#define TOOLS_FLOOR_HPP
#include <cassert>
#include <type_traits>
#include "tools/is_integral.hpp"
namespace tools {
template <typename M, typename N> requires (
::tools::is_integral_v<M> && !::std::is_same_v<::std::remove_cv_t<M>, bool> &&
::tools::is_integral_v<N> && !::std::is_same_v<::std::remove_cv_t<N>, bool>)
constexpr ::std::common_type_t<M, N> floor(const M x, const N y) noexcept {
assert(y != 0);
if (y >= 0) {
if (x >= 0) {
return x / y;
} else {
return (x + 1) / y - 1;
}
} else {
if (x > 0) {
return (x - 1) / y - 1;
} else {
return x / y;
}
}
}
}
#endif
#line 1 "tools/floor.hpp"
#include <cassert>
#include <type_traits>
#line 1 "tools/is_integral.hpp"
#line 5 "tools/is_integral.hpp"
namespace tools {
template <typename T>
struct is_integral : ::std::is_integral<T> {};
template <typename T>
inline constexpr bool is_integral_v = ::tools::is_integral<T>::value;
}
#line 7 "tools/floor.hpp"
namespace tools {
template <typename M, typename N> requires (
::tools::is_integral_v<M> && !::std::is_same_v<::std::remove_cv_t<M>, bool> &&
::tools::is_integral_v<N> && !::std::is_same_v<::std::remove_cv_t<N>, bool>)
constexpr ::std::common_type_t<M, N> floor(const M x, const N y) noexcept {
assert(y != 0);
if (y >= 0) {
if (x >= 0) {
return x / y;
} else {
return (x + 1) / y - 1;
}
} else {
if (x > 0) {
return (x - 1) / y - 1;
} else {
return x / y;
}
}
}
}