From 99ecdf59af907ebb8d2d847863614094bb576e3f Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 13 May 2018 01:10:34 -0500 Subject: [PATCH] Smarter MIN, MAX, ABS macros Use macros that explicitly avoid double-evaluation and can be used for any datatype, replacing `min`, `max`, `abs`, `fabs`, `labs`, and `FABS`. Co-Authored-By: ejtagle --- Marlin/src/HAL/HAL_DUE/usb/compiler.h | 73 ------------------- .../src/HAL/HAL_DUE/usb/uotghs_device_due.c | 2 +- .../src/HAL/HAL_DUE/usb/uotghs_device_due.h | 2 +- Marlin/src/HAL/HAL_LPC1768/SoftwareSPI.cpp | 2 +- Marlin/src/HAL/HAL_LPC1768/include/Arduino.h | 7 +- .../HAL/HAL_STM32F1/HAL_timers_Stm32f1.cpp | 4 +- .../src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h | 2 +- Marlin/src/HAL/HAL_STM32F7/TMC2660.cpp | 4 +- Marlin/src/HAL/servo.cpp | 2 +- Marlin/src/core/macros.h | 51 +++++++++++-- Marlin/src/feature/I2CPositionEncoder.cpp | 20 ++--- Marlin/src/feature/Max7219_Debug_LEDs.cpp | 4 +- Marlin/src/feature/bedlevel/abl/abl.cpp | 8 +- .../bedlevel/mbl/mesh_bed_leveling.cpp | 2 +- Marlin/src/feature/bedlevel/ubl/ubl.h | 10 +-- Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp | 16 ++-- .../src/feature/bedlevel/ubl/ubl_motion.cpp | 6 +- .../src/feature/digipot/digipot_mcp4018.cpp | 2 +- .../src/feature/digipot/digipot_mcp4451.cpp | 2 +- Marlin/src/gcode/bedlevel/G26.cpp | 6 +- Marlin/src/gcode/bedlevel/abl/G29.cpp | 2 +- Marlin/src/gcode/bedlevel/mbl/G29.cpp | 2 +- Marlin/src/gcode/calibrate/G28.cpp | 2 +- Marlin/src/gcode/calibrate/M48.cpp | 2 +- Marlin/src/gcode/control/M605.cpp | 2 +- Marlin/src/gcode/feature/pause/M125.cpp | 2 +- Marlin/src/gcode/feature/pause/M600.cpp | 6 +- Marlin/src/gcode/feature/pause/M603.cpp | 4 +- Marlin/src/gcode/feature/pause/M701_M702.cpp | 12 +-- Marlin/src/gcode/motion/G0_G1.cpp | 2 +- Marlin/src/gcode/motion/G2_G3.cpp | 2 +- Marlin/src/gcode/probe/G38.cpp | 6 +- Marlin/src/gcode/temperature/M104_M109.cpp | 2 +- Marlin/src/gcode/temperature/M106_M107.cpp | 4 +- Marlin/src/gcode/temperature/M140_M190.cpp | 2 +- Marlin/src/inc/Conditionals_post.h | 21 +++--- Marlin/src/lcd/malyanlcd.cpp | 4 +- Marlin/src/lcd/ultralcd.cpp | 18 ++--- Marlin/src/lcd/ultralcd_impl_DOGM.h | 2 +- Marlin/src/lcd/ultralcd_impl_HD44780.h | 10 +-- Marlin/src/libs/least_squares_fit.cpp | 2 +- Marlin/src/libs/least_squares_fit.h | 8 +- Marlin/src/libs/nozzle.cpp | 6 +- Marlin/src/module/delta.cpp | 2 +- Marlin/src/module/motion.cpp | 21 +++--- Marlin/src/module/motion.h | 2 +- Marlin/src/module/planner.cpp | 58 +++++++-------- Marlin/src/module/planner.h | 2 +- Marlin/src/module/planner_bezier.cpp | 2 +- Marlin/src/module/probe.cpp | 4 +- Marlin/src/module/temperature.cpp | 8 +- Marlin/src/module/temperature.h | 6 +- 52 files changed, 206 insertions(+), 247 deletions(-) diff --git a/Marlin/src/HAL/HAL_DUE/usb/compiler.h b/Marlin/src/HAL/HAL_DUE/usb/compiler.h index efc895bb11..43895381a2 100644 --- a/Marlin/src/HAL/HAL_DUE/usb/compiler.h +++ b/Marlin/src/HAL/HAL_DUE/usb/compiler.h @@ -785,79 +785,6 @@ typedef struct //! @} - -/*! \name Mathematics - * - * The same considerations as for clz and ctz apply here but GCC does not - * provide built-in functions to access the assembly instructions abs, min and - * max and it does not produce them by itself in most cases, so two sets of - * macros are defined here: - * - Abs, Min and Max to apply to constant expressions (values known at - * compile time); - * - abs, min and max to apply to non-constant expressions (values unknown at - * compile time), abs is found in stdlib.h. - */ -//! @{ - -/*! \brief Takes the absolute value of \a a. - * - * \param a Input value. - * - * \return Absolute value of \a a. - * - * \note More optimized if only used with values known at compile time. - */ -#define Abs(a) (((a) < 0 ) ? -(a) : (a)) - -/*! \brief Takes the minimal value of \a a and \a b. - * - * \param a Input value. - * \param b Input value. - * - * \return Minimal value of \a a and \a b. - * - * \note More optimized if only used with values known at compile time. - */ -#define Min(a, b) (((a) < (b)) ? (a) : (b)) - -/*! \brief Takes the maximal value of \a a and \a b. - * - * \param a Input value. - * \param b Input value. - * - * \return Maximal value of \a a and \a b. - * - * \note More optimized if only used with values known at compile time. - */ -#define Max(a, b) (((a) > (b)) ? (a) : (b)) - -// abs() is already defined by stdlib.h - -/*! \brief Takes the minimal value of \a a and \a b. - * - * \param a Input value. - * \param b Input value. - * - * \return Minimal value of \a a and \a b. - * - * \note More optimized if only used with values unknown at compile time. - */ -#define min(a, b) Min(a, b) - -/*! \brief Takes the maximal value of \a a and \a b. - * - * \param a Input value. - * \param b Input value. - * - * \return Maximal value of \a a and \a b. - * - * \note More optimized if only used with values unknown at compile time. - */ -#define max(a, b) Max(a, b) - -//! @} - - /*! \brief Calls the routine at address \a addr. * * It generates a long call opcode. diff --git a/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.c b/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.c index fce050cf69..0dfcd5ac1f 100644 --- a/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.c +++ b/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.c @@ -1904,7 +1904,7 @@ static void udd_ep_in_sent(udd_ep_id_t ep) ptr_src = &ptr_job->buf[ptr_job->buf_cnt]; nb_remain = ptr_job->buf_size - ptr_job->buf_cnt; // Fill a bank even if no data (ZLP) - nb_data = min(nb_remain, pkt_size); + nb_data = MIN(nb_remain, pkt_size); // Modify job information ptr_job->buf_cnt += nb_data; ptr_job->buf_load = nb_data; diff --git a/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.h b/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.h index 88e015ca37..9ed7f11241 100644 --- a/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.h +++ b/Marlin/src/HAL/HAL_DUE/usb/uotghs_device_due.h @@ -290,7 +290,7 @@ extern "C" { //! Bounds given integer size to allowed range and rounds it up to the nearest //! available greater size, then applies register format of UOTGHS controller //! for endpoint size bit-field. -#define udd_format_endpoint_size(size) (32 - clz(((uint32_t)min(max(size, 8), 1024) << 1) - 1) - 1 - 3) +#define udd_format_endpoint_size(size) (32 - clz(((uint32_t)MIN(MAX(size, 8), 1024) << 1) - 1) - 1 - 3) //! Configures the selected endpoint size #define udd_configure_endpoint_size(ep, size) (Wr_bitfield(UOTGHS_ARRAY(UOTGHS_DEVEPTCFG[0], ep), UOTGHS_DEVEPTCFG_EPSIZE_Msk, udd_format_endpoint_size(size))) //! Gets the configured selected endpoint size diff --git a/Marlin/src/HAL/HAL_LPC1768/SoftwareSPI.cpp b/Marlin/src/HAL/HAL_LPC1768/SoftwareSPI.cpp index 14c01e83ba..87f7bf383e 100644 --- a/Marlin/src/HAL/HAL_LPC1768/SoftwareSPI.cpp +++ b/Marlin/src/HAL/HAL_LPC1768/SoftwareSPI.cpp @@ -84,7 +84,7 @@ void swSpiBegin(const pin_t sck_pin, const pin_t miso_pin, const pin_t mosi_pin) uint8_t swSpiInit(const uint8_t spiRate, const pin_t sck_pin, const pin_t mosi_pin) { WRITE(mosi_pin, HIGH); WRITE(sck_pin, LOW); - return (SystemCoreClock == 120000000 ? 44 : 38) / POW(2, 6 - min(spiRate, 6)); + return (SystemCoreClock == 120000000 ? 44 : 38) / POW(2, 6 - MIN(spiRate, 6)); } #endif // TARGET_LPC1768 diff --git a/Marlin/src/HAL/HAL_LPC1768/include/Arduino.h b/Marlin/src/HAL/HAL_LPC1768/include/Arduino.h index d43021b290..ecb877e09c 100644 --- a/Marlin/src/HAL/HAL_LPC1768/include/Arduino.h +++ b/Marlin/src/HAL/HAL_LPC1768/include/Arduino.h @@ -50,9 +50,11 @@ typedef uint8_t byte; #define PSTR(v) (v) #define PGM_P const char * +// Used for libraries, preprocessor, and constants #define min(a,b) ((a)<(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b)) #define abs(x) ((x)>0?(x):-(x)) + #ifndef isnan #define isnan std::isnan #endif @@ -60,11 +62,6 @@ typedef uint8_t byte; #define isinf std::isinf #endif -//not constexpr until c++14 -//#define max(v1, v2) std::max((int)v1,(int)v2) -//#define min(v1, v2) std::min((int)v1,(int)v2) -//#define abs(v) std::abs(v) - #define sq(v) ((v) * (v)) #define square(v) sq(v) #define constrain(value, arg_min, arg_max) ((value) < (arg_min) ? (arg_min) :((value) > (arg_max) ? (arg_max) : (value))) diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.cpp b/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.cpp index 21a6482690..41e4a6c3c7 100644 --- a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.cpp +++ b/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.cpp @@ -121,7 +121,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { timer_set_count(STEP_TIMER_DEV, 0); timer_set_prescaler(STEP_TIMER_DEV, (uint16)(STEPPER_TIMER_PRESCALE - 1)); timer_set_reload(STEP_TIMER_DEV, 0xFFFF); - timer_set_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN, min(HAL_TIMER_TYPE_MAX, (HAL_STEPPER_TIMER_RATE / frequency))); + timer_set_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN, MIN(HAL_TIMER_TYPE_MAX, (HAL_STEPPER_TIMER_RATE / frequency))); timer_attach_interrupt(STEP_TIMER_DEV, STEP_TIMER_CHAN, stepTC_Handler); nvic_irq_set_priority(irq_num, 1); timer_generate_update(STEP_TIMER_DEV); @@ -132,7 +132,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { timer_set_count(TEMP_TIMER_DEV, 0); timer_set_prescaler(TEMP_TIMER_DEV, (uint16)(TEMP_TIMER_PRESCALE - 1)); timer_set_reload(TEMP_TIMER_DEV, 0xFFFF); - timer_set_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, min(HAL_TIMER_TYPE_MAX, ((F_CPU / TEMP_TIMER_PRESCALE) / frequency))); + timer_set_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, MIN(HAL_TIMER_TYPE_MAX, ((F_CPU / TEMP_TIMER_PRESCALE) / frequency))); timer_attach_interrupt(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, tempTC_Handler); nvic_irq_set_priority(irq_num, 2); timer_generate_update(TEMP_TIMER_DEV); diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h b/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h index b97c7667e1..fcce7e6cb4 100644 --- a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h +++ b/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h @@ -130,7 +130,7 @@ bool HAL_timer_interrupt_enabled(const uint8_t timer_num); */ FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) { - //compare = min(compare, HAL_TIMER_TYPE_MAX); + //compare = MIN(compare, HAL_TIMER_TYPE_MAX); switch (timer_num) { case STEP_TIMER_NUM: timer_set_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN, compare); diff --git a/Marlin/src/HAL/HAL_STM32F7/TMC2660.cpp b/Marlin/src/HAL/HAL_STM32F7/TMC2660.cpp index ff092907b6..f2d14658eb 100644 --- a/Marlin/src/HAL/HAL_STM32F7/TMC2660.cpp +++ b/Marlin/src/HAL/HAL_STM32F7/TMC2660.cpp @@ -237,7 +237,7 @@ unsigned int TMC26XStepper::getSpeed(void) { return this->speed; } */ char TMC26XStepper::step(int steps_to_move) { if (this->steps_left == 0) { - this->steps_left = abs(steps_to_move); // how many steps to take + this->steps_left = ABS(steps_to_move); // how many steps to take // determine direction based on whether steps_to_move is + or -: if (steps_to_move > 0) @@ -257,7 +257,7 @@ char TMC26XStepper::move(void) { // rem if (time >= this->next_step_time) { - if (abs(time - this->last_step_time) > this->step_delay) { + if (ABS(time - this->last_step_time) > this->step_delay) { // increment or decrement the step number, // depending on direction: if (this->direction == 1) diff --git a/Marlin/src/HAL/servo.cpp b/Marlin/src/HAL/servo.cpp index 9635f92c43..4ff2779153 100644 --- a/Marlin/src/HAL/servo.cpp +++ b/Marlin/src/HAL/servo.cpp @@ -99,7 +99,7 @@ int8_t Servo::attach(const int pin, const int min, const int max) { if (pin > 0) servo_info[this->servoIndex].Pin.nbr = pin; pinMode(servo_info[this->servoIndex].Pin.nbr, OUTPUT); // set servo pin to output - // todo min/max check: abs(min - MIN_PULSE_WIDTH) /4 < 128 + // todo min/max check: ABS(min - MIN_PULSE_WIDTH) /4 < 128 this->min = (MIN_PULSE_WIDTH - min) / 4; //resolution of min/max is 4 uS this->max = (MAX_PULSE_WIDTH - max) / 4; diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h index 4ba013bc1d..23364a434d 100644 --- a/Marlin/src/core/macros.h +++ b/Marlin/src/core/macros.h @@ -113,7 +113,7 @@ #define DECIMAL_SIGNED(a) (DECIMAL(a) || (a) == '-' || (a) == '+') #define COUNT(a) (sizeof(a)/sizeof(*a)) #define ZERO(a) memset(a,0,sizeof(a)) -#define COPY(a,b) memcpy(a,b,min(sizeof(a),sizeof(b))) +#define COPY(a,b) memcpy(a,b,MIN(sizeof(a),sizeof(b))) // Macros for initializing arrays #define ARRAY_6(v1, v2, v3, v4, v5, v6, ...) { v1, v2, v3, v4, v5, v6 } @@ -164,12 +164,48 @@ #define CEILING(x,y) (((x) + (y) - 1) / (y)) -#define MIN3(a, b, c) min(min(a, b), c) -#define MIN4(a, b, c, d) min(MIN3(a, b, c), d) -#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e) -#define MAX3(a, b, c) max(max(a, b), c) -#define MAX4(a, b, c, d) max(MAX3(a, b, c), d) -#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e) +// Avoid double evaluation of arguments on MIN/MAX/ABS +#undef MIN +#undef MAX +#undef ABS +#ifdef __cplusplus + + // C++11 solution that is standards compliant. Return type is deduced automatically + template static inline constexpr auto MIN(const L lhs, const R rhs) -> decltype(lhs + rhs) { + return lhs < rhs ? lhs : rhs; + } + template static inline constexpr auto MAX(const L lhs, const R rhs) -> decltype(lhs + rhs){ + return lhs > rhs ? lhs : rhs; + } + template static inline constexpr const T ABS(const T v) { + return v >= 0 ? v : -v; + } +#else + + // Using GCC extensions, but Travis GCC version does not like it and gives + // "error: statement-expressions are not allowed outside functions nor in template-argument lists" + #define MIN(a, b) \ + ({__typeof__(a) _a = (a); \ + __typeof__(b) _b = (b); \ + _a < _b ? _a : _b;}) + + #define MAX(a, b) \ + ({__typeof__(a) _a = (a); \ + __typeof__(b) _b = (b); \ + _a > _b ? _a : _b;}) + + #define ABS(a) \ + ({__typeof__(a) _a = (a); \ + _a >= 0 ? _a : -_a;}) + +#endif + +#define MIN3(a, b, c) MIN(MIN(a, b), c) +#define MIN4(a, b, c, d) MIN(MIN3(a, b, c), d) +#define MIN5(a, b, c, d, e) MIN(MIN4(a, b, c, d), e) +#define MAX3(a, b, c) MAX(MAX(a, b), c) +#define MAX4(a, b, c, d) MAX(MAX3(a, b, c), d) +#define MAX5(a, b, c, d, e) MAX(MAX4(a, b, c, d), e) #define UNEAR_ZERO(x) ((x) < 0.000001) #define NEAR_ZERO(x) WITHIN(x, -0.000001, 0.000001) @@ -182,7 +218,6 @@ // Maths macros that can be overridden by HAL // #define ATAN2(y, x) atan2(y, x) -#define FABS(x) fabs(x) #define POW(x, y) pow(x, y) #define SQRT(x) sqrt(x) #define CEIL(x) ceil(x) diff --git a/Marlin/src/feature/I2CPositionEncoder.cpp b/Marlin/src/feature/I2CPositionEncoder.cpp index b1778ae582..6a088d6760 100644 --- a/Marlin/src/feature/I2CPositionEncoder.cpp +++ b/Marlin/src/feature/I2CPositionEncoder.cpp @@ -134,7 +134,7 @@ void I2CPositionEncoder::update() { #ifdef I2CPE_EC_THRESH_PROPORTIONAL const millis_t deltaTime = positionTime - lastPositionTime; - const uint32_t distance = abs(position - lastPosition), + const uint32_t distance = ABS(position - lastPosition), speed = distance / deltaTime; const float threshold = constrain((speed / 50), 1, 50) * ecThreshold; #else @@ -150,7 +150,7 @@ void I2CPositionEncoder::update() { LOOP_L_N(i, I2CPE_ERR_ARRAY_SIZE) { sum += err[i]; - if (i) diffSum += abs(err[i-1] - err[i]); + if (i) diffSum += ABS(err[i-1] - err[i]); } const int32_t error = int32_t(sum / (I2CPE_ERR_ARRAY_SIZE + 1)); //calculate average for error @@ -163,7 +163,7 @@ void I2CPositionEncoder::update() { //SERIAL_ECHOLN(error); #ifdef I2CPE_ERR_THRESH_ABORT - if (labs(error) > I2CPE_ERR_THRESH_ABORT * planner.axis_steps_per_mm[encoderAxis]) { + if (ABS(error) > I2CPE_ERR_THRESH_ABORT * planner.axis_steps_per_mm[encoderAxis]) { //kill("Significant Error"); SERIAL_ECHOPGM("Axis error greater than set threshold, aborting!"); SERIAL_ECHOLN(error); @@ -175,8 +175,8 @@ void I2CPositionEncoder::update() { if (errIdx == 0) { // In order to correct for "error" but avoid correcting for noise and non-skips // it must be > threshold and have a difference average of < 10 and be < 2000 steps - if (labs(error) > threshold * planner.axis_steps_per_mm[encoderAxis] && - diffSum < 10 * (I2CPE_ERR_ARRAY_SIZE - 1) && labs(error) < 2000) { // Check for persistent error (skip) + if (ABS(error) > threshold * planner.axis_steps_per_mm[encoderAxis] && + diffSum < 10 * (I2CPE_ERR_ARRAY_SIZE - 1) && ABS(error) < 2000) { // Check for persistent error (skip) errPrst[errPrstIdx++] = error; // Error must persist for I2CPE_ERR_PRST_ARRAY_SIZE error cycles. This also serves to improve the average accuracy if (errPrstIdx >= I2CPE_ERR_PRST_ARRAY_SIZE) { float sumP = 0; @@ -193,14 +193,14 @@ void I2CPositionEncoder::update() { errPrstIdx = 0; } #else - if (labs(error) > threshold * planner.axis_steps_per_mm[encoderAxis]) { + if (ABS(error) > threshold * planner.axis_steps_per_mm[encoderAxis]) { //SERIAL_ECHOLN(error); //SERIAL_ECHOLN(position); thermalManager.babystepsTodo[encoderAxis] = -LROUND(error / 2); } #endif - if (labs(error) > I2CPE_ERR_CNT_THRESH * planner.axis_steps_per_mm[encoderAxis]) { + if (ABS(error) > I2CPE_ERR_CNT_THRESH * planner.axis_steps_per_mm[encoderAxis]) { const millis_t ms = millis(); if (ELAPSED(ms, nextErrorCountTime)) { SERIAL_ECHOPAIR("Large error on ", axis_codes[encoderAxis]); @@ -258,7 +258,7 @@ float I2CPositionEncoder::get_axis_error_mm(const bool report) { actual = mm_from_count(position); error = actual - target; - if (labs(error) > 10000) error = 0; // ? + if (ABS(error) > 10000) error = 0; // ? if (report) { SERIAL_ECHO(axis_codes[encoderAxis]); @@ -293,7 +293,7 @@ int32_t I2CPositionEncoder::get_axis_error_steps(const bool report) { error = (encoderCountInStepperTicksScaled - target); //suppress discontinuities (might be caused by bad I2C readings...?) - bool suppressOutput = (labs(error - errorPrev) > 100); + bool suppressOutput = (ABS(error - errorPrev) > 100); if (report) { SERIAL_ECHO(axis_codes[encoderAxis]); @@ -435,7 +435,7 @@ void I2CPositionEncoder::calibrate_steps_mm(const uint8_t iter) { delay(250); stopCount = get_position(); - travelledDistance = mm_from_count(abs(stopCount - startCount)); + travelledDistance = mm_from_count(ABS(stopCount - startCount)); SERIAL_ECHOPAIR("Attempted to travel: ", travelDistance); SERIAL_ECHOLNPGM("mm."); diff --git a/Marlin/src/feature/Max7219_Debug_LEDs.cpp b/Marlin/src/feature/Max7219_Debug_LEDs.cpp index 6946490ed4..616b61c18c 100644 --- a/Marlin/src/feature/Max7219_Debug_LEDs.cpp +++ b/Marlin/src/feature/Max7219_Debug_LEDs.cpp @@ -347,8 +347,8 @@ void Max7219_idle_tasks() { NOMORE(current_depth, 16); // if the BLOCK_BUFFER_SIZE is greater than 16, two lines // of LEDs is enough to see if the buffer is draining - const uint8_t st = min(current_depth, last_depth), - en = max(current_depth, last_depth); + const uint8_t st = MIN(current_depth, last_depth), + en = MAX(current_depth, last_depth); if (current_depth < last_depth) for (uint8_t i = st; i <= en; i++) // clear the highest order LEDs Max7219_LED_Off(MAX7219_DEBUG_STEPPER_QUEUE + (i & 1), i / 2); diff --git a/Marlin/src/feature/bedlevel/abl/abl.cpp b/Marlin/src/feature/bedlevel/abl/abl.cpp index 6362608622..28dcb5e512 100644 --- a/Marlin/src/feature/bedlevel/abl/abl.cpp +++ b/Marlin/src/feature/bedlevel/abl/abl.cpp @@ -295,7 +295,7 @@ float bilinear_z_offset(const float raw[XYZ]) { #endif gridx = gx; - nextx = min(gridx + 1, ABL_BG_POINTS_X - 1); + nextx = MIN(gridx + 1, ABL_BG_POINTS_X - 1); } if (last_y != ry || last_gridx != gridx) { @@ -312,7 +312,7 @@ float bilinear_z_offset(const float raw[XYZ]) { #endif gridy = gy; - nexty = min(gridy + 1, ABL_BG_POINTS_Y - 1); + nexty = MIN(gridy + 1, ABL_BG_POINTS_Y - 1); } if (last_gridx != gridx || last_gridy != gridy) { @@ -336,7 +336,7 @@ float bilinear_z_offset(const float raw[XYZ]) { /* static float last_offset = 0; - if (FABS(last_offset - offset) > 0.2) { + if (ABS(last_offset - offset) > 0.2) { SERIAL_ECHOPGM("Sudden Shift at "); SERIAL_ECHOPAIR("x=", rx); SERIAL_ECHOPAIR(" / ", bilinear_grid_spacing[X_AXIS]); @@ -389,7 +389,7 @@ float bilinear_z_offset(const float raw[XYZ]) { #define LINE_SEGMENT_END(A) (current_position[A ##_AXIS] + (destination[A ##_AXIS] - current_position[A ##_AXIS]) * normalized_dist) float normalized_dist, end[XYZE]; - const int8_t gcx = max(cx1, cx2), gcy = max(cy1, cy2); + const int8_t gcx = MAX(cx1, cx2), gcy = MAX(cy1, cy2); // Crosses on the X and not already split on this X? // The x_splits flags are insurance against rounding errors. diff --git a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp index 800630c6ba..97e1eacac5 100644 --- a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp +++ b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp @@ -76,7 +76,7 @@ #define MBL_SEGMENT_END(A) (current_position[A ##_AXIS] + (destination[A ##_AXIS] - current_position[A ##_AXIS]) * normalized_dist) float normalized_dist, end[XYZE]; - const int8_t gcx = max(cx1, cx2), gcy = max(cy1, cy2); + const int8_t gcx = MAX(cx1, cx2), gcy = MAX(cy1, cy2); // Crosses on the X and not already split on this X? // The x_splits flags are insurance against rounding errors. diff --git a/Marlin/src/feature/bedlevel/ubl/ubl.h b/Marlin/src/feature/bedlevel/ubl/ubl.h index a79d9a67ec..dcb9a1024d 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl.h +++ b/Marlin/src/feature/bedlevel/ubl/ubl.h @@ -242,7 +242,7 @@ class unified_bed_leveling { const float xratio = (rx0 - mesh_index_to_xpos(x1_i)) * (1.0 / (MESH_X_DIST)), z1 = z_values[x1_i][yi]; - return z1 + xratio * (z_values[min(x1_i, GRID_MAX_POINTS_X - 2) + 1][yi] - z1); // Don't allow x1_i+1 to be past the end of the array + return z1 + xratio * (z_values[MIN(x1_i, GRID_MAX_POINTS_X - 2) + 1][yi] - z1); // Don't allow x1_i+1 to be past the end of the array // If it is, it is clamped to the last element of the // z_values[][] array and no correction is applied. } @@ -276,7 +276,7 @@ class unified_bed_leveling { const float yratio = (ry0 - mesh_index_to_ypos(y1_i)) * (1.0 / (MESH_Y_DIST)), z1 = z_values[xi][y1_i]; - return z1 + yratio * (z_values[xi][min(y1_i, GRID_MAX_POINTS_Y - 2) + 1] - z1); // Don't allow y1_i+1 to be past the end of the array + return z1 + yratio * (z_values[xi][MIN(y1_i, GRID_MAX_POINTS_Y - 2) + 1] - z1); // Don't allow y1_i+1 to be past the end of the array // If it is, it is clamped to the last element of the // z_values[][] array and no correction is applied. } @@ -302,11 +302,11 @@ class unified_bed_leveling { const float z1 = calc_z0(rx0, mesh_index_to_xpos(cx), z_values[cx][cy], - mesh_index_to_xpos(cx + 1), z_values[min(cx, GRID_MAX_POINTS_X - 2) + 1][cy]); + mesh_index_to_xpos(cx + 1), z_values[MIN(cx, GRID_MAX_POINTS_X - 2) + 1][cy]); const float z2 = calc_z0(rx0, - mesh_index_to_xpos(cx), z_values[cx][min(cy, GRID_MAX_POINTS_Y - 2) + 1], - mesh_index_to_xpos(cx + 1), z_values[min(cx, GRID_MAX_POINTS_X - 2) + 1][min(cy, GRID_MAX_POINTS_Y - 2) + 1]); + mesh_index_to_xpos(cx), z_values[cx][MIN(cy, GRID_MAX_POINTS_Y - 2) + 1], + mesh_index_to_xpos(cx + 1), z_values[MIN(cx, GRID_MAX_POINTS_X - 2) + 1][MIN(cy, GRID_MAX_POINTS_Y - 2) + 1]); float z0 = calc_z0(ry0, mesh_index_to_ypos(cy), z1, diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp index c4b1dc73d1..2ed21e4acc 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp @@ -451,7 +451,7 @@ if (parser.seen('B')) { g29_card_thickness = parser.has_value() ? parser.value_float() : measure_business_card_thickness((float) Z_CLEARANCE_BETWEEN_PROBES); - if (FABS(g29_card_thickness) > 1.5) { + if (ABS(g29_card_thickness) > 1.5) { SERIAL_PROTOCOLLNPGM("?Error in Business Card measurement."); return; } @@ -796,7 +796,7 @@ save_ubl_active_state_and_disable(); // Disable bed level correction for probing do_blocking_move_to(0.5 * (MESH_MAX_X - (MESH_MIN_X)), 0.5 * (MESH_MAX_Y - (MESH_MIN_Y)), in_height); - //, min(planner.max_feedrate_mm_s[X_AXIS], planner.max_feedrate_mm_s[Y_AXIS]) / 2.0); + //, MIN(planner.max_feedrate_mm_s[X_AXIS], planner.max_feedrate_mm_s[Y_AXIS]) / 2.0); planner.synchronize(); SERIAL_PROTOCOLPGM("Place shim under nozzle"); @@ -816,7 +816,7 @@ do_blocking_move_to_z(current_position[Z_AXIS] + Z_CLEARANCE_BETWEEN_PROBES); - const float thickness = abs(z1 - z2); + const float thickness = ABS(z1 - z2); if (g29_verbose_level > 1) { SERIAL_PROTOCOLPGM("Business Card is "); @@ -1499,10 +1499,10 @@ #include "../../../libs/vector_3.h" void unified_bed_leveling::tilt_mesh_based_on_probed_grid(const bool do_3_pt_leveling) { - constexpr int16_t x_min = max(MIN_PROBE_X, MESH_MIN_X), - x_max = min(MAX_PROBE_X, MESH_MAX_X), - y_min = max(MIN_PROBE_Y, MESH_MIN_Y), - y_max = min(MAX_PROBE_Y, MESH_MAX_Y); + constexpr int16_t x_min = MAX(MIN_PROBE_X, MESH_MIN_X), + x_max = MIN(MAX_PROBE_X, MESH_MAX_X), + y_min = MAX(MIN_PROBE_Y, MESH_MIN_Y), + y_max = MIN(MAX_PROBE_Y, MESH_MAX_Y); bool abort_flag = false; @@ -1770,7 +1770,7 @@ SERIAL_ECHOPGM("Extrapolating mesh..."); - const float weight_scaled = weight_factor * max(MESH_X_DIST, MESH_Y_DIST); + const float weight_scaled = weight_factor * MAX(MESH_X_DIST, MESH_Y_DIST); for (uint8_t jx = 0; jx < GRID_MAX_POINTS_X; jx++) for (uint8_t jy = 0; jy < GRID_MAX_POINTS_Y; jy++) diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp index 957a3a7d1d..85a6fad8e6 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp @@ -387,11 +387,11 @@ inverse_kinematics(raw); // this writes delta[ABC] from raw[XYZE] // should move the feedrate scaling to scara inverse_kinematics - const float adiff = FABS(delta[A_AXIS] - scara_oldA), - bdiff = FABS(delta[B_AXIS] - scara_oldB); + const float adiff = ABS(delta[A_AXIS] - scara_oldA), + bdiff = ABS(delta[B_AXIS] - scara_oldB); scara_oldA = delta[A_AXIS]; scara_oldB = delta[B_AXIS]; - float s_feedrate = max(adiff, bdiff) * scara_feed_factor; + float s_feedrate = MAX(adiff, bdiff) * scara_feed_factor; planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], in_raw[E_AXIS], s_feedrate, active_extruder); diff --git a/Marlin/src/feature/digipot/digipot_mcp4018.cpp b/Marlin/src/feature/digipot/digipot_mcp4018.cpp index 5ae24188fd..12a180e7d4 100644 --- a/Marlin/src/feature/digipot/digipot_mcp4018.cpp +++ b/Marlin/src/feature/digipot/digipot_mcp4018.cpp @@ -87,7 +87,7 @@ static void i2c_send(const uint8_t channel, const byte v) { // This is for the MCP4018 I2C based digipot void digipot_i2c_set_current(const uint8_t channel, const float current) { - i2c_send(channel, current_to_wiper(min(max(current, 0.0f), float(DIGIPOT_A4988_MAX_CURRENT)))); + i2c_send(channel, current_to_wiper(MIN(MAX(current, 0.0f), float(DIGIPOT_A4988_MAX_CURRENT)))); } void digipot_i2c_init() { diff --git a/Marlin/src/feature/digipot/digipot_mcp4451.cpp b/Marlin/src/feature/digipot/digipot_mcp4451.cpp index 2d6ab3147e..ca02977f85 100644 --- a/Marlin/src/feature/digipot/digipot_mcp4451.cpp +++ b/Marlin/src/feature/digipot/digipot_mcp4451.cpp @@ -69,7 +69,7 @@ void digipot_i2c_set_current(const uint8_t channel, const float current) { // Set actual wiper value byte addresses[4] = { 0x00, 0x10, 0x60, 0x70 }; - i2c_send(addr, addresses[channel & 0x3], current_to_wiper(min((float) max(current, 0.0f), DIGIPOT_I2C_MAX_CURRENT))); + i2c_send(addr, addresses[channel & 0x3], current_to_wiper(MIN((float) MAX(current, 0.0f), DIGIPOT_I2C_MAX_CURRENT))); } void digipot_i2c_init() { diff --git a/Marlin/src/gcode/bedlevel/G26.cpp b/Marlin/src/gcode/bedlevel/G26.cpp index 749f305d8a..a11d98675c 100644 --- a/Marlin/src/gcode/bedlevel/G26.cpp +++ b/Marlin/src/gcode/bedlevel/G26.cpp @@ -305,7 +305,7 @@ void print_line_from_here_to_there(const float &sx, const float &sy, const float // If the end point of the line is closer to the nozzle, flip the direction, // moving from the end to the start. On very small lines the optimization isn't worth it. - if (dist_end < dist_start && (INTERSECTION_CIRCLE_RADIUS) < FABS(line_length)) + if (dist_end < dist_start && (INTERSECTION_CIRCLE_RADIUS) < ABS(line_length)) return print_line_from_here_to_there(ex, ey, ez, sx, sy, sz); // Decide whether to retract & bump @@ -427,7 +427,7 @@ inline bool turn_on_heaters() { #endif #endif thermalManager.setTargetBed(g26_bed_temp); - while (abs(thermalManager.degBed() - g26_bed_temp) > 3) { + while (ABS(thermalManager.degBed() - g26_bed_temp) > 3) { #if ENABLED(NEWPANEL) if (is_lcd_clicked()) return exit_from_g26(); @@ -450,7 +450,7 @@ inline bool turn_on_heaters() { // Start heating the nozzle and wait for it to reach temperature. thermalManager.setTargetHotend(g26_hotend_temp, 0); - while (abs(thermalManager.degHotend(0) - g26_hotend_temp) > 3) { + while (ABS(thermalManager.degHotend(0) - g26_hotend_temp) > 3) { #if ENABLED(NEWPANEL) if (is_lcd_clicked()) return exit_from_g26(); diff --git a/Marlin/src/gcode/bedlevel/abl/G29.cpp b/Marlin/src/gcode/bedlevel/abl/G29.cpp index e4a597da2c..552c5d36ef 100644 --- a/Marlin/src/gcode/bedlevel/abl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/abl/G29.cpp @@ -471,7 +471,7 @@ void GcodeSuite::G29() { if (verbose_level || seenQ) { SERIAL_PROTOCOLPGM("Manual G29 "); if (g29_in_progress) { - SERIAL_PROTOCOLPAIR("point ", min(abl_probe_index + 1, abl_points)); + SERIAL_PROTOCOLPAIR("point ", MIN(abl_probe_index + 1, abl_points)); SERIAL_PROTOCOLLNPAIR(" of ", abl_points); } else diff --git a/Marlin/src/gcode/bedlevel/mbl/G29.cpp b/Marlin/src/gcode/bedlevel/mbl/G29.cpp index 0332506d99..8c970e89b0 100644 --- a/Marlin/src/gcode/bedlevel/mbl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/mbl/G29.cpp @@ -205,7 +205,7 @@ void GcodeSuite::G29() { } // switch(state) if (state == MeshNext) { - SERIAL_PROTOCOLPAIR("MBL G29 point ", min(mbl_probe_index, GRID_MAX_POINTS)); + SERIAL_PROTOCOLPAIR("MBL G29 point ", MIN(mbl_probe_index, GRID_MAX_POINTS)); SERIAL_PROTOCOLLNPAIR(" of ", int(GRID_MAX_POINTS)); } diff --git a/Marlin/src/gcode/calibrate/G28.cpp b/Marlin/src/gcode/calibrate/G28.cpp index a0bce4731c..c299a119ad 100644 --- a/Marlin/src/gcode/calibrate/G28.cpp +++ b/Marlin/src/gcode/calibrate/G28.cpp @@ -64,7 +64,7 @@ const float mlx = max_length(X_AXIS), mly = max_length(Y_AXIS), mlratio = mlx > mly ? mly / mlx : mlx / mly, - fr_mm_s = min(homing_feedrate(X_AXIS), homing_feedrate(Y_AXIS)) * SQRT(sq(mlratio) + 1.0); + fr_mm_s = MIN(homing_feedrate(X_AXIS), homing_feedrate(Y_AXIS)) * SQRT(sq(mlratio) + 1.0); #if ENABLED(SENSORLESS_HOMING) sensorless_homing_per_axis(X_AXIS); diff --git a/Marlin/src/gcode/calibrate/M48.cpp b/Marlin/src/gcode/calibrate/M48.cpp index 14efec5e00..3b5a18bbdd 100644 --- a/Marlin/src/gcode/calibrate/M48.cpp +++ b/Marlin/src/gcode/calibrate/M48.cpp @@ -129,7 +129,7 @@ void GcodeSuite::M48() { (int) (0.1250000000 * (DELTA_PRINTABLE_RADIUS)), (int) (0.3333333333 * (DELTA_PRINTABLE_RADIUS)) #else - (int) 5.0, (int) (0.125 * min(X_BED_SIZE, Y_BED_SIZE)) + (int) 5.0, (int) (0.125 * MIN(X_BED_SIZE, Y_BED_SIZE)) #endif ); diff --git a/Marlin/src/gcode/control/M605.cpp b/Marlin/src/gcode/control/M605.cpp index e94e076e46..13ab424603 100644 --- a/Marlin/src/gcode/control/M605.cpp +++ b/Marlin/src/gcode/control/M605.cpp @@ -50,7 +50,7 @@ case DXC_AUTO_PARK_MODE: break; case DXC_DUPLICATION_MODE: - if (parser.seen('X')) duplicate_extruder_x_offset = max(parser.value_linear_units(), X2_MIN_POS - x_home_pos(0)); + if (parser.seen('X')) duplicate_extruder_x_offset = MAX(parser.value_linear_units(), X2_MIN_POS - x_home_pos(0)); if (parser.seen('R')) duplicate_extruder_temp_offset = parser.value_celsius_diff(); SERIAL_ECHO_START(); SERIAL_ECHOPGM(MSG_HOTEND_OFFSET); diff --git a/Marlin/src/gcode/feature/pause/M125.cpp b/Marlin/src/gcode/feature/pause/M125.cpp index f25b0907da..fbba475f2a 100644 --- a/Marlin/src/gcode/feature/pause/M125.cpp +++ b/Marlin/src/gcode/feature/pause/M125.cpp @@ -50,7 +50,7 @@ */ void GcodeSuite::M125() { // Initial retract before move to filament change position - const float retract = -FABS(parser.seen('L') ? parser.value_axis_units(E_AXIS) : 0 + const float retract = -ABS(parser.seen('L') ? parser.value_axis_units(E_AXIS) : 0 #ifdef PAUSE_PARK_RETRACT_LENGTH + (PAUSE_PARK_RETRACT_LENGTH) #endif diff --git a/Marlin/src/gcode/feature/pause/M600.cpp b/Marlin/src/gcode/feature/pause/M600.cpp index 3fc4d70fc4..be03c736c9 100644 --- a/Marlin/src/gcode/feature/pause/M600.cpp +++ b/Marlin/src/gcode/feature/pause/M600.cpp @@ -74,7 +74,7 @@ void GcodeSuite::M600() { #endif // Initial retract before move to filament change position - const float retract = -FABS(parser.seen('E') ? parser.value_axis_units(E_AXIS) : 0 + const float retract = -ABS(parser.seen('E') ? parser.value_axis_units(E_AXIS) : 0 #ifdef PAUSE_PARK_RETRACT_LENGTH + (PAUSE_PARK_RETRACT_LENGTH) #endif @@ -93,14 +93,14 @@ void GcodeSuite::M600() { #endif // Unload filament - const float unload_length = -FABS(parser.seen('U') ? parser.value_axis_units(E_AXIS) + const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS) : filament_change_unload_length[active_extruder]); // Slow load filament constexpr float slow_load_length = FILAMENT_CHANGE_SLOW_LOAD_LENGTH; // Fast load filament - const float fast_load_length = FABS(parser.seen('L') ? parser.value_axis_units(E_AXIS) + const float fast_load_length = ABS(parser.seen('L') ? parser.value_axis_units(E_AXIS) : filament_change_load_length[active_extruder]); const int beep_count = parser.intval('B', diff --git a/Marlin/src/gcode/feature/pause/M603.cpp b/Marlin/src/gcode/feature/pause/M603.cpp index 3ac44cc7b9..a6231c3169 100644 --- a/Marlin/src/gcode/feature/pause/M603.cpp +++ b/Marlin/src/gcode/feature/pause/M603.cpp @@ -47,7 +47,7 @@ void GcodeSuite::M603() { // Unload length if (parser.seen('U')) { - filament_change_unload_length[target_extruder] = FABS(parser.value_axis_units(E_AXIS)); + filament_change_unload_length[target_extruder] = ABS(parser.value_axis_units(E_AXIS)); #if ENABLED(PREVENT_LENGTHY_EXTRUDE) NOMORE(filament_change_unload_length[target_extruder], EXTRUDE_MAXLENGTH); #endif @@ -55,7 +55,7 @@ void GcodeSuite::M603() { // Load length if (parser.seen('L')) { - filament_change_load_length[target_extruder] = FABS(parser.value_axis_units(E_AXIS)); + filament_change_load_length[target_extruder] = ABS(parser.value_axis_units(E_AXIS)); #if ENABLED(PREVENT_LENGTHY_EXTRUDE) NOMORE(filament_change_load_length[target_extruder], EXTRUDE_MAXLENGTH); #endif diff --git a/Marlin/src/gcode/feature/pause/M701_M702.cpp b/Marlin/src/gcode/feature/pause/M701_M702.cpp index b875478fff..5dd37de6cc 100644 --- a/Marlin/src/gcode/feature/pause/M701_M702.cpp +++ b/Marlin/src/gcode/feature/pause/M701_M702.cpp @@ -74,18 +74,18 @@ void GcodeSuite::M701() { // Lift Z axis if (park_point.z > 0) - do_blocking_move_to_z(min(current_position[Z_AXIS] + park_point.z, Z_MAX_POS), NOZZLE_PARK_Z_FEEDRATE); + do_blocking_move_to_z(MIN(current_position[Z_AXIS] + park_point.z, Z_MAX_POS), NOZZLE_PARK_Z_FEEDRATE); // Load filament constexpr float slow_load_length = FILAMENT_CHANGE_SLOW_LOAD_LENGTH; - const float fast_load_length = FABS(parser.seen('L') ? parser.value_axis_units(E_AXIS) + const float fast_load_length = ABS(parser.seen('L') ? parser.value_axis_units(E_AXIS) : filament_change_load_length[active_extruder]); load_filament(slow_load_length, fast_load_length, ADVANCED_PAUSE_PURGE_LENGTH, FILAMENT_CHANGE_ALERT_BEEPS, true, thermalManager.wait_for_heating(target_extruder), ADVANCED_PAUSE_MODE_LOAD_FILAMENT); // Restore Z axis if (park_point.z > 0) - do_blocking_move_to_z(max(current_position[Z_AXIS] - park_point.z, 0), NOZZLE_PARK_Z_FEEDRATE); + do_blocking_move_to_z(MAX(current_position[Z_AXIS] - park_point.z, 0), NOZZLE_PARK_Z_FEEDRATE); #if EXTRUDERS > 1 // Restore toolhead if it was changed @@ -136,7 +136,7 @@ void GcodeSuite::M702() { // Lift Z axis if (park_point.z > 0) - do_blocking_move_to_z(min(current_position[Z_AXIS] + park_point.z, Z_MAX_POS), NOZZLE_PARK_Z_FEEDRATE); + do_blocking_move_to_z(MIN(current_position[Z_AXIS] + park_point.z, Z_MAX_POS), NOZZLE_PARK_Z_FEEDRATE); // Unload filament #if EXTRUDERS > 1 && ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS) @@ -150,7 +150,7 @@ void GcodeSuite::M702() { #endif { // Unload length - const float unload_length = -FABS(parser.seen('U') ? parser.value_axis_units(E_AXIS) : + const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS) : filament_change_unload_length[target_extruder]); unload_filament(unload_length, true, ADVANCED_PAUSE_MODE_UNLOAD_FILAMENT); @@ -158,7 +158,7 @@ void GcodeSuite::M702() { // Restore Z axis if (park_point.z > 0) - do_blocking_move_to_z(max(current_position[Z_AXIS] - park_point.z, 0), NOZZLE_PARK_Z_FEEDRATE); + do_blocking_move_to_z(MAX(current_position[Z_AXIS] - park_point.z, 0), NOZZLE_PARK_Z_FEEDRATE); #if EXTRUDERS > 1 // Restore toolhead if it was changed diff --git a/Marlin/src/gcode/motion/G0_G1.cpp b/Marlin/src/gcode/motion/G0_G1.cpp index d3091fecc5..b0e088b821 100644 --- a/Marlin/src/gcode/motion/G0_G1.cpp +++ b/Marlin/src/gcode/motion/G0_G1.cpp @@ -61,7 +61,7 @@ void GcodeSuite::G0_G1( if (fwretract.autoretract_enabled && parser.seen('E') && !(parser.seen('X') || parser.seen('Y') || parser.seen('Z'))) { const float echange = destination[E_AXIS] - current_position[E_AXIS]; // Is this a retract or recover move? - if (WITHIN(FABS(echange), MIN_AUTORETRACT, MAX_AUTORETRACT) && fwretract.retracted[active_extruder] == (echange > 0.0)) { + if (WITHIN(ABS(echange), MIN_AUTORETRACT, MAX_AUTORETRACT) && fwretract.retracted[active_extruder] == (echange > 0.0)) { current_position[E_AXIS] = destination[E_AXIS]; // Hide a G1-based retract/recover from calculations sync_plan_position_e(); // AND from the planner return fwretract.retract(echange < 0.0); // Firmware-based retract/recover (double-retract ignored) diff --git a/Marlin/src/gcode/motion/G2_G3.cpp b/Marlin/src/gcode/motion/G2_G3.cpp index 8ce54978ca..f5c98c934d 100644 --- a/Marlin/src/gcode/motion/G2_G3.cpp +++ b/Marlin/src/gcode/motion/G2_G3.cpp @@ -91,7 +91,7 @@ void plan_arc( angular_travel = RADIANS(360); const float flat_mm = radius * angular_travel, - mm_of_travel = linear_travel ? HYPOT(flat_mm, linear_travel) : FABS(flat_mm); + mm_of_travel = linear_travel ? HYPOT(flat_mm, linear_travel) : ABS(flat_mm); if (mm_of_travel < 0.001) return; uint16_t segments = FLOOR(mm_of_travel / (MM_PER_ARC_SEGMENT)); diff --git a/Marlin/src/gcode/probe/G38.cpp b/Marlin/src/gcode/probe/G38.cpp index 263b1d1df9..bdbb635ef3 100644 --- a/Marlin/src/gcode/probe/G38.cpp +++ b/Marlin/src/gcode/probe/G38.cpp @@ -39,8 +39,8 @@ static bool G38_run_probe() { // Get direction of move and retract float retract_mm[XYZ]; LOOP_XYZ(i) { - float dist = destination[i] - current_position[i]; - retract_mm[i] = FABS(dist) < G38_MINIMUM_MOVE ? 0 : home_bump_mm((AxisEnum)i) * (dist > 0 ? -1 : 1); + const float dist = destination[i] - current_position[i]; + retract_mm[i] = ABS(dist) < G38_MINIMUM_MOVE ? 0 : home_bump_mm((AxisEnum)i) * (dist > 0 ? -1 : 1); } #endif @@ -105,7 +105,7 @@ void GcodeSuite::G38(const bool is_38_2) { // If any axis has enough movement, do the move LOOP_XYZ(i) - if (FABS(destination[i] - current_position[i]) >= G38_MINIMUM_MOVE) { + if (ABS(destination[i] - current_position[i]) >= G38_MINIMUM_MOVE) { if (!parser.seenval('F')) feedrate_mm_s = homing_feedrate((AxisEnum)i); // If G38.2 fails throw an error if (!G38_run_probe() && is_38_2) { diff --git a/Marlin/src/gcode/temperature/M104_M109.cpp b/Marlin/src/gcode/temperature/M104_M109.cpp index 5b4be899c9..0104fd1a83 100644 --- a/Marlin/src/gcode/temperature/M104_M109.cpp +++ b/Marlin/src/gcode/temperature/M104_M109.cpp @@ -216,7 +216,7 @@ void GcodeSuite::M109() { #if TEMP_RESIDENCY_TIME > 0 - const float temp_diff = FABS(target_temp - temp); + const float temp_diff = ABS(target_temp - temp); if (!residency_start_ms) { // Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time. diff --git a/Marlin/src/gcode/temperature/M106_M107.cpp b/Marlin/src/gcode/temperature/M106_M107.cpp index dccf3234bf..b8bdc03d61 100644 --- a/Marlin/src/gcode/temperature/M106_M107.cpp +++ b/Marlin/src/gcode/temperature/M106_M107.cpp @@ -55,14 +55,14 @@ void GcodeSuite::M106() { fanSpeeds[p] = new_fanSpeeds[p]; break; default: - new_fanSpeeds[p] = min(t, 255); + new_fanSpeeds[p] = MIN(t, 255); break; } return; } #endif // EXTRA_FAN_SPEED const uint16_t s = parser.ushortval('S', 255); - fanSpeeds[p] = min(s, 255); + fanSpeeds[p] = MIN(s, 255U); } } diff --git a/Marlin/src/gcode/temperature/M140_M190.cpp b/Marlin/src/gcode/temperature/M140_M190.cpp index a8af02e591..324a1b9f93 100644 --- a/Marlin/src/gcode/temperature/M140_M190.cpp +++ b/Marlin/src/gcode/temperature/M140_M190.cpp @@ -145,7 +145,7 @@ void GcodeSuite::M190() { #if TEMP_BED_RESIDENCY_TIME > 0 - const float temp_diff = FABS(target_temp - temp); + const float temp_diff = ABS(target_temp - temp); if (!residency_start_ms) { // Start the TEMP_BED_RESIDENCY_TIME timer when we reach target temp for the first time. diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index d1dc972398..02531b3edc 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -35,6 +35,16 @@ || MB(SCOOVO_X9H) \ ) +#ifdef TEENSYDUINO + #undef max + #define max(a,b) ((a)>(b)?(a):(b)) + #undef min + #define min(a,b) ((a)<(b)?(a):(b)) + + #undef NOT_A_PIN // Override Teensyduino legacy CapSense define work-around + #define NOT_A_PIN 0 // For PINS_DEBUGGING +#endif + #define IS_SCARA (ENABLED(MORGAN_SCARA) || ENABLED(MAKERARM_SCARA)) #define IS_KINEMATIC (ENABLED(DELTA) || IS_SCARA) #define IS_CARTESIAN !IS_KINEMATIC @@ -1374,7 +1384,6 @@ #undef LROUND #undef FMOD #define ATAN2(y, x) atan2f(y, x) - #define FABS(x) fabsf(x) #define POW(x, y) powf(x, y) #define SQRT(x) sqrtf(x) #define CEIL(x) ceilf(x) @@ -1383,16 +1392,6 @@ #define FMOD(x, y) fmodf(x, y) #endif -#ifdef TEENSYDUINO - #undef max - #define max(a,b) ((a)>(b)?(a):(b)) - #undef min - #define min(a,b) ((a)<(b)?(a):(b)) - - #undef NOT_A_PIN // Override Teensyduino legacy CapSense define work-around - #define NOT_A_PIN 0 // For PINS_DEBUGGING -#endif - // Number of VFAT entries used. Each entry has 13 UTF-16 characters #if ENABLED(SCROLL_LONG_FILENAMES) #define MAX_VFAT_ENTRIES (5) diff --git a/Marlin/src/lcd/malyanlcd.cpp b/Marlin/src/lcd/malyanlcd.cpp index 7c627225e4..a87f3655c0 100644 --- a/Marlin/src/lcd/malyanlcd.cpp +++ b/Marlin/src/lcd/malyanlcd.cpp @@ -75,7 +75,7 @@ int inbound_count; // Everything written needs the high bit set. void write_to_lcd_P(const char * const message) { char encoded_message[MAX_CURLY_COMMAND]; - uint8_t message_length = min(strlen_P(message), sizeof(encoded_message)); + uint8_t message_length = MIN(strlen_P(message), sizeof(encoded_message)); for (uint8_t i = 0; i < message_length; i++) encoded_message[i] = pgm_read_byte(&message[i]) | 0x80; @@ -85,7 +85,7 @@ void write_to_lcd_P(const char * const message) { void write_to_lcd(const char * const message) { char encoded_message[MAX_CURLY_COMMAND]; - const uint8_t message_length = min(strlen(message), sizeof(encoded_message)); + const uint8_t message_length = MIN(strlen(message), sizeof(encoded_message)); for (uint8_t i = 0; i < message_length; i++) encoded_message[i] = message[i] | 0x80; diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index 132d114daf..ba6bdabd4c 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -629,7 +629,7 @@ uint16_t max_display_update_time = 0; screen_changed = false; } if (screen_items > 0 && encoderLine >= screen_items - limit) { - encoderLine = max(0, screen_items - limit); + encoderLine = MAX(0, screen_items - limit); encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); } if (is_menu) { @@ -1579,7 +1579,7 @@ void lcd_quick_feedback(const bool clear_buttons) { * */ void _lcd_preheat(const int16_t endnum, const int16_t temph, const int16_t tempb, const int16_t fan) { - if (temph > 0) thermalManager.setTargetHotend(min(heater_maxtemp[endnum], temph), endnum); + if (temph > 0) thermalManager.setTargetHotend(MIN(heater_maxtemp[endnum], temph), endnum); #if HAS_HEATED_BED if (tempb >= 0) thermalManager.setTargetBed(tempb); #else @@ -2118,7 +2118,7 @@ void lcd_quick_feedback(const bool clear_buttons) { char UBL_LCD_GCODE[16]; const int ind = ubl_height_amount > 0 ? 9 : 10; strcpy_P(UBL_LCD_GCODE, PSTR("G29 P6 C -")); - sprintf_P(&UBL_LCD_GCODE[ind], PSTR(".%i"), abs(ubl_height_amount)); + sprintf_P(&UBL_LCD_GCODE[ind], PSTR(".%i"), ABS(ubl_height_amount)); lcd_enqueue_command(UBL_LCD_GCODE); } @@ -2441,7 +2441,7 @@ void lcd_quick_feedback(const bool clear_buttons) { if (encoderPosition) { step_scaler += (int32_t)encoderPosition; x_plot += step_scaler / (ENCODER_STEPS_PER_MENU_ITEM); - if (abs(step_scaler) >= ENCODER_STEPS_PER_MENU_ITEM) step_scaler = 0; + if (ABS(step_scaler) >= ENCODER_STEPS_PER_MENU_ITEM) step_scaler = 0; encoderPosition = 0; lcdDrawUpdate = LCDVIEW_REDRAW_NOW; } @@ -2853,7 +2853,7 @@ void lcd_quick_feedback(const bool clear_buttons) { do_blocking_move_to_xy(rx, ry); lcd_synchronize(); - move_menu_scale = max(PROBE_MANUALLY_STEP, MIN_STEPS_PER_SEGMENT / float(DEFAULT_XYZ_STEPS_PER_UNIT)); + move_menu_scale = MAX(PROBE_MANUALLY_STEP, MIN_STEPS_PER_SEGMENT / float(DEFAULT_XYZ_STEPS_PER_UNIT)); lcd_goto_screen(lcd_move_z); } @@ -3625,8 +3625,8 @@ void lcd_quick_feedback(const bool clear_buttons) { #define MINTEMP_ALL MIN3(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP) #define MAXTEMP_ALL MAX3(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP) #elif HOTENDS > 1 - #define MINTEMP_ALL min(HEATER_0_MINTEMP, HEATER_1_MINTEMP) - #define MAXTEMP_ALL max(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP) + #define MINTEMP_ALL MIN(HEATER_0_MINTEMP, HEATER_1_MINTEMP) + #define MAXTEMP_ALL MAX(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP) #else #define MINTEMP_ALL HEATER_0_MINTEMP #define MAXTEMP_ALL HEATER_0_MAXTEMP @@ -5229,7 +5229,7 @@ void lcd_update() { #endif - const bool encoderPastThreshold = (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP); + const bool encoderPastThreshold = (ABS(encoderDiff) >= ENCODER_PULSES_PER_STEP); if (encoderPastThreshold || lcd_clicked) { if (encoderPastThreshold) { int32_t encoderMultiplier = 1; @@ -5237,7 +5237,7 @@ void lcd_update() { #if ENABLED(ENCODER_RATE_MULTIPLIER) if (encoderRateMultiplierEnabled) { - int32_t encoderMovementSteps = abs(encoderDiff) / ENCODER_PULSES_PER_STEP; + int32_t encoderMovementSteps = ABS(encoderDiff) / ENCODER_PULSES_PER_STEP; if (lastEncoderMovementMillis) { // Note that the rate is always calculated between two passes through the diff --git a/Marlin/src/lcd/ultralcd_impl_DOGM.h b/Marlin/src/lcd/ultralcd_impl_DOGM.h index e8b4551165..add8e1b07b 100644 --- a/Marlin/src/lcd/ultralcd_impl_DOGM.h +++ b/Marlin/src/lcd/ultralcd_impl_DOGM.h @@ -534,7 +534,7 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ filename[l]; // rotate, xor if (filename_scroll_hash != name_hash) { // If the hash changed... filename_scroll_hash = name_hash; // Save the new hash - filename_scroll_max = max(0, utf8_strlen(longFilename) - maxlen); // Update the scroll limit + filename_scroll_max = MAX(0, utf8_strlen(longFilename) - maxlen); // Update the scroll limit filename_scroll_pos = 0; // Reset scroll to the start lcd_status_update_delay = 8; // Don't scroll right away } diff --git a/Marlin/src/lcd/ultralcd_impl_HD44780.h b/Marlin/src/lcd/ultralcd_impl_HD44780.h index ad514cc7d2..7511d97c65 100644 --- a/Marlin/src/lcd/ultralcd_impl_HD44780.h +++ b/Marlin/src/lcd/ultralcd_impl_HD44780.h @@ -352,12 +352,12 @@ void lcd_implementation_clear() { lcd.clear(); } lcd_put_u8str(text); #else char tmp[LCD_WIDTH + 1] = {0}; - int16_t n = max(utf8_strlen_P(text) - len, 0); + int16_t n = MAX(utf8_strlen_P(text) - len, 0); for (int16_t i = 0; i <= n; i++) { - utf8_strncpy_p(tmp, text + i, min(len, LCD_WIDTH)); + utf8_strncpy_p(tmp, text + i, MIN(len, LCD_WIDTH)); lcd_moveto(col, line); lcd_put_u8str(tmp); - delay(time / max(n, 1)); + delay(time / MAX(n, 1)); } #endif } @@ -875,7 +875,7 @@ static void lcd_implementation_status_screen() { name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ filename[l]; // rotate, xor if (filename_scroll_hash != name_hash) { // If the hash changed... filename_scroll_hash = name_hash; // Save the new hash - filename_scroll_max = max(0, utf8_strlen(longFilename) - n); // Update the scroll limit + filename_scroll_max = MAX(0, utf8_strlen(longFilename) - n); // Update the scroll limit filename_scroll_pos = 0; // Reset scroll to the start lcd_status_update_delay = 8; // Don't scroll right away } @@ -1186,7 +1186,7 @@ static void lcd_implementation_status_screen() { //dump_custom_char("at entry:", &new_char); clear_custom_char(&new_char); - const uint8_t ypix = min(upper_left.y_pixel_offset + pixels_per_y_mesh_pnt, ULTRA_Y_PIXELS_PER_CHAR); + const uint8_t ypix = MIN(upper_left.y_pixel_offset + pixels_per_y_mesh_pnt, ULTRA_Y_PIXELS_PER_CHAR); for (j = upper_left.y_pixel_offset; j < ypix; j++) { i = upper_left.x_pixel_mask; for (k = 0; k < pixels_per_x_mesh_pnt; k++) { diff --git a/Marlin/src/libs/least_squares_fit.cpp b/Marlin/src/libs/least_squares_fit.cpp index 94588a0df5..6d7fc580d8 100644 --- a/Marlin/src/libs/least_squares_fit.cpp +++ b/Marlin/src/libs/least_squares_fit.cpp @@ -58,7 +58,7 @@ int finish_incremental_LSF(struct linear_fit_data *lsf) { lsf->xzbar = lsf->xzbar / N - lsf->xbar * lsf->zbar; const float DD = lsf->x2bar * lsf->y2bar - sq(lsf->xybar); - if (FABS(DD) <= 1e-10 * (lsf->max_absx + lsf->max_absy)) + if (ABS(DD) <= 1e-10 * (lsf->max_absx + lsf->max_absy)) return 1; lsf->A = (lsf->yzbar * lsf->xybar - lsf->xzbar * lsf->y2bar) / DD; diff --git a/Marlin/src/libs/least_squares_fit.h b/Marlin/src/libs/least_squares_fit.h index b45bc23f3d..cbd42d2c6b 100644 --- a/Marlin/src/libs/least_squares_fit.h +++ b/Marlin/src/libs/least_squares_fit.h @@ -63,8 +63,8 @@ void inline incremental_WLSF(struct linear_fit_data *lsf, const float &x, const lsf->xzbar += w * x * z; lsf->yzbar += w * y * z; lsf->N += w; - lsf->max_absx = max(FABS(w * x), lsf->max_absx); - lsf->max_absy = max(FABS(w * y), lsf->max_absy); + lsf->max_absx = MAX(ABS(w * x), lsf->max_absx); + lsf->max_absy = MAX(ABS(w * y), lsf->max_absy); } void inline incremental_LSF(struct linear_fit_data *lsf, const float &x, const float &y, const float &z) { @@ -77,8 +77,8 @@ void inline incremental_LSF(struct linear_fit_data *lsf, const float &x, const f lsf->xybar += x * y; lsf->xzbar += x * z; lsf->yzbar += y * z; - lsf->max_absx = max(FABS(x), lsf->max_absx); - lsf->max_absy = max(FABS(y), lsf->max_absy); + lsf->max_absx = MAX(ABS(x), lsf->max_absx); + lsf->max_absy = MAX(ABS(y), lsf->max_absy); lsf->N += 1.0; } diff --git a/Marlin/src/libs/nozzle.cpp b/Marlin/src/libs/nozzle.cpp index 9d62cf3912..fd845685d8 100644 --- a/Marlin/src/libs/nozzle.cpp +++ b/Marlin/src/libs/nozzle.cpp @@ -79,7 +79,7 @@ do_blocking_move_to(start.x, start.y, start.z); const uint8_t zigs = objects << 1; - const bool horiz = FABS(diffx) >= FABS(diffy); // Do a horizontal wipe? + const bool horiz = ABS(diffx) >= ABS(diffy); // Do a horizontal wipe? const float P = (horiz ? diffx : diffy) / zigs; // Period of each zig / zag const point_t *side; for (uint8_t j = 0; j < strokes; j++) { @@ -172,11 +172,11 @@ break; case 2: // Raise by Z-park height - do_blocking_move_to_z(min(current_position[Z_AXIS] + park.z, Z_MAX_POS), fr_z); + do_blocking_move_to_z(MIN(current_position[Z_AXIS] + park.z, Z_MAX_POS), fr_z); break; default: // Raise to at least the Z-park height - do_blocking_move_to_z(max(park.z, current_position[Z_AXIS]), fr_z); + do_blocking_move_to_z(MAX(park.z, current_position[Z_AXIS]), fr_z); } do_blocking_move_to_xy(park.x, park.y, fr_xy); diff --git a/Marlin/src/module/delta.cpp b/Marlin/src/module/delta.cpp index 1b0e9086fe..352610bbf8 100644 --- a/Marlin/src/module/delta.cpp +++ b/Marlin/src/module/delta.cpp @@ -150,7 +150,7 @@ float delta_safe_distance_from_top() { float centered_extent = delta[A_AXIS]; cartesian[Y_AXIS] = DELTA_PRINTABLE_RADIUS; inverse_kinematics(cartesian); - return FABS(centered_extent - delta[A_AXIS]); + return ABS(centered_extent - delta[A_AXIS]); } /** diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index e9818e776b..ae413d2077 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -552,7 +552,7 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS }, float cartesian_mm = SQRT(sq(xdiff) + sq(ydiff) + sq(zdiff)); // If the move is very short, check the E move distance - if (UNEAR_ZERO(cartesian_mm)) cartesian_mm = FABS(ediff); + if (UNEAR_ZERO(cartesian_mm)) cartesian_mm = ABS(ediff); // No E move either? Game over. if (UNEAR_ZERO(cartesian_mm)) return true; @@ -665,6 +665,7 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS }, const float diff2 = HYPOT2(delta[A_AXIS] - oldA, delta[B_AXIS] - oldB); if (diff2) { planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], rtarget[Z_AXIS], rtarget[E_AXIS], SQRT(diff2) * inverse_secs, active_extruder); + /* SERIAL_ECHOPAIR("final: A=", delta[A_AXIS]); SERIAL_ECHOPAIR(" B=", delta[B_AXIS]); SERIAL_ECHOPAIR(" adiff=", delta[A_AXIS] - oldA); SERIAL_ECHOPAIR(" bdiff=", delta[B_AXIS] - oldB); @@ -710,7 +711,7 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS }, // If the move is very short, check the E move distance // No E move either? Game over. float cartesian_mm = SQRT(sq(xdiff) + sq(ydiff) + sq(zdiff)); - if (UNEAR_ZERO(cartesian_mm)) cartesian_mm = FABS(ediff); + if (UNEAR_ZERO(cartesian_mm)) cartesian_mm = ABS(ediff); if (UNEAR_ZERO(cartesian_mm)) return; // The length divided by the segment size @@ -921,7 +922,7 @@ void prepare_move_to_destination() { } #endif // PREVENT_COLD_EXTRUSION #if ENABLED(PREVENT_LENGTHY_EXTRUDE) - if (FABS(destination[E_AXIS] - current_position[E_AXIS]) * planner.e_factor[active_extruder] > (EXTRUDE_MAXLENGTH)) { + if (ABS(destination[E_AXIS] - current_position[E_AXIS]) * planner.e_factor[active_extruder] > (EXTRUDE_MAXLENGTH)) { current_position[E_AXIS] = destination[E_AXIS]; // Behave as if the move really took place, but ignore E part SERIAL_ECHO_START(); SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP); @@ -1289,7 +1290,7 @@ void homeaxis(const AxisEnum axis) { // When homing Z with probe respect probe clearance const float bump = axis_home_dir * ( #if HOMING_Z_WITH_PROBE - (axis == Z_AXIS && (Z_HOME_BUMP_MM)) ? max(Z_CLEARANCE_BETWEEN_PROBES, Z_HOME_BUMP_MM) : + (axis == Z_AXIS && (Z_HOME_BUMP_MM)) ? MAX(Z_CLEARANCE_BETWEEN_PROBES, Z_HOME_BUMP_MM) : #endif home_bump_mm(axis) ); @@ -1318,7 +1319,7 @@ void homeaxis(const AxisEnum axis) { #if ENABLED(X_DUAL_ENDSTOPS) if (axis == X_AXIS) { const bool lock_x1 = pos_dir ? (endstops.x_endstop_adj > 0) : (endstops.x_endstop_adj < 0); - float adj = FABS(endstops.x_endstop_adj); + float adj = ABS(endstops.x_endstop_adj); if (pos_dir) adj = -adj; if (lock_x1) stepper.set_x_lock(true); else stepper.set_x2_lock(true); do_homing_move(axis, adj); @@ -1329,7 +1330,7 @@ void homeaxis(const AxisEnum axis) { #if ENABLED(Y_DUAL_ENDSTOPS) if (axis == Y_AXIS) { const bool lock_y1 = pos_dir ? (endstops.y_endstop_adj > 0) : (endstops.y_endstop_adj < 0); - float adj = FABS(endstops.y_endstop_adj); + float adj = ABS(endstops.y_endstop_adj); if (pos_dir) adj = -adj; if (lock_y1) stepper.set_y_lock(true); else stepper.set_y2_lock(true); do_homing_move(axis, adj); @@ -1340,7 +1341,7 @@ void homeaxis(const AxisEnum axis) { #if ENABLED(Z_DUAL_ENDSTOPS) if (axis == Z_AXIS) { const bool lock_z1 = pos_dir ? (endstops.z_endstop_adj > 0) : (endstops.z_endstop_adj < 0); - float adj = FABS(endstops.z_endstop_adj); + float adj = ABS(endstops.z_endstop_adj); if (pos_dir) adj = -adj; if (lock_z1) stepper.set_z_lock(true); else stepper.set_z2_lock(true); do_homing_move(axis, adj); @@ -1424,7 +1425,7 @@ void homeaxis(const AxisEnum axis) { if (axis == X_AXIS) { // In Dual X mode hotend_offset[X] is T1's home position - float dual_max_x = max(hotend_offset[X_AXIS][1], X2_MAX_POS); + float dual_max_x = MAX(hotend_offset[X_AXIS][1], X2_MAX_POS); if (active_extruder != 0) { // T1 can move from X2_MIN_POS to X2_MAX_POS or X2 home position (whichever is larger) @@ -1435,7 +1436,7 @@ void homeaxis(const AxisEnum axis) { // In Duplication Mode, T0 can move as far left as X_MIN_POS // but not so far to the right that T1 would move past the end soft_endstop_min[X_AXIS] = base_min_pos(X_AXIS); - soft_endstop_max[X_AXIS] = min(base_max_pos(X_AXIS), dual_max_x - duplicate_extruder_x_offset); + soft_endstop_max[X_AXIS] = MIN(base_max_pos(X_AXIS), dual_max_x - duplicate_extruder_x_offset); } else { // In other modes, T0 can move from X_MIN_POS to X_MAX_POS @@ -1471,7 +1472,7 @@ void homeaxis(const AxisEnum axis) { case X_AXIS: case Y_AXIS: // Get a minimum radius for clamping - soft_endstop_radius = MIN3(FABS(max(soft_endstop_min[X_AXIS], soft_endstop_min[Y_AXIS])), soft_endstop_max[X_AXIS], soft_endstop_max[Y_AXIS]); + soft_endstop_radius = MIN3(ABS(MAX(soft_endstop_min[X_AXIS], soft_endstop_min[Y_AXIS])), soft_endstop_max[X_AXIS], soft_endstop_max[Y_AXIS]); soft_endstop_radius_2 = sq(soft_endstop_radius); break; #endif diff --git a/Marlin/src/module/motion.h b/Marlin/src/module/motion.h index 486677c4d9..2535f07c98 100644 --- a/Marlin/src/module/motion.h +++ b/Marlin/src/module/motion.h @@ -260,7 +260,7 @@ void homeaxis(const AxisEnum axis); // Note: This won't work on SCARA since the probe offset rotates with the arm. inline bool position_is_reachable_by_probe(const float &rx, const float &ry) { return position_is_reachable(rx - (X_PROBE_OFFSET_FROM_EXTRUDER), ry - (Y_PROBE_OFFSET_FROM_EXTRUDER)) - && position_is_reachable(rx, ry, FABS(MIN_PROBE_EDGE)); + && position_is_reachable(rx, ry, ABS(MIN_PROBE_EDGE)); } #endif diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index ac8ae8aaaa..a087ab9517 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -833,7 +833,7 @@ void Planner::reverse_pass_kernel(block_t* const current, const block_t* const n // for max allowable speed if block is decelerating and nominal length is false. const float new_entry_speed = (TEST(current->flag, BLOCK_BIT_NOMINAL_LENGTH) || max_entry_speed <= next->entry_speed) ? max_entry_speed - : min(max_entry_speed, max_allowable_speed(-current->acceleration, next->entry_speed, current->millimeters)); + : MIN(max_entry_speed, max_allowable_speed(-current->acceleration, next->entry_speed, current->millimeters)); if (new_entry_speed != current->entry_speed) { current->entry_speed = new_entry_speed; SBI(current->flag, BLOCK_BIT_RECALCULATE); @@ -859,7 +859,7 @@ void Planner::reverse_pass() { // for max allowable speed if block is decelerating and nominal length is false. const float new_entry_speed = TEST(current->flag, BLOCK_BIT_NOMINAL_LENGTH) ? max_entry_speed - : min(max_entry_speed, max_allowable_speed(-current->acceleration, MINIMUM_PLANNER_SPEED, current->millimeters)); + : MIN(max_entry_speed, max_allowable_speed(-current->acceleration, MINIMUM_PLANNER_SPEED, current->millimeters)); if (current->entry_speed != new_entry_speed) { current->entry_speed = new_entry_speed; SBI(current->flag, BLOCK_BIT_RECALCULATE); @@ -884,7 +884,7 @@ void Planner::forward_pass_kernel(const block_t* const previous, block_t* const // guaranteed to be reached. No need to recheck. if (!TEST(previous->flag, BLOCK_BIT_NOMINAL_LENGTH)) { if (previous->entry_speed < current->entry_speed) { - const float new_entry_speed = min(current->entry_speed, max_allowable_speed(-previous->acceleration, previous->entry_speed, previous->millimeters)); + const float new_entry_speed = MIN(current->entry_speed, max_allowable_speed(-previous->acceleration, previous->entry_speed, previous->millimeters)); // Check for junction speed change if (current->entry_speed != new_entry_speed) { current->entry_speed = new_entry_speed; @@ -1384,7 +1384,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE] } #endif // PREVENT_COLD_EXTRUSION #if ENABLED(PREVENT_LENGTHY_EXTRUDE) - if (labs(de * e_factor[extruder]) > (int32_t)axis_steps_per_mm[E_AXIS_N] * (EXTRUDE_MAXLENGTH)) { // It's not important to get max. extrusion length in a precision < 1mm, so save some cycles and cast to int + if (ABS(de * e_factor[extruder]) > (int32_t)axis_steps_per_mm[E_AXIS_N] * (EXTRUDE_MAXLENGTH)) { // It's not important to get max. extrusion length in a precision < 1mm, so save some cycles and cast to int position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part #if HAS_POSITION_FLOAT position_float[E_AXIS] = target_float[E_AXIS]; @@ -1425,7 +1425,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE] if (de < 0) SBI(dm, E_AXIS); const float esteps_float = de * e_factor[extruder]; - const int32_t esteps = abs(esteps_float) + 0.5; + const int32_t esteps = ABS(esteps_float) + 0.5; // Wait for the next available block uint8_t next_buffer_head; @@ -1440,26 +1440,26 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE] // Number of steps for each axis // See http://www.corexy.com/theory.html #if CORE_IS_XY - block->steps[A_AXIS] = labs(da + db); - block->steps[B_AXIS] = labs(da - db); - block->steps[Z_AXIS] = labs(dc); + block->steps[A_AXIS] = ABS(da + db); + block->steps[B_AXIS] = ABS(da - db); + block->steps[Z_AXIS] = ABS(dc); #elif CORE_IS_XZ - block->steps[A_AXIS] = labs(da + dc); - block->steps[Y_AXIS] = labs(db); - block->steps[C_AXIS] = labs(da - dc); + block->steps[A_AXIS] = ABS(da + dc); + block->steps[Y_AXIS] = ABS(db); + block->steps[C_AXIS] = ABS(da - dc); #elif CORE_IS_YZ - block->steps[X_AXIS] = labs(da); - block->steps[B_AXIS] = labs(db + dc); - block->steps[C_AXIS] = labs(db - dc); + block->steps[X_AXIS] = ABS(da); + block->steps[B_AXIS] = ABS(db + dc); + block->steps[C_AXIS] = ABS(db - dc); #elif IS_SCARA - block->steps[A_AXIS] = labs(da); - block->steps[B_AXIS] = labs(db); - block->steps[Z_AXIS] = labs(dc); + block->steps[A_AXIS] = ABS(da); + block->steps[B_AXIS] = ABS(db); + block->steps[Z_AXIS] = ABS(dc); #else // default non-h-bot planning - block->steps[A_AXIS] = labs(da); - block->steps[B_AXIS] = labs(db); - block->steps[C_AXIS] = labs(dc); + block->steps[A_AXIS] = ABS(da); + block->steps[B_AXIS] = ABS(db); + block->steps[C_AXIS] = ABS(dc); #endif block->steps[E_AXIS] = esteps; @@ -1660,7 +1660,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE] delta_mm[E_AXIS] = esteps_float * steps_to_mm[E_AXIS_N]; if (block->steps[A_AXIS] < MIN_STEPS_PER_SEGMENT && block->steps[B_AXIS] < MIN_STEPS_PER_SEGMENT && block->steps[C_AXIS] < MIN_STEPS_PER_SEGMENT) { - block->millimeters = FABS(delta_mm[E_AXIS]); + block->millimeters = ABS(delta_mm[E_AXIS]); } else if (!millimeters) { block->millimeters = SQRT( @@ -1751,7 +1751,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE] // Calculate and limit speed in mm/sec for each axis float current_speed[NUM_AXIS], speed_factor = 1.0; // factor <1 decreases speed LOOP_XYZE(i) { - const float cs = FABS((current_speed[i] = delta_mm[i] * inverse_secs)); + const float cs = ABS((current_speed[i] = delta_mm[i] * inverse_secs)); #if ENABLED(DISTINCT_E_FACTORS) if (i == E_AXIS) i += extruder; #endif @@ -1789,7 +1789,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE] const uint32_t max_x_segment_time = MAX3(xs0, xs1, xs2), max_y_segment_time = MAX3(ys0, ys1, ys2), - min_xy_segment_time = min(max_x_segment_time, max_y_segment_time); + min_xy_segment_time = MIN(max_x_segment_time, max_y_segment_time); if (min_xy_segment_time < MAX_FREQ_TIME_US) { const float low_sf = speed_factor * min_xy_segment_time / (MAX_FREQ_TIME_US); NOMORE(speed_factor, low_sf); @@ -1973,7 +1973,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE] vmax_junction = MINIMUM_PLANNER_SPEED; } else { - junction_cos_theta = max(junction_cos_theta, -0.999999); // Check for numerical round-off to avoid divide by zero. + junction_cos_theta = MAX(junction_cos_theta, -0.999999); // Check for numerical round-off to avoid divide by zero. const float sin_theta_d2 = SQRT(0.5 * (1.0 - junction_cos_theta)); // Trig half angle identity. Always positive. // TODO: Technically, the acceleration used in calculation needs to be limited by the minimum of the @@ -2003,7 +2003,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE] float safe_speed = block->nominal_speed; uint8_t limited = 0; LOOP_XYZE(i) { - const float jerk = FABS(current_speed[i]), maxj = max_jerk[i]; + const float jerk = ABS(current_speed[i]), maxj = max_jerk[i]; if (jerk > maxj) { if (limited) { const float mjerk = maxj * block->nominal_speed; @@ -2023,7 +2023,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE] // The junction velocity will be shared between successive segments. Limit the junction velocity to their minimum. // Pick the smaller of the nominal speeds. Higher speed shall not be achieved at the junction during coasting. - vmax_junction = min(block->nominal_speed, previous_nominal_speed); + vmax_junction = MIN(block->nominal_speed, previous_nominal_speed); // Factor to multiply the previous / current nominal velocities to get componentwise limited velocities. float v_factor = 1; @@ -2043,9 +2043,9 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE] // Calculate jerk depending on whether the axis is coasting in the same direction or reversing. const float jerk = (v_exit > v_entry) ? // coasting axis reversal - ( (v_entry > 0 || v_exit < 0) ? (v_exit - v_entry) : max(v_exit, -v_entry) ) + ( (v_entry > 0 || v_exit < 0) ? (v_exit - v_entry) : MAX(v_exit, -v_entry) ) : // v_exit <= v_entry coasting axis reversal - ( (v_entry < 0 || v_exit > 0) ? (v_entry - v_exit) : max(-v_exit, v_entry) ); + ( (v_entry < 0 || v_exit > 0) ? (v_entry - v_exit) : MAX(-v_exit, v_entry) ); if (jerk > max_jerk[axis]) { v_factor *= max_jerk[axis] / jerk; @@ -2072,7 +2072,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE] const float v_allowable = max_allowable_speed(-block->acceleration, MINIMUM_PLANNER_SPEED, block->millimeters); // If stepper ISR is disabled, this indicates buffer_segment wants to add a split block. // In this case start with the max. allowed speed to avoid an interrupted first move. - block->entry_speed = STEPPER_ISR_ENABLED() ? MINIMUM_PLANNER_SPEED : min(vmax_junction, v_allowable); + block->entry_speed = STEPPER_ISR_ENABLED() ? MINIMUM_PLANNER_SPEED : MIN(vmax_junction, v_allowable); // Initialize planner efficiency flags // Set flag if block will always reach maximum junction speed regardless of entry/exit speeds. diff --git a/Marlin/src/module/planner.h b/Marlin/src/module/planner.h index e7fe34031b..89a3716305 100644 --- a/Marlin/src/module/planner.h +++ b/Marlin/src/module/planner.h @@ -710,7 +710,7 @@ class Planner { }; -#define PLANNER_XY_FEEDRATE() (min(planner.max_feedrate_mm_s[X_AXIS], planner.max_feedrate_mm_s[Y_AXIS])) +#define PLANNER_XY_FEEDRATE() (MIN(planner.max_feedrate_mm_s[X_AXIS], planner.max_feedrate_mm_s[Y_AXIS])) extern Planner planner; diff --git a/Marlin/src/module/planner_bezier.cpp b/Marlin/src/module/planner_bezier.cpp index 4bba9850b7..bbd1e82625 100644 --- a/Marlin/src/module/planner_bezier.cpp +++ b/Marlin/src/module/planner_bezier.cpp @@ -67,7 +67,7 @@ inline static float eval_bezier(float a, float b, float c, float d, float t) { * We approximate Euclidean distance with the sum of the coordinates * offset (so-called "norm 1"), which is quicker to compute. */ -inline static float dist1(float x1, float y1, float x2, float y2) { return FABS(x1 - x2) + FABS(y1 - y2); } +inline static float dist1(float x1, float y1, float x2, float y2) { return ABS(x1 - x2) + ABS(y1 - y2); } /** * The algorithm for computing the step is loosely based on the one in Kig diff --git a/Marlin/src/module/probe.cpp b/Marlin/src/module/probe.cpp index 7f95d7cb1e..3ffdb29e0b 100644 --- a/Marlin/src/module/probe.cpp +++ b/Marlin/src/module/probe.cpp @@ -392,7 +392,7 @@ bool set_probe_deployed(const bool deploy) { #endif if (deploy_stow_condition && unknown_condition) - do_probe_raise(max(Z_CLEARANCE_BETWEEN_PROBES, Z_CLEARANCE_DEPLOY_PROBE)); + do_probe_raise(MAX(Z_CLEARANCE_BETWEEN_PROBES, Z_CLEARANCE_DEPLOY_PROBE)); #if ENABLED(Z_PROBE_SLED) || ENABLED(Z_PROBE_ALLEN_KEY) #if ENABLED(Z_PROBE_SLED) @@ -672,7 +672,7 @@ float probe_pt(const float &rx, const float &ry, const ProbePtRaise raise_after/ const float nz = #if ENABLED(DELTA) // Move below clip height or xy move will be aborted by do_blocking_move_to - min(current_position[Z_AXIS], delta_clip_start_height) + MIN(current_position[Z_AXIS], delta_clip_start_height) #else current_position[Z_AXIS] #endif diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 1b584ce065..4cbcf791dc 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -811,8 +811,8 @@ void Temperature::manage_heater() { updateTemperaturesFromRawValues(); // also resets the watchdog #if ENABLED(HEATER_0_USES_MAX6675) - if (current_temperature[0] > min(HEATER_0_MAXTEMP, MAX6675_TMAX - 1.0)) max_temp_error(0); - if (current_temperature[0] < max(HEATER_0_MINTEMP, MAX6675_TMIN + .01)) min_temp_error(0); + if (current_temperature[0] > MIN(HEATER_0_MAXTEMP, MAX6675_TMAX - 1.0)) max_temp_error(0); + if (current_temperature[0] < MAX(HEATER_0_MINTEMP, MAX6675_TMIN + .01)) min_temp_error(0); #endif #if WATCH_HOTENDS || WATCH_THE_BED || DISABLED(PIDTEMPBED) || HAS_AUTO_FAN || HEATER_IDLE_HANDLER @@ -845,7 +845,7 @@ void Temperature::manage_heater() { #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT) // Make sure measured temperatures are close together - if (FABS(current_temperature[0] - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF) + if (ABS(current_temperature[0] - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF) _temp_error(0, PSTR(MSG_REDUNDANCY), PSTR(MSG_ERR_REDUNDANT_TEMP)); #endif @@ -1097,7 +1097,7 @@ void Temperature::updateTemperaturesFromRawValues() { * a return value of 1. */ int8_t Temperature::widthFil_to_size_ratio() { - if (FABS(filament_width_nominal - filament_width_meas) <= FILWIDTH_ERROR_MARGIN) + if (ABS(filament_width_nominal - filament_width_meas) <= FILWIDTH_ERROR_MARGIN) return int(100.0 * filament_width_nominal / filament_width_meas) - 100; return 0; } diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h index b3e4e3cffd..f6637d03ea 100644 --- a/Marlin/src/module/temperature.h +++ b/Marlin/src/module/temperature.h @@ -91,7 +91,7 @@ enum ADCSensorState : char { // get all oversampled sensor readings #define MIN_ADC_ISR_LOOPS 10 -#define ACTUAL_ADC_SAMPLES max(int(MIN_ADC_ISR_LOOPS), int(SensorsReady)) +#define ACTUAL_ADC_SAMPLES MAX(int(MIN_ADC_ISR_LOOPS), int(SensorsReady)) #if HAS_PID_HEATING #define PID_K2 (1.0-PID_K1) @@ -440,7 +440,7 @@ class Temperature { #endif target_temperature_bed = #ifdef BED_MAXTEMP - min(celsius, BED_MAXTEMP) + MIN(celsius, BED_MAXTEMP) #else celsius #endif @@ -463,7 +463,7 @@ class Temperature { #endif FORCE_INLINE static bool wait_for_heating(const uint8_t e) { - return degTargetHotend(e) > TEMP_HYSTERESIS && abs(degHotend(e) - degTargetHotend(e)) > TEMP_HYSTERESIS; + return degTargetHotend(e) > TEMP_HYSTERESIS && ABS(degHotend(e) - degTargetHotend(e)) > TEMP_HYSTERESIS; } /**