Q5
touchgfx/widgets/canvas/CWRUtil.hpp
Defines a "floating point number" with 5 bits reserved for the fractional part of the decimal number. Q5 implements some simple arithmetic operations, most yielding a Q5 number and some yielding a Q10 number as a result. Other operations also work with Q15 numbers.
Public Functions
| int | ceil() const | 
| Convert the Q5 value to an integer by removing the 5 bits used for the fraction. | |
| int | floor() const | 
| Convert the Q5 value to an integer by removing the 5 bits used for the fraction. | |
| operator int() const | |
| Gets the Q5 as an integer without conversion. | |
| Q5 | operator%(const Q5 q5) const | 
| Modulus operator. | |
| Q5 & | operator%=(const Q5 q5) | 
| Modulus operator. | |
| Q5 | operator*(const int i) const | 
| Multiplication operator. | |
| Q5 | operator*(const Q15 & q15) const | 
| Multiplication operator. | |
| Q10 | operator*(const Q5 & q5) const | 
| Multiplication operator. | |
| Q5 | operator+(const Q5 & q5) const | 
| Addition operator. | |
| Q5 & | operator+=(const Q5 & q5) | 
| Addition operator. | |
| Q5 | operator-() const | 
| Negation operator. | |
| Q5 | operator-(const Q5 & q5) const | 
| Subtraction operator. | |
| Q5 & | operator-=(const Q5 & q5) | 
| Subtraction operator. | |
| Q5 | operator/(const int i) const | 
| Division operator. | |
| Q5 | operator/(const Q5 q5) const | 
| Division operator. | |
| Q5() | |
| Initializes a new instance of the Q5 class. | |
| Q5(const Q10 q10) | |
| Constructor from Q10. | |
| Q5(int i) | |
| Constructor from integer. | |
| int | round() const | 
| Round the Q5 value to the nearest integer value. | |
| template <typename T > T | to() const | 
| Convert the Q5 value to an integer by removing the 5 bits used for the fraction, or to a floating point value by dividing by 32, depending on the type specified as T. | |
Public Functions Documentation
ceil
| int ceil | ( | ) | const | 
floor
| int floor | ( | ) | const | 
operator int
| operator int | ( | ) | const | 
operator%
operator%=
| Q5 & operator%= | ( | const Q5 | q5 | ) | |
operator*
| Q5 operator* | ( | const int | i | ) | |
Multiplication operator.
| i | The integer to multiply this with. | 
The result of the operation.
operator*
Multiplication operator.
Often used in relation with sine and cosine calculation which are pre-calculated as Q15. As the result is needed as a Q5, this operator multiplies with the given Q15 and converts the result to a Q5.
| q15 | The Q15 to multiply this with. | 
The result of the operation.
operator*
operator+
operator+=
| Q5 & operator+= | ( | const Q5 & | q5 | ) | |
operator-
| Q5 operator- | ( | ) | const | 
Negation operator.
The negative value of this.
operator-
Subtraction operator.
| q5 | The Q5 to subtract from this. | 
The result of the operation.
operator-=
| Q5 & operator-= | ( | const Q5 & | q5 | ) | |
Subtraction operator.
| q5 | The Q5 to subtract from this. | 
The result of the operation.
operator/
| Q5 operator/ | ( | const int | i | ) | |
Division operator.
| i | The integer to divide this by. | 
The result of the operation.
operator/
Q5
Q5
Q5
| explicit Q5 | ( | int | i | ) | |
round
| int round | ( | ) | const | 
to
| T to | ( | ) | const | 
Convert the Q5 value to an integer by removing the 5 bits used for the fraction, or to a floating point value by dividing by 32, depending on the type specified as T.
| T | Either int or float. | 
Q5 value as a type T.
Note
Using "to<int16_t>()" result in loss of precision. Use "(int16_t)to<int>()" instead.