Skip to main content

math-inlines.h File

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

Included Headers​

#include <cstdint>

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 inline implementations for the µTest++ mathematical utilities.

This header provides the inline implementations for the mathematical utility templates used within the µTest++ framework. It defines the constexpr 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 are in deprecated-inlines.h.

These utilities 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 literals and of the comparisons, not part of the public API.

This file is included by math.h; the applications include micro-os-plus/micro-test-plus.h, not this file.

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
41
42#ifndef MICRO_OS_PLUS_MICRO_TEST_PLUS_INLINES_MATH_INLINES_H_
43#define MICRO_OS_PLUS_MICRO_TEST_PLUS_INLINES_MATH_INLINES_H_
44
45// ----------------------------------------------------------------------------
46
47#if defined(__cplusplus)
48
49// ----------------------------------------------------------------------------
50
51#include <cstdint>
52
53// ----------------------------------------------------------------------------
54
55#if defined(__GNUC__)
56#pragma GCC diagnostic push
57
58#pragma GCC diagnostic ignored "-Waggregate-return"
59#if defined(__clang__)
60#pragma clang diagnostic ignored "-Wc++98-compat"
61#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
62#pragma clang diagnostic ignored "-Wc++20-compat"
63#endif // defined(__clang__)
64#endif // defined(__GNUC__)
65
66// ============================================================================
67
69{
70 // --------------------------------------------------------------------------
71
72 namespace detail::math
73 {
74
86 template <class T>
87 constexpr auto
88 abs (const T t) noexcept -> T
89 {
90 return t < T{} ? -t : t;
91 }
92
93#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
104 template <class T>
105 constexpr auto
106 min_value (const T& lhs, const T& rhs) noexcept -> const T&
107 {
108 return (rhs < lhs) ? rhs : lhs;
109 }
110#endif // defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
111
112 } // namespace detail::math
113
114 // --------------------------------------------------------------------------
115} // namespace micro_os_plus::micro_test_plus
116
117#if defined(__GNUC__)
118#pragma GCC diagnostic pop
119#endif // defined(__GNUC__)
120
121// ----------------------------------------------------------------------------
122
123#endif // defined(__cplusplus)
124
125// ----------------------------------------------------------------------------
126
127#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_INLINES_MATH_INLINES_H_
128
129// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.