Arduino Filters master
Filter library for Arduino
Divide.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <AH/STL/cstdint>
4#include <AH/STL/type_traits>
7#include <stddef.h>
8
10
12
16template <uint8_t N, class T>
18 static T div(T val) { return val / N; }
19};
20
22template <uint8_t N, class T>
24 static T div(T val) {
25 return (val + (N / 2)) / N;
26 static_assert(std::is_unsigned<T>::value && std::is_integral<T>::value,
27 "This function is only valid for unsigned integers");
28 }
29};
30
32template <uint8_t N, class T>
34 static T div(T val) {
35 T offset = val >= 0 ? (N / 2) : (-N / 2);
36 return (val + offset) / N;
37 }
38};
39
42template <uint8_t N, class T>
44 : std::conditional<std::is_signed<T>::value, round_div_signed_int<N, T>,
45 round_div_unsigned_int<N, T>>::type {};
46
49template <uint8_t N, class T>
51 : std::conditional<std::is_integral<T>::value, round_div_int<N, T>,
52 round_div_default<N, T>>::type {};
53
56template <size_t N, class T>
57T round_div(T val) {
59}
60
62
T round_div(T val)
Divide a number by N and round the result.
Definition: Divide.hpp:57
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:36
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:35
Divide by N using the default division operator, without explicit rounding This should be used for fl...
Definition: Divide.hpp:17
static T div(T val)
Definition: Divide.hpp:18
Select the right rounding division operator, depending on whether T is an integer or not.
Definition: Divide.hpp:52
Select the right rounding division operator, depending on whether T is a signed or unsigned integer.
Definition: Divide.hpp:45
Divide a signed integer by N, rounding the result.
Definition: Divide.hpp:33
static T div(T val)
Definition: Divide.hpp:34
Divide an unsigned integer by N, rounding the result.
Definition: Divide.hpp:23
static T div(T val)
Definition: Divide.hpp:24