My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

minmax.h 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #undef MIN
  23. #undef MAX
  24. // Pass NUM_ARGS(__VA_ARGS__) to use the number of arguments
  25. #define _NUM_ARGS(_0,_24_,_23,_22,_21,_20,_19,_18,_17,_16,_15,_14,_13,_12,_11,_10,_9,_8,_7,_6,_5,_4,_3,_2,_1,N,...) N
  26. #define NUM_ARGS(...) _NUM_ARGS(0, __VA_ARGS__ ,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
  27. #ifdef __cplusplus
  28. #ifndef _MINMAX_H_
  29. #define _MINMAX_H_
  30. extern "C++" {
  31. // C++11 solution that is standards compliant. Return type is deduced automatically
  32. template <class L, class R> static inline constexpr auto MIN(const L lhs, const R rhs) -> decltype(lhs + rhs) {
  33. return lhs < rhs ? lhs : rhs;
  34. }
  35. template <class L, class R> static inline constexpr auto MAX(const L lhs, const R rhs) -> decltype(lhs + rhs) {
  36. return lhs > rhs ? lhs : rhs;
  37. }
  38. template<class T, class ... Ts> static inline constexpr const T MIN(T V, Ts... Vs) { return MIN(V, MIN(Vs...)); }
  39. template<class T, class ... Ts> static inline constexpr const T MAX(T V, Ts... Vs) { return MAX(V, MAX(Vs...)); }
  40. }
  41. #endif
  42. #else
  43. #define MIN_2(a,b) ((a)<(b)?(a):(b))
  44. #define MIN_3(a,...) MIN_2(a,MIN_2(__VA_ARGS__))
  45. #define MIN_4(a,...) MIN_2(a,MIN_3(__VA_ARGS__))
  46. #define MIN_5(a,...) MIN_2(a,MIN_4(__VA_ARGS__))
  47. #define MIN_6(a,...) MIN_2(a,MIN_5(__VA_ARGS__))
  48. #define MIN_7(a,...) MIN_2(a,MIN_6(__VA_ARGS__))
  49. #define MIN_8(a,...) MIN_2(a,MIN_7(__VA_ARGS__))
  50. #define MIN_9(a,...) MIN_2(a,MIN_8(__VA_ARGS__))
  51. #define MIN_10(a,...) MIN_2(a,MIN_9(__VA_ARGS__))
  52. #define __MIN_N(N, ...) MIN_##N(__VA_ARGS__)
  53. #define _MIN_N(N, ...) __MIN_N(N,__VA_ARGS__)
  54. #define MIN(...) _MIN_N(NUM_ARGS(__VA_ARGS__), __VA_ARGS__)
  55. #define MAX_2(a,b) ((a)>(b)?(a):(b))
  56. #define MAX_3(a,...) MAX_2(a,MAX_2(__VA_ARGS__))
  57. #define MAX_4(a,...) MAX_2(a,MAX_3(__VA_ARGS__))
  58. #define MAX_5(a,...) MAX_2(a,MAX_4(__VA_ARGS__))
  59. #define MAX_6(a,...) MAX_2(a,MAX_5(__VA_ARGS__))
  60. #define MAX_7(a,...) MAX_2(a,MAX_6(__VA_ARGS__))
  61. #define MAX_8(a,...) MAX_2(a,MAX_7(__VA_ARGS__))
  62. #define MAX_9(a,...) MAX_2(a,MAX_8(__VA_ARGS__))
  63. #define MAX_10(a,...) MAX_2(a,MAX_9(__VA_ARGS__))
  64. #define __MAX_N(N, ...) MAX_##N(__VA_ARGS__)
  65. #define _MAX_N(N, ...) __MAX_N(N,__VA_ARGS__)
  66. #define MAX(...) _MAX_N(NUM_ARGS(__VA_ARGS__), __VA_ARGS__)
  67. #endif