GCC Code Coverage Report


Directory: include/tts/
File: include/tts/engine/math.hpp
Date: 2026-10-14 16:28:14
Exec Total Coverage
Lines: 32 32 100.0%
Functions: 32 40 80.0%
Branches: 15 16 93.8%

Line Branch Exec Source
1 //======================================================================================================================
2 /*
3 TTS - Tiny Test System
4 Copyright : TTS Contributors & Maintainers
5 SPDX-License-Identifier: BSL-1.0
6 */
7 //======================================================================================================================
8 #pragma once
9 #include <tts/tools/bitcast.hpp>
10
11 namespace tts::_
12 {
13 #if defined(__FAST_MATH__)
14 constexpr auto is_nan(auto)
15 {
16 return false;
17 }
18 constexpr auto is_inf(auto)
19 {
20 return false;
21 }
22 constexpr auto is_unordered(auto, auto)
23 {
24 return false;
25 }
26 #else
27 8623788 constexpr auto is_nan(auto x)
28 {
29 8623788 return x != x;
30 }
31 4299130 constexpr auto is_inf(auto x)
32 {
33
4/4
✓ Branch 1 taken 2149562 times.
✓ Branch 2 taken 10 times.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 2149546 times.
4299130 return !is_nan(x) && is_nan(x - x);
34 }
35 4152 constexpr auto is_unordered(auto x, auto y)
36 {
37
4/4
✓ Branch 1 taken 4133 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 4130 times.
4152 return is_nan(x) || is_nan(y);
38 }
39 #endif
40
41 26272 constexpr auto min(auto x, auto y)
42 {
43
2/2
✓ Branch 0 taken 8283 times.
✓ Branch 1 taken 4858 times.
26272 return x < y ? x : y;
44 }
45 901184 constexpr auto max(auto x, auto y)
46 {
47
2/2
✓ Branch 0 taken 294 times.
✓ Branch 1 taken 452348 times.
901184 return x < y ? y : x;
48 }
49 1744877 constexpr auto abs(auto x)
50 {
51
2/2
✓ Branch 0 taken 436170 times.
✓ Branch 1 taken 436274 times.
1744877 return x < 0 ? -x : x;
52 }
53 8290 constexpr bool signbit(auto x)
54 {
55 8290 return (as_int(x) >> (sizeof(x) * 8 - 1)) != 0;
56 }
57
58 //====================================================================================================================
59 // Math wrappers
60 //====================================================================================================================
61 #if !defined(TTS_USE_STDMATH)
62 // POW
63 316012 inline double pow(double x, double y)
64 {
65 316012 return __builtin_pow(x, y);
66 }
67 320117 inline float pow(float x, float y)
68 {
69 320117 return __builtin_powf(x, y);
70 }
71 inline long double pow(long double x, long double y)
72 {
73 return __builtin_powl(x, y);
74 }
75
76 // SQRT
77 216012 inline double sqrt(double x)
78 {
79 216012 return __builtin_sqrt(x);
80 }
81 220117 inline float sqrt(float x)
82 {
83 220117 return __builtin_sqrtf(x);
84 }
85 inline long double sqrt(long double x)
86 {
87 return __builtin_sqrtl(x);
88 }
89
90 // LOG10
91 632024 inline double log10(double x)
92 {
93 632024 return __builtin_log10(x);
94 }
95 640234 inline float log10(float x)
96 {
97 640234 return __builtin_log10f(x);
98 }
99 inline long double log10(long double x)
100 {
101 return __builtin_log10l(x);
102 }
103
104 // CEIL
105 16384 inline double ceil(double x)
106 {
107 16384 return __builtin_ceil(x);
108 }
109 inline float ceil(float x)
110 {
111 return __builtin_ceilf(x);
112 }
113 inline long double ceil(long double x)
114 {
115 return __builtin_ceill(x);
116 }
117
118 // LOG2 (Floating point)
119 inline double log2(double x)
120 {
121 return __builtin_log2(x);
122 }
123 inline float log2(float x)
124 {
125 return __builtin_log2f(x);
126 }
127 inline long double log2(long double x)
128 {
129 return __builtin_log2l(x);
130 }
131 #else
132 inline double pow(double x, double y)
133 {
134 return ::pow(x, y);
135 }
136 inline float pow(float x, float y)
137 {
138 return ::powf(x, y);
139 }
140 inline long double pow(long double x, long double y)
141 {
142 return ::powl(x, y);
143 }
144
145 inline double sqrt(double x)
146 {
147 return ::sqrt(x);
148 }
149 inline float sqrt(float x)
150 {
151 return ::sqrtf(x);
152 }
153 inline long double sqrt(long double x)
154 {
155 return ::sqrtl(x);
156 }
157
158 inline double log10(double x)
159 {
160 return ::log10(x);
161 }
162 inline float log10(float x)
163 {
164 return ::log10f(x);
165 }
166 inline long double log10(long double x)
167 {
168 return ::log10l(x);
169 }
170
171 inline double ceil(double x)
172 {
173 return ::ceil(x);
174 }
175 inline float ceil(float x)
176 {
177 return ::ceilf(x);
178 }
179 inline long double ceil(long double x)
180 {
181 return ::ceill(x);
182 }
183
184 inline double log2(double x)
185 {
186 return ::log2(x);
187 }
188 inline float log2(float x)
189 {
190 return ::log2f(x);
191 }
192 inline long double log2(long double x)
193 {
194 return ::log2l(x);
195 }
196 #endif
197
198 4844 constexpr std::size_t log2(std::size_t n)
199 {
200
1/2
✓ Branch 0 taken 4844 times.
✗ Branch 1 not taken.
4844 return n ? static_cast<std::size_t>(std::bit_width(n) - 1) : std::size_t {0};
201 }
202 1268162 template<typename T> T exp10(T a)
203 {
204 1268162 return tts::_::pow(T(10), a);
205 }
206 }
207