Skip to main content

math.h File

C++ header file with declarations for the µTest++ mathematical utilities. More...

Included Headers​

#include <array> #include <limits> #include "inlines/math-inlines.h"

Namespaces Index​

namespacemicro_os_plus

The primary namespace for the µOS++ framework. More...

namespacemicro_test_plus

Primary namespace for the µTest++ testing framework. More...

namespacedetail

Internal implementation details for the µTest++ framework. More...

namespacemath

Internal mathematical utilities for the µTest++ testing framework. More...

Functions Index​

template <class T>
constexpr Tabs (const T t) noexcept

Computes the absolute value of a given comparable value. More...

template <class T>
constexpr const T &min_value (const T &lhs, const T &rhs) noexcept

Computes the minimum of two comparable values. More...

Description​

C++ header file with declarations for the µTest++ mathematical utilities.

This header provides the declaration of the mathematical utility template used within the µTest++ framework: the absolute value, used by the approximate comparison; and, only if the deprecated functionality is enabled, the minimum value, used by the tolerance of the deprecated wrappers. The exponentiation and the compile-time parsing of the numeric literals, which serve only the deprecated wrappers and literals, are declared in deprecated.h.

These utilities are lightweight, constexpr, and support both integral and floating-point types.

All definitions reside within the micro_os_plus::micro_test_plus::detail::math namespace, since they are implementation details of the comparisons, not part of the public API.

This file is included by micro-os-plus/micro-test-plus.h, which is the header that the applications include.

Functions​

abs()​

template <class T>
T micro_os_plus::micro_test_plus::detail::math::abs (const T t)
nodiscard constexpr noexcept

Computes the absolute value of a given comparable value.

This function template provides a generic, constexpr implementation for obtaining the absolute value of any type that supports comparison and unary negation.

The function returns the non-negative value of the input. If the input is less than the default-constructed value of its type (typically zero), the negated value is returned; otherwise, the original value is returned.

Template Parameters
T

The type of the input value. Must support comparison and unary negation.

Parameters
t

The value for which the absolute value is to be computed.

Returns

The absolute value of the input.

Definition at line 88 of file math-inlines.h.

88 abs (const T t) noexcept -> T
89 {
90 return t < T{} ? -t : t;
91 }

Reference micro_os_plus::micro_test_plus::detail::math::abs.

Referenced by micro_os_plus::micro_test_plus::detail::math::abs, micro_os_plus::micro_test_plus::detail::math::count_decimals, micro_os_plus::micro_test_plus::detail::differ_by_at_most and micro_os_plus::micro_test_plus::detail::within_tolerance.

min_value()​

template <class T>
const T & micro_os_plus::micro_test_plus::detail::math::min_value (const T & lhs, const T & rhs)
nodiscard constexpr noexcept

Computes the minimum of two comparable values.

This function template provides a generic, constexpr implementation for determining the minimum of two values of any type that supports comparison.

The function returns a reference to the lesser of the two input values, as determined by the < operator. If the second argument is less than the first, it is returned; otherwise, the first argument is returned.

Template Parameters
T

The type of the input values. Must support comparison via the < operator.

Parameters
lhs

The first value to compare.

rhs

The second value to compare.

Returns

A reference to the minimum of the two input values.

Definition at line 106 of file math-inlines.h.

106 min_value (const T& lhs, const T& rhs) noexcept -> const T&
107 {
108 return (rhs < lhs) ? rhs : lhs;
109 }

Reference micro_os_plus::micro_test_plus::detail::math::min_value.

Referenced by micro_os_plus::micro_test_plus::detail::math::count_decimals, micro_os_plus::micro_test_plus::detail::math::min_value and micro_os_plus::micro_test_plus::detail::within_tolerance.

File Listing​

The file content with the documentation metadata removed is:

1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can be
9 * obtained from https://opensource.org/licenses/mit.
10 *
11 * Major parts of the code are inspired from v1.1.8 of the Boost UT project,
12 * released under the terms of the Boost Version 1.0 Software License,
13 * which can be obtained from https://www.boost.org/LICENSE_1_0.txt.
14 */
15
16// ----------------------------------------------------------------------------
17
42
43#ifndef MICRO_OS_PLUS_MICRO_TEST_PLUS_MATH_H_
44#define MICRO_OS_PLUS_MICRO_TEST_PLUS_MATH_H_
45
46// ----------------------------------------------------------------------------
47
48#if defined(__cplusplus)
49
50// ----------------------------------------------------------------------------
51
52#if __has_include("micro-os-plus/project-config.h")
53#include "micro-os-plus/project-config.h"
54#endif // __has_include("micro-os-plus/project-config.h")
55
56#if __has_include("micro-os-plus/micro-test-plus-defines.h")
57#include "micro-os-plus/micro-test-plus-defines.h"
58#endif // __has_include("micro-os-plus/micro-test-plus-defines.h")
59
60#include <array>
61#include <limits>
62
63// ----------------------------------------------------------------------------
64
65#if defined(__GNUC__)
66#pragma GCC diagnostic push
67
68#pragma GCC diagnostic ignored "-Wconversion"
69#pragma GCC diagnostic ignored "-Wpadded"
70#if defined(__clang__)
71#pragma clang diagnostic ignored "-Wc++98-compat"
72#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
73#pragma clang diagnostic ignored "-Wc++20-compat"
74#endif // defined(__clang__)
75#endif // defined(__GNUC__)
76
77// ============================================================================
78
80{
81 // --------------------------------------------------------------------------
82
104 namespace detail::math
105 {
115 template <class T>
116 [[nodiscard]] constexpr auto
117 abs (const T t) noexcept -> T;
118
119#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
130 template <class T>
131 [[nodiscard]] constexpr auto
132 min_value (const T& lhs, const T& rhs) noexcept -> const T&;
133#endif // defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
134
135 // ------------------------------------------------------------------------
136 } // namespace detail::math
137
138 // --------------------------------------------------------------------------
139} // namespace micro_os_plus::micro_test_plus
140
141#if defined(__GNUC__)
142#pragma GCC diagnostic pop
143#endif // defined(__GNUC__)
144
145// ----------------------------------------------------------------------------
146
147#endif // defined(__cplusplus)
148
149// ============================================================================
150// Templates, inlines & constexpr implementations.
151
153
154// ----------------------------------------------------------------------------
155
156#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_MATH_H_
157
158// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.