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 T q = a / b;
16 T r = a % b;
17 if (r != 0 && a < 0) --q;
18 return q;
19 }
20
22 template<class T>
23 TIME_SHIELD_CONSTEXPR inline T floor_mod(T a, T b) noexcept {
24 T r = a % b;
25 if (r < 0) r += b;
26 return r;
27 }
28
29} // namespace detail
30} // namespace time_shield
31
32#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.