Are these statements functionally equivalent ?

mip->atmin = (newpos <= mip->min);
if (mip->atmin)
newpos = mip->min;

``````if (newpos <= mip->min)
{
mip->atmin = true;
}
else
{
mip->atmin = false;
}
if (mip->atmin)
newpos = mip->min;
``````

And:

mip->atmax = (newpos >= mip->max);
if (mip->atmax)
newpos = mip->max;

``````if (newpos >= mip->max)
{
mip->atmax = true;
}
else
{
mip->atmax = false;
}
if (mip->atmax)
newpos = mip->max;
``````

Yes

They are similar indeed, If you go for the if else version you can save one test though

``````if (newpos >= mip->max)
{
mip->atmax = true;
newpos = mip->max;
}
else
{
mip->atmax = false;
}
``````

Or go for ternary operator but it’s convoluted / less readable.

J-M-L:
They are similar indeed, If you go for the if else version you can save one test though

``````if (newpos >= mip->max)
``````

{
mip->atmax = true;
newpos = mip->max;
}
else
{
mip->atmax = false;
}

``````

Or go for ternary operator but it’s convoluted / less readable.
``````

Thank you so much J-M-L, there is beauty in this simplicity.
As opposed to a previous poster that liked to try and jam all functions into one long, convoluted statement.
Have pity please, on those that might have to come after you.

You could also do both limits with the Arduino 'constrain()' function:

``````      newpos = constrian(newpos, mip->min, mip->max);
mip->atmin = newpos == mip->min;
mip->atmax = newpos == mip->max;
``````