Largest Value revisited 
Author Message
 Largest Value revisited

Shouldn't the following work on but one and two complement machines:

#define MAXLONG ((~(unsigned long) 0) >> 1)

Given that we know this works fine on two complement machines, all I
need to show is that it works fine for ones complement machines.

So, the unsigned long would change the zero into an unsigned value.
The ~ would then subtract that value from the largest possible
unsigned number which would give us all 1s (this definition is from
K&R2's reference section).  Now since there is no conversion to
unsigned, all the bits will still be on for the right shift one.  The
signed conversion, if any, would happen after all the shifting is
done.  This should give us the largest signed value, given how one's
complement machines work.

So, is this reasonable, or is there something subtle that I'm missing
here?

Warner

P.S.  If this was in another part of the thread and I missed it, sorry
for covering old ground.
--

"Red hair is caused by sugar and lust," the woman, who was blond, confided.
"Highly evolved beings do not indulge in sugar and lust." -- Tom Robbins



Wed, 23 Mar 1994 15:40:10 GMT  
 Largest Value revisited
Ugg. 'C' didn't work.


Quote:
(Warner Losh) writes: (hey that's me)

[...]
Quote:
>Now since there is no conversion to unsigned, [...]

                                  ^^^^^^^^^^^
This should read "from unsigned to signed."

Warner
--

"Red hair is caused by sugar and lust," the woman, who was blond, confided.
"Highly evolved beings do not indulge in sugar and lust." -- Tom Robbins



Wed, 23 Mar 1994 15:50:57 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Largest double value ...

2. How C Handle Value Larger than 32 bit?

3. Largest Value of Integer

4. Value too large for defined data type

5. very large integer values

6. Setting Large (Binary) values in Registry

7. Setting large binary values in registry using RegSetValueEx

8. Formatting for large values

9. GetTextExtent() returning too large a value?

10. Value, value, who's got the value?

11. Exceptions revisited

12. String library revisited...

 

 
Powered by phpBB® Forum Software