Use operators for min/max

Turns out AVR doesn't have __builtin_min/max
pull/108/head
Yuri D'Elia 2021-08-28 18:09:22 +02:00 committed by DRracer
parent 1f2662518b
commit b55c13dec2
1 changed files with 3 additions and 3 deletions

View File

@ -9,19 +9,19 @@
// AVR libc doesn't support cmath // AVR libc doesn't support cmath
#include <math.h> #include <math.h>
// Use builtin functions for min/max/abs
template <typename T> template <typename T>
static inline const T min(T a, T b) { static inline const T min(T a, T b) {
return __builtin_min((a, b)); return a <= b ? a : b;
} }
template <typename T> template <typename T>
static inline const T max(T a, T b) { static inline const T max(T a, T b) {
return __builtin_max((a, b)); return a > b ? a : b;
} }
template <typename T> template <typename T>
static inline const T abs(T n) { static inline const T abs(T n) {
// Use builtin function when available
return __builtin_abs((n)); return __builtin_abs((n));
} }