COMP: specie - ensure if block is evaluated

This commit is contained in:
Andrew Heather
2017-05-18 22:12:48 +01:00
parent 0a4733acab
commit 62ff00f860

View File

@ -159,14 +159,17 @@ inline specie operator==(const specie& st1, const specie& st2)
diffY = SMALL;
}
const scalar diffRW =
st2.Y_/st2.molWeight_ - st1.Y_/st1.molWeight_;
const scalar diffRW = st2.Y_/st2.molWeight_ - st1.Y_/st1.molWeight_;
scalar molWeight = GREAT;
if (mag(diffRW) > SMALL)
{
molWeight = diffY/diffRW;
}
// if (mag(diffRW) > SMALL)
// {
// molWeight = diffY/diffRW;
// }
// Using intermediate volatile bool to prevent compiler optimising out the
// if block (above) - CLANG 3.7.1
volatile const bool valid = (mag(diffRW) > SMALL);
const scalar molWeight = valid ? diffY/diffRW : GREAT;
return specie(diffY, molWeight);
}