mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-19 06:15:16 +03:00
Simplify Fixed point Math notations
This commit is contained in:
parent
431ca856cf
commit
257865cff2
5 changed files with 25 additions and 38 deletions
|
@ -338,15 +338,14 @@ void arraySubInt32(int32_t *dest, int32_t *array1, int32_t *array2, int count)
|
|||
}
|
||||
}
|
||||
|
||||
int16_t qPercent(q_number_t q) {
|
||||
return 100 * q.num / q.den;
|
||||
int16_t qPercent(fix12_t q) {
|
||||
return (100 * q) >> 12;
|
||||
}
|
||||
|
||||
int16_t qMultiply(q_number_t q, int16_t input) {
|
||||
return input * q.num / q.den;
|
||||
int16_t qMultiply(fix12_t q, int16_t input) {
|
||||
return (input * q) >> 12;
|
||||
}
|
||||
|
||||
void qConstruct(q_number_t *qNumber, int16_t num, int16_t den, int qType) {
|
||||
qNumber->num = (1 << qType) / den;
|
||||
qNumber->den = (1 << qType) / num;
|
||||
fix12_t qConstruct(int16_t num, int16_t den) {
|
||||
return (num << 12) / den;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue