jeudi 6 septembre 2018

How to change the boolean value of false to "-1" instead of "0"?

My intention is to avoid if-else conditions completely. But I am currently unable to perform it because boolean false is always 0.

if(temp > 0) {
    temp = -temp;
    temp >> 10;
    temp = -temp;
}
else {
    temp >> 10;
}

this above code, I would wish to replace it with the below code: `

bool result = temp > 0;
temp = result * temp;
temp >> 10;
temp = result * temp;

this code fails when temp is less than 0, because in that scenario, result is 0 (but not -1) and consequently, temp will become 0.

Aucun commentaire:

Enregistrer un commentaire