Discussion: comparison
Afficher un message
Vieux 21/10/2007, 11h46   #4
Charlie Gordon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: comparison

"Martin Ambuhl" <mambuhl@earthlink.net> a écrit dans le message de news:
5o0ngiFkk1juU1@mid.individual.net...
> ndun78@gmail.com wrote:
>> I want to write something like
>> status_bit = (unsigned)(i - j) >> 31
>>
>> as an equivalent code for
>> if(i < j){
>> {
>> status_bit = 1;
>> }else{
>> status_bit = 0;
>> }

>
> Try the simple
> status_bit = (i < j);
>
>> This actually works for most of the cases but fails for two values
>> i = 0x80000000
>> j = 0x7fffffff
>>
>> I want a linear code for the above i.e. without jumps, so
>> 1. what could be the issue?
>> 2. what could be the solution?

>
> Is there a reason for avoiding the obvious
> status_bit = (i < j);


In other words: if there is a way to compute this without tests and jumps,
the compiler should know.

--
Chqrlie.


  Réponse avec citation
 
Page generated in 0,04576 seconds with 9 queries