17#ifndef MICRO_TEST_PLUS_MATH_H_
18#define MICRO_TEST_PLUS_MATH_H_
31#pragma GCC diagnostic push
32#pragma GCC diagnostic ignored "-Wconversion"
34#pragma clang diagnostic ignored "-Wc++98-compat"
55 [[nodiscard]]
constexpr auto
58 return t < T{} ? -t : t;
65 [[nodiscard]]
constexpr auto
68 return (rhs < lhs) ? rhs : lhs;
74 template <
class T,
class Exp_T>
75 [[nodiscard]]
constexpr auto
76 pow (
const T base,
const Exp_T exp) -> T
79 return exp ? T (base *
pow (base, exp - Exp_T (1))) : T (1);
86 template <
class T,
char... Cs>
87 [[nodiscard]]
constexpr auto
92 ((Cs ==
'.' or Cs ==
'\'' or (Cs >=
'0' and Cs <=
'9')) and ...));
94 for (
const char c : { Cs... })
100 if (c >=
'0' and c <=
'9')
102 result = result * T (10) + T (c -
'0');
112 template <
class T,
char... Cs>
113 [[nodiscard]]
constexpr auto
116 constexpr const std::array cs{ Cs... };
119 while (cs[i++] !=
'.')
123 for (
auto j = i; j <
sizeof...(Cs); ++j)
125 result +=
pow (T (10),
sizeof...(Cs) - j) * T (cs[j] -
'0');
134 template <
class T,
char... Cs>
135 [[nodiscard]]
constexpr auto
138 constexpr const std::array cs{ Cs... };
141#pragma GCC diagnostic push
142#pragma GCC diagnostic ignored "-Wconversion"
144 while (cs[i++] !=
'.')
146#pragma GCC diagnostic pop
151 return T (
sizeof...(Cs)) - i + T (1);
158 template <
class T,
class Value_T>
159 [[nodiscard]]
constexpr auto
162 constexpr auto precision = Value_T (1e-7);
169#pragma GCC diagnostic push
170#if !defined(__clang__)
171#pragma GCC diagnostic ignored "-Warith-conversion"
173#if defined(__clang__)
174#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
177 tmp = value - T (value);
179#pragma GCC diagnostic pop
183 while (tmp > precision);
194#pragma GCC diagnostic pop
constexpr auto abs(const T t) -> T
Generic absolute of any value.
constexpr auto den() -> T
Compute the decimals of a number represented as an array of characters.
constexpr auto pow(const T base, const Exp_T exp) -> T
Generic 'power of', to raise base to exponent (base ^ exp).
constexpr auto num() -> T
Compute the integral value of a number represented as an array of characters.
constexpr auto den_size() -> T
Compute the number of decimal places of a number represented as an array of characters.
constexpr auto min_value(const T &lhs, const T &rhs) -> const T &
Generic minimum of two values.