For Programmers: Free Programming Magazines  


Home > Archive > Fortran > December 2005 > Re: Kind of NOT integer constant









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Kind of NOT integer constant
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


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com