TP/BP 7.01 shift bug?
Author Message
TP/BP 7.01 shift bug?

In TP 7 (7.01??) and BP 7.01, with

var n : longint; shift : integer;

this executes correctly:

shift := ((n and 63) - 1) shr 1;
if odd( BitVector[ n shr 6] shr shift) then

but this doesn't:

if odd( BitVector[ n shr 6] shr ((n and 63) - 1) shr 1) then

I thought that the bug with shifting a longint was fixed in
version 7.01.  I tried this with TP and BP 7.01.  What's the
problem?

Jud McCranie

Wed, 18 Jun 1902 08:00:00 GMT
TP/BP 7.01 shift bug?
On Wed, 19 Jan 2000 00:14:11 -0500, Jud McCranie

Quote:

> In TP 7 (7.01??) and BP 7.01, with

> var n : longint; shift : integer;

> this executes correctly:

>  shift := ((n and 63) - 1) shr 1;
>  if odd( BitVector[ n shr 6] shr shift) then

> but this doesn't:

>  if odd( BitVector[ n shr 6] shr ((n and 63) - 1) shr 1) then

> I thought that the bug with shifting a longint was fixed in
> version 7.01.  I tried this with TP and BP 7.01.  What's the
> problem?

A missing pair of parens. Shift operators are not associative and
binary operators with the same precedence are left associative.

A SHR B SHR C

means

(A SHR B) SHR C

and not

A SHR ( B SHR C)

You should write

if odd( BitVector[ n shr 6] shr (((n and 63) - 1) shr 1) ) then

if odd( BitVector[ n shr 6] shr ((n and 63) - 1) shr 1 ) then

Regards
Horst

Wed, 18 Jun 1902 08:00:00 GMT
TP/BP 7.01 shift bug?

Quote:

> In TP 7 (7.01??) and BP 7.01, with

> var n : longint; shift : integer;

> this executes correctly:

>  shift := ((n and 63) - 1) shr 1;
>  if odd( BitVector[ n shr 6] shr shift) then

> but this doesn't:

>  if odd( BitVector[ n shr 6] shr ((n and 63) - 1) shr 1) then

> I thought that the bug with shifting a longint was fixed in
> version 7.01.  I tried this with TP and BP 7.01.

> What's the problem?

Exactly, _what is the problem?_

Robert
--
Robert AH Prins

Sent via Deja.com http://www.deja.com/

Wed, 18 Jun 1902 08:00:00 GMT
TP/BP 7.01 shift bug?

Quote:

>A missing pair of parens. Shift operators are not associative and
>binary operators with the same precedence are left associative.

Whoops!  You're right, my mistake.  (It was late at night when I
did that.)
Jud McCranie

Wed, 18 Jun 1902 08:00:00 GMT
TP/BP 7.01 shift bug?
Hi !

Quote:

> In TP 7 (7.01??) and BP 7.01, with
> var n : longint; shift : integer;
> this executes correctly:
>  shift := ((n and 63) - 1) shr 1;
>  if odd( BitVector[ n shr 6] shr shift) then
> but this doesn't:

I would say that you forgot a bracket in the following line and so the
expression is not calculated exactly !
It should be like this

Quote:
>  if odd( BitVector[ n shr 6] shr ((n and 63) - 1) shr 1 ) ) then

^^^

I think that should be all.

Quote:
> I thought that the bug with shifting a longint was fixed in
> version 7.01.  I tried this with TP and BP 7.01.  What's the
> problem?
> Jud McCranie

Hope it helps !
Toralf

Wed, 18 Jun 1902 08:00:00 GMT
TP/BP 7.01 shift bug?

Quote:

>I would say that you forgot a bracket in the following line and so the
>expression is not calculated exactly !

You're right.  It was late at night, and when I tried to
optimize by putting the variable inline, I didn't do it right,
and when it didn't work, I assumed that it was something related
to the old longint shift bug.

Jud McCranie

Wed, 18 Jun 1902 08:00:00 GMT

 Page 1 of 1 [ 6 post ]

Relevant Pages
 5. BP 7.01