FastLED 3.9.15
Loading...
Searching...
No Matches
qfx.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/stdint.h"
4#include "fl/stl/noexcept.h"
5namespace fl {
8
13template<class T, int F, int I> class qfx {
14 T i:I;
15 T f:F;
16public:
18 qfx(float fx) FL_NOEXCEPT { i = fx; f = (fx-i) * (1<<F); }
20 qfx(u8 _i, u8 _f) FL_NOEXCEPT {i=_i; f=_f; }
21
23 u32 operator*(u32 v) FL_NOEXCEPT { return (v*i) + ((v*f)>>F); }
25 u16 operator*(u16 v) FL_NOEXCEPT { return (v*i) + ((v*f)>>F); }
27 i32 operator*(i32 v) FL_NOEXCEPT { return (v*i) + ((v*f)>>F); }
29 i16 operator*(i16 v) FL_NOEXCEPT { return (v*i) + ((v*f)>>F); }
30#if (defined(FL_IS_ARM) || defined(FASTLED_RISCV) || defined(FASTLED_APOLLO3)) && !defined(ARDUINO_ARCH_ZEPHYR)
32 int operator*(int v) { return (v*i) + ((v*f)>>F); }
33#endif
34};
35
36template<class T, int F, int I> static u32 operator*(u32 v, qfx<T,F,I> & q) FL_NOEXCEPT { return q * v; }
37template<class T, int F, int I> static u16 operator*(u16 v, qfx<T,F,I> & q) FL_NOEXCEPT { return q * v; }
38template<class T, int F, int I> static i32 operator*(i32 v, qfx<T,F,I> & q) FL_NOEXCEPT { return q * v; }
39template<class T, int F, int I> static i16 operator*(i16 v, qfx<T,F,I> & q) FL_NOEXCEPT { return q * v; }
40#if (defined(FL_IS_ARM) || defined(FASTLED_RISCV) || defined(FASTLED_APOLLO3)) && !defined(ARDUINO_ARCH_ZEPHYR)
41template<class T, int F, int I> static int operator*(int v, qfx<T,F,I> & q) { return q * v; }
42#endif
43
52
54} // namespace fl
55
56// Fractional types are in namespace fl:: (q44, q62, q88, q124)
i16 operator*(i16 v) FL_NOEXCEPT
Definition qfx.h:29
u16 operator*(u16 v) FL_NOEXCEPT
Definition qfx.h:25
u32 operator*(u32 v) FL_NOEXCEPT
Multiply the fractional int by a value.
Definition qfx.h:23
qfx(float fx) FL_NOEXCEPT
Constructor, storing a float as a fractional int.
Definition qfx.h:18
i32 operator*(i32 v) FL_NOEXCEPT
Definition qfx.h:27
qfx(u8 _i, u8 _f) FL_NOEXCEPT
Constructor, storing a fractional int directly.
Definition qfx.h:20
Template class for representing fractional ints.
Definition qfx.h:13
qfx< u16, 12, 4 > q124
A 12.4 integer (12 bits integer, 4 bits fraction)
Definition qfx.h:51
qfx< u16, 8, 8 > q88
A 8.8 integer (8 bits integer, 8 bits fraction)
Definition qfx.h:49
qfx< u8, 4, 4 > q44
A 4.4 integer (4 bits integer, 4 bits fraction)
Definition qfx.h:45
qfx< u8, 6, 2 > q62
A 6.2 integer (6 bits integer, 2 bits fraction)
Definition qfx.h:47
unsigned char u8
Definition stdint.h:131
FASTLED_FORCE_INLINE CRGB operator*(const CRGB &p1, u8 d) FL_NOEXCEPT
Multiply each of the channels by a constant, saturating each channel at 0xFF.
Definition crgb.hpp:198
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT