1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

OP-1309 more performant implementation of boundf()

This commit is contained in:
Corvus Corax 2014-04-29 19:55:34 +02:00
parent 2f572995ac
commit 66f2f8e840

View File

@ -37,15 +37,17 @@
static inline float boundf(float val, float boundary1, float boundary2)
{
if (boundary1 > boundary2) {
float tmp = boundary2;
boundary2 = boundary1;
boundary1 = tmp;
}
if (!(val >= boundary1)) {
val = boundary1;
}
if (!(val <= boundary2)) {
val = boundary2;
if (!(val >= boundary2)) {
return boundary2;
} else if (!(val <= boundary1)) {
return boundary1;
}
} else {
if (!(val >= boundary1)) {
return boundary1;
} else if (!(val <= boundary2)) {
return boundary2;
}
}
return val;
}