Time Shield Library
C++ library for working with time
Loading...
Searching...
No Matches
floor_math.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2#pragma once
3#ifndef _TIME_SHIELD_DETAIL_FLOOR_MATH_HPP_INCLUDED
4#define _TIME_SHIELD_DETAIL_FLOOR_MATH_HPP_INCLUDED
5
8
9namespace time_shield {
10namespace detail {
11
13 template<class T>
14 TIME_SHIELD_CONSTEXPR inline T floor_div(T a, T b) noexcept {
15 return static_cast<T>((a / b) - (((a % b) != 0 && a < 0) ? 1 : 0));
16 }
17
19 template<class T>
20 TIME_SHIELD_CONSTEXPR inline T floor_mod(T a, T b) noexcept {
21 return static_cast<T>((a % b) + (((a % b) < 0) ? b : 0));
22 }
23
24} // namespace detail
25} // namespace time_shield
26
27#endif // _TIME_SHIELD_DETAIL_FLOOR_MATH_HPP_INCLUDED
TIME_SHIELD_CONSTEXPR T floor_mod(T a, T b) noexcept
Floor-mod for positive modulus (returns r in [0..b)).
TIME_SHIELD_CONSTEXPR T floor_div(T a, T b) noexcept
Floor division for positive divisor.
Main namespace for the Time Shield library.