GCC Code Coverage Report


Directory: ./
File: overlays/wled/lib8tion/qfx.h
Date: 2026-10-29 08:11:58
Exec Total Coverage
Lines: 0 8 0.0%
Functions: 0 12 0.0%
Branches: 0 0 -%

Line Branch Exec Source
1 #pragma once
2
3 #include <stdint.h>
4 #include "../fl/namespace.h"
5
6 FASTLED_NAMESPACE_BEGIN
7
8
9 /// @addtogroup FractionalTypes
10 /// @{
11
12 /// Template class for representing fractional ints.
13 /// @tparam T underlying type for data storage
14 /// @tparam F number of fractional bits
15 /// @tparam I number of integer bits
16 template<class T, int F, int I> class qfx {
17 T i:I; ///< Integer value of number
18 T f:F; ///< Fractional value of number
19 public:
20 /// Constructor, storing a float as a fractional int
21 qfx(float fx) { i = fx; f = (fx-i) * (1<<F); }
22 /// Constructor, storing a fractional int directly
23 ✗ qfx(uint8_t _i, uint8_t _f) {i=_i; f=_f; }
24
25 /// Multiply the fractional int by a value
26 ✗ uint32_t operator*(uint32_t v) { return (v*i) + ((v*f)>>F); }
27 /// @copydoc operator*(uint32_t)
28 ✗ uint16_t operator*(uint16_t v) { return (v*i) + ((v*f)>>F); }
29 /// @copydoc operator*(uint32_t)
30 ✗ int32_t operator*(int32_t v) { return (v*i) + ((v*f)>>F); }
31 /// @copydoc operator*(uint32_t)
32 ✗ int16_t operator*(int16_t v) { return (v*i) + ((v*f)>>F); }
33 #if defined(FASTLED_ARM) | defined(FASTLED_RISCV) | defined(FASTLED_APOLLO3)
34 /// @copydoc operator*(uint32_t)
35 int operator*(int v) { return (v*i) + ((v*f)>>F); }
36 #endif
37 };
38
39 ✗ template<class T, int F, int I> static uint32_t operator*(uint32_t v, qfx<T,F,I> & q) { return q * v; }
40 ✗ template<class T, int F, int I> static uint16_t operator*(uint16_t v, qfx<T,F,I> & q) { return q * v; }
41 ✗ template<class T, int F, int I> static int32_t operator*(int32_t v, qfx<T,F,I> & q) { return q * v; }
42 template<class T, int F, int I> static int16_t operator*(int16_t v, qfx<T,F,I> & q) { return q * v; }
43 #if defined(FASTLED_ARM) | defined(FASTLED_RISCV) | defined(FASTLED_APOLLO3)
44 template<class T, int F, int I> static int operator*(int v, qfx<T,F,I> & q) { return q * v; }
45 #endif
46
47 /// A 4.4 integer (4 bits integer, 4 bits fraction)
48 typedef qfx<uint8_t, 4,4> q44;
49 /// A 6.2 integer (6 bits integer, 2 bits fraction)
50 typedef qfx<uint8_t, 6,2> q62;
51 /// A 8.8 integer (8 bits integer, 8 bits fraction)
52 typedef qfx<uint16_t, 8,8> q88;
53 /// A 12.4 integer (12 bits integer, 4 bits fraction)
54 typedef qfx<uint16_t, 12,4> q124;
55
56 /// @} FractionalTypes
57
58 FASTLED_NAMESPACE_END
59