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 <ejtagle@hotmail.com>
This commit is contained in:
Scott Lahteine
2018-05-13 01:10:34 -05:00
parent 083ec9963e
commit 99ecdf59af
52 changed files with 206 additions and 247 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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);