跳轉到主要內容

Q10

touchgfx/widgets/canvas/CWRUtil.hpp

Defines a "floating point number" with 10 bits reserved for the fractional part of the decimal number. Q10 implements some simple arithmetic operations, most yielding a Q10 number and some yielding a Q5 number or a Q15 number as a result.

Q5*Q5=Q10, Q10/Q5=Q5, ...

See: Q5, Q15

Public Functions

operator int() const
Gets the Q10 as an integer without conversion.
Q15operator*(const Q5 & q5) const
Multiplication operator.
Q10operator+(const Q10 & q10) const
Addition operator.
Q10operator-() const
Negation operator.
Q5operator/(const Q5 & q5) const
Division operator.
Q10()
Initializes a new instance of the Q10 class.
Q10(int i)
Constructor from integer.
template <typename T >
T
to() const
Converts the Q10 value to an int or a float.

Public Functions Documentation

operator int

Gets the Q10 as an integer without conversion.

Returns:

The unconverted Q10 value.

operator*

Q15 operator*(const Q5 &q5)

Multiplication operator.

The result is a Q15, not a Q10, for increased precision.

Parameters:
q5The Q5 to multiply this with.
Returns:

The result of the operation.

operator+

Q10 operator+(const Q10 &q10)

Addition operator.

Parameters:
q10The Q10 to add to this.
Returns:

The result of the operation.

operator-

Q10 operator-()const

Negation operator.

Returns:

The negative value of this.

operator/

Q5 operator/(const Q5 &q5)

Division operator.

Parameters:
q5The Q5 to divide this by.
Returns:

The result of the operation.

Q10

Q10()

Initializes a new instance of the Q10 class.

Q10

explicit Q10(inti)

Constructor from integer.

No conversion is done - the integer is assumed to already be in Q10 format.

Parameters:
iint pre-formattet in Q10 format.

to

T to()const

Converts the Q10 value to an int or a float.

Convert the Q10 value to an integer by removing the 10 bits used for the fraction, or to a floating point value by dividing by 32 * 32, depending on the type specified as T.

Template Parameters:
TEither int or float.
Returns:

Q10 value as a type T.