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

instead of

    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/
Before you buy.



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  
 
 [ 6 post ] 

 Relevant Pages 

1. Is there a 7.01 update for BP/TP or did I dream it

2. TP 7.0 & BP 7.01

3. BP 7.0 shift bug

4. TP 7 vs. TP 7.01

5. BP 7.01

6. BP 7.01 TSR's.

7. BP 7.01: RTL?

8. BP 7.01 Update Disk

9. BP with Objects 7.0 vs 7.01

10. Re. BP with Objects 7.0 vs. 7.01

11. BP 7.01 Patch

12. BP 7.01 Patch

 

 
Powered by phpBB® Forum Software