| glen herrmannsfeldt 2005-12-18, 7:01 pm |
| robin wrote:
> "Steven G. Kargl" <kargl@troutmask.apl.washington.edu> wrote in message
> news:dnvhla$rnb$1@gnus01.u.washington.edu...
(snip)
> NOT(0) returns an integer having all bits set.
(snip)
> The returned value is -1 on a machine that represents negative numbers
> in twos complement form.
> [on a machine that represents negative numbers in ones complement
> form, the value is -0]
What does a ones complement machine do when extending an integer?
I believe that sign extension is still the right thing to do, though
for negative zero it might be legal to generate a positive zero.
That would not work very well for NOT.
> PROGRAM TEST
> IMPLICIT NONE
> INTEGER, PARAMETER :: W8 = SELECTED_INT_KIND (1)
> INTEGER, PARAMETER :: W16 = SELECTED_INT_KIND (3)
> INTEGER (KIND=W8) :: I = 0
> INTEGER (KIND=W16) :: J = 0
>
> PRINT *, BIT_SIZE(I), BIT_SIZE(J), BIT_SIZE(0)
> PRINT *, BIT_SIZE(NOT(I)), BIT_SIZE(NOT(J)), BIT_SIZE(NOT(0))
> PRINT *, NOT(I), NOT(J), NOT(0)
> END PROGRAM TEST
>
> 8 16 32
> 8 16 32
> -1 -1 -1
That is interesting. In C, all three would be 32 bits after
applying ~ (on a machine with a 32 bit int), though applying ~ to
a 64 bit int would result in a 64 bit int. C pretty much doesn't
do any operation on data smaller than int without extending it first,
which is also how many machines work.
-- glen
|