diff --git a/Marlin/src/core/serial_base.h b/Marlin/src/core/serial_base.h index a8700f3d23..07bed55b35 100644 --- a/Marlin/src/core/serial_base.h +++ b/Marlin/src/core/serial_base.h @@ -228,7 +228,7 @@ struct SerialBase { // Handle negative numbers if (number < 0.0) { write('-'); - number = -number; + number *= -1; } // Round correctly so that print(1.999, 2) prints as "2.00" diff --git a/Marlin/src/gcode/calibrate/G34_M422.cpp b/Marlin/src/gcode/calibrate/G34_M422.cpp index 1ac58cc894..6c367ad882 100644 --- a/Marlin/src/gcode/calibrate/G34_M422.cpp +++ b/Marlin/src/gcode/calibrate/G34_M422.cpp @@ -390,7 +390,7 @@ void GcodeSuite::G34() { // Decreasing accuracy was detected so move was inverted. // Will match reversed Z steppers on dual steppers. Triple will need more work to map. if (adjustment_reverse) { - z_align_move = -z_align_move; + z_align_move *= -1; if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> Z", zstepper + 1, " correction reversed to ", z_align_move); } #endif diff --git a/Marlin/src/lcd/extui/dgus/fysetc/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/dgus/fysetc/DGUSScreenHandler.cpp index be0e60a8df..f4c7db544b 100644 --- a/Marlin/src/lcd/extui/dgus/fysetc/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/dgus/fysetc/DGUSScreenHandler.cpp @@ -205,7 +205,7 @@ void DGUSScreenHandler::handleManualMove(DGUS_VP_Variable &var, void *val_ptr) { const uint16_t backup_speed = MMS_TO_MMM(feedrate_mm_s); char sign[] = "\0"; int16_t value = movevalue / 100; - if (movevalue < 0) { value = -value; sign[0] = '-'; } + if (movevalue < 0) { value *= -1; sign[0] = '-'; } int16_t fraction = ABS(movevalue) % 100; snprintf_P(buf, 32, PSTR("G0 %c%s%d.%02d F%d"), axiscode, sign, value, fraction, speed); queue.enqueue_one_now(buf); diff --git a/Marlin/src/lcd/extui/dgus/hiprecy/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/dgus/hiprecy/DGUSScreenHandler.cpp index 297c71f8a9..a62d3a2ffc 100644 --- a/Marlin/src/lcd/extui/dgus/hiprecy/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/dgus/hiprecy/DGUSScreenHandler.cpp @@ -207,7 +207,7 @@ void DGUSScreenHandler::handleManualMove(DGUS_VP_Variable &var, void *val_ptr) { const uint16_t backup_speed = MMS_TO_MMM(feedrate_mm_s); char sign[] = "\0"; int16_t value = movevalue / 100; - if (movevalue < 0) { value = -value; sign[0] = '-'; } + if (movevalue < 0) { value *= -1; sign[0] = '-'; } int16_t fraction = ABS(movevalue) % 100; snprintf_P(buf, 32, PSTR("G0 %c%s%d.%02d F%d"), axiscode, sign, value, fraction, speed); queue.enqueue_one_now(buf); diff --git a/Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp index 010e1be381..2965d75da3 100644 --- a/Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp @@ -778,7 +778,7 @@ void DGUSScreenHandler::handleManualMove(DGUS_VP_Variable &var, void *val_ptr) { char buf[32]; // G1 X9999.99 F12345 char sign[] = "\0"; int16_t value = movevalue / 100; - if (movevalue < 0) { value = -value; sign[0] = '-'; } + if (movevalue < 0) { value *= -1; sign[0] = '-'; } const int16_t fraction = ABS(movevalue) % 100; snprintf_P(buf, 32, PSTR("G0 %c%s%d.%02d F%d"), axiscode, sign, value, fraction, speed); queue.enqueue_one_now(buf); diff --git a/Marlin/src/lcd/extui/dgus/origin/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/dgus/origin/DGUSScreenHandler.cpp index 0afc8a25ad..ac73c8cf65 100644 --- a/Marlin/src/lcd/extui/dgus/origin/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/dgus/origin/DGUSScreenHandler.cpp @@ -207,7 +207,7 @@ void DGUSScreenHandler::handleManualMove(DGUS_VP_Variable &var, void *val_ptr) { const uint16_t backup_speed = MMS_TO_MMM(feedrate_mm_s); char sign[] = "\0"; int16_t value = movevalue / 100; - if (movevalue < 0) { value = -value; sign[0] = '-'; } + if (movevalue < 0) { value *= -1; sign[0] = '-'; } int16_t fraction = ABS(movevalue) % 100; snprintf_P(buf, 32, PSTR("G0 %c%s%d.%02d F%d"), axiscode, sign, value, fraction, speed); queue.enqueue_one_now(buf); diff --git a/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp b/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp index e195654caa..6b2caadba0 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp +++ b/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp @@ -676,11 +676,11 @@ void DGUSRxHandler::moveStep(DGUS_VP &vp, void *data_ptr) { switch (direction) { default: return; - case DGUS_Data::MoveDirection::XM: offset = -offset; + case DGUS_Data::MoveDirection::XM: offset *= -1; case DGUS_Data::MoveDirection::XP: axis = ExtUI::X; break; - case DGUS_Data::MoveDirection::YM: offset = -offset; + case DGUS_Data::MoveDirection::YM: offset *= -1; case DGUS_Data::MoveDirection::YP: axis = ExtUI::Y; break; - case DGUS_Data::MoveDirection::ZM: offset = -offset; + case DGUS_Data::MoveDirection::ZM: offset *= -1; case DGUS_Data::MoveDirection::ZP: axis = ExtUI::Z; break; } diff --git a/Marlin/src/lcd/menu/game/brickout.cpp b/Marlin/src/lcd/menu/game/brickout.cpp index 061e4e89c8..7b596a156f 100644 --- a/Marlin/src/lcd/menu/game/brickout.cpp +++ b/Marlin/src/lcd/menu/game/brickout.cpp @@ -53,7 +53,7 @@ void reset_ball() { bdat.ballv = FTOF(1.3f); bdat.ballh = -FTOF(1.25f); uint8_t bx = bdat.paddle_x + (PADDLE_W) / 2 + ball_dist; - if (bx >= GAME_WIDTH - 10) { bx -= ball_dist * 2; bdat.ballh = -bdat.ballh; } + if (bx >= GAME_WIDTH - 10) { bx -= ball_dist * 2; bdat.ballh *= -1; } bdat.ballx = BTOF(bx); bdat.hit_dir = -1; } @@ -71,10 +71,10 @@ void BrickoutGame::game_screen() { // Provisionally update the ball position const fixed_t newx = bdat.ballx + bdat.ballh, newy = bdat.bally + bdat.ballv; // current next position if (!WITHIN(newx, 0, BTOF(GAME_WIDTH - 1))) { // out in x? - bdat.ballh = -bdat.ballh; _BUZZ(5, 220); // bounce x + bdat.ballh *= -1; _BUZZ(5, 220); // bounce x } if (newy < 0) { // out in y? - bdat.ballv = -bdat.ballv; _BUZZ(5, 280); // bounce v + bdat.ballv *= -1; _BUZZ(5, 280); // bounce v bdat.hit_dir = 1; } // Did the ball go below the bottom? @@ -96,8 +96,8 @@ void BrickoutGame::game_screen() { // If bricks are gone, go to reset state if (!--bdat.brick_count) game_state = 2; // Bounce the ball cleverly - if ((bdat.ballv < 0) == (bdat.hit_dir < 0)) { bdat.ballv = -bdat.ballv; bdat.ballh += fixed_t(random(-16, 16)); _BUZZ(5, 880); } - else { bdat.ballh = -bdat.ballh; bdat.ballv += fixed_t(random(-16, 16)); _BUZZ(5, 640); } + if ((bdat.ballv < 0) == (bdat.hit_dir < 0)) { bdat.ballv *= -1; bdat.ballh += fixed_t(random(-16, 16)); _BUZZ(5, 880); } + else { bdat.ballh *= -1; bdat.ballv += fixed_t(random(-16, 16)); _BUZZ(5, 640); } } } // Is the ball moving down and in paddle range? @@ -107,13 +107,13 @@ void BrickoutGame::game_screen() { if (WITHIN(diff, 0, PADDLE_W - 1)) { // Reverse Y direction - bdat.ballv = -bdat.ballv; _BUZZ(3, 880); + bdat.ballv *= -1; _BUZZ(3, 880); bdat.hit_dir = -1; // Near edges affects X velocity const bool is_left_edge = (diff <= 1); if (is_left_edge || diff >= PADDLE_W-1 - 1) { - if ((bdat.ballh > 0) == is_left_edge) bdat.ballh = -bdat.ballh; + if ((bdat.ballh > 0) == is_left_edge) bdat.ballh *= -1; } else if (diff <= 3) { bdat.ballh += fixed_t(random(-64, 0)); diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index 6be58e7bb5..cc0401cc6c 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -2515,7 +2515,7 @@ hal_timer_t Stepper::block_phase_isr() { if (forward_e != motor_direction(E_AXIS)) { last_direction_bits.toggle(E_AXIS); - count_direction.e = -count_direction.e; + count_direction.e *= -1; DIR_WAIT_BEFORE(); @@ -2876,7 +2876,7 @@ hal_timer_t Stepper::block_phase_isr() { la_interval = calc_timer_interval(uint32_t(ABS(step_rate))); if (forward_e != motor_direction(E_AXIS)) { last_direction_bits.toggle(E_AXIS); - count_direction.e = -count_direction.e; + count_direction.e *= -1; DIR_WAIT_BEFORE(); E_APPLY_DIR(forward_e, false); TERN_(FT_MOTION, last_set_direction = last_direction_bits);