Skip to content

Commit

Permalink
AP_Math: Add missing constexpr
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric authored and tridge committed Mar 16, 2020
1 parent c9f2b9f commit 1635054
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion libraries/AP_Math/AP_Math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ float linear_interpolate(float low_output, float high_output,
* alpha range: [0,1] min to max expo
* input range: [-1,1]
*/
float expo_curve(float alpha, float x)
constexpr float expo_curve(float alpha, float x)
{
return (1.0f - alpha) * x + alpha * x * x * x;
}
Expand Down
14 changes: 7 additions & 7 deletions libraries/AP_Math/AP_Math.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,32 +215,32 @@ static inline auto MAX(const A &one, const B &two) -> decltype(one > two ? one :
return one > two ? one : two;
}

inline uint32_t hz_to_nsec(uint32_t freq)
inline constexpr uint32_t hz_to_nsec(uint32_t freq)
{
return AP_NSEC_PER_SEC / freq;
}

inline uint32_t nsec_to_hz(uint32_t nsec)
inline constexpr uint32_t nsec_to_hz(uint32_t nsec)
{
return AP_NSEC_PER_SEC / nsec;
}

inline uint32_t usec_to_nsec(uint32_t usec)
inline constexpr uint32_t usec_to_nsec(uint32_t usec)
{
return usec * AP_NSEC_PER_USEC;
}

inline uint32_t nsec_to_usec(uint32_t nsec)
inline constexpr uint32_t nsec_to_usec(uint32_t nsec)
{
return nsec / AP_NSEC_PER_USEC;
}

inline uint32_t hz_to_usec(uint32_t freq)
inline constexpr uint32_t hz_to_usec(uint32_t freq)
{
return AP_USEC_PER_SEC / freq;
}

inline uint32_t usec_to_hz(uint32_t usec)
inline constexpr uint32_t usec_to_hz(uint32_t usec)
{
return AP_USEC_PER_SEC / usec;
}
Expand All @@ -256,7 +256,7 @@ float linear_interpolate(float low_output, float high_output,
* alpha range: [0,1] min to max expo
* input range: [-1,1]
*/
float expo_curve(float alpha, float input);
constexpr float expo_curve(float alpha, float input);

/* throttle curve generator
* thr_mid: output at mid stick
Expand Down

0 comments on commit 1635054

Please sign in to comment.