mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-26 09:43:57 -04:00
AP_Math: use /2 in place of *0.5f
MdB says: dividing by 2 is actually optimal. It's type correct for all usage, and the compiler generates the multiplication if it's float, and sticks with divide for integers Godbolt indicates on any optimization level (O1-O3, and Os) that the compiler will correctly optimize the / 2 into a float multiplication if using a float, but if using integer types in the template it will stick with the / 2 which is faster then doing the conversions to/from float.
This commit is contained in:
parent
31daaf9933
commit
ce53ae63ae
@ -48,7 +48,7 @@ void MatrixN<T,N>::force_symmetry(void)
|
|||||||
{
|
{
|
||||||
for (uint8_t i = 0; i < N; i++) {
|
for (uint8_t i = 0; i < N; i++) {
|
||||||
for (uint8_t j = 0; j < (i - 1); j++) {
|
for (uint8_t j = 0; j < (i - 1); j++) {
|
||||||
v[i][j] = (v[i][j] + v[j][i]) * 0.5f;
|
v[i][j] = (v[i][j] + v[j][i]) / 2;
|
||||||
v[j][i] = v[i][j];
|
v[j][i] = v[i][j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user