Sound Byte Libs
0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
magnitude.hpp
Go to the documentation of this file.
1
/**
2
* @file magnitude.hpp
3
* @brief A float's magnitude as its bit pattern, for compares without the FPU
4
* @ingroup math
5
*
6
* With the sign bit cleared, an IEEE 754 single's bits order as its magnitude
7
* does, and an infinity or a NaN reads above every finite value. A compare of
8
* two such words is an integer compare, with no FPU compare.
9
*/
10
11
#ifndef SBL_MATH_MAGNITUDE_HPP_
12
#define SBL_MATH_MAGNITUDE_HPP_
13
14
#include <cstdint>
15
#include <cstring>
16
17
namespace
sbl::math
{
18
19
/**
20
* @brief x's bits with the sign cleared.
21
*
22
* For finite a and b, magnitude_bits(a) < magnitude_bits(b) exactly when
23
* |a| < |b|; a non-finite value reads above every finite one, and both zeros
24
* read 0.
25
*
26
* @param x Any float, NaN and infinities included
27
* @return The IEEE 754 bit pattern of x with bit 31 cleared
28
*/
29
inline
uint32_t
magnitude_bits
(
float
x) {
30
uint32_t bits;
31
std::memcpy(&bits, &x,
sizeof
(bits));
32
return
bits & 0x7FFFFFFFu;
33
}
34
35
}
// namespace sbl::math
36
37
#endif
// SBL_MATH_MAGNITUDE_HPP_
sbl::math
Domain-neutral math: constants, clamp, interpolation.
Definition
clamp.hpp:13
sbl::math::magnitude_bits
uint32_t magnitude_bits(float x)
x's bits with the sign cleared.
Definition
magnitude.hpp:29
src
sbl
math
magnitude.hpp
Generated by
1.9.8