Prusa-MMU-Private
PrusaMultiMaterialUpgradev3firmwareforMK3SMK4
cmath.h
Go to the documentation of this file.
1 // Provide an uniform interface for basic math functions between AVR libc and newer
3 // standards that support <cmath>
4 #pragma once
5 
6 #ifndef __AVR__
7 #include <cmath> // abs
8 
9 #include <algorithm>
10 using std::max;
11 using std::min;
12 #else
13 
14 // AVR libc doesn't support cmath
15 #include <math.h>
16 
17 template <typename T>
18 static inline const T min(const T a, const T b) {
19  return a <= b ? a : b;
20 }
21 
22 template <typename T>
23 static inline const T max(const T a, const T b) {
24  return a > b ? a : b;
25 }
26 
27 template <typename T>
28 static inline const T abs(const T n) {
29  return n < 0 ? -n : n;
30 }
31 
32 static inline const int16_t abs(const int16_t n) {
33  // Use builtin function only when possible
34  return __builtin_abs((n));
35 }
36 
37 #endif