Page 1 of 1

### Stack effect is inverted - what does that mean?

Posted: 04 Mar 2017 06:34
In the documentation for bitLeft and bitRight, a precaution mentioning to be careful due to Oforth's stack effect to invert an integer (method of
integer). If I understand the precaution correctly, would that mean that the maximum positive number on the stack if incremented by 1 will result in a negative number?

If that's so, then bit shifting has to have the result checked for whether the most significant bit has been toggled from 0 to 1 then, right?

Is there a way to verify the maximum number of bits a particular processor is capable of handling?

Bob

### Re: Stack effect is inverted - what does that mean?

Posted: 06 Mar 2017 12:13
Hello,

No, this is not related to negative results, this is only related to the order of the 2 objects on the stack (the number to shift and the number of shift to do).

#bitLeft and #bitRight are methods of the Integer class.
The top of the stack is the integer we want to shift, not the number of shift to do.
So #bitLeft (and #bitRight) stack effects is :

bitLeft \ n x1 -- x2 : Logical shift of n bits on x1 giving x2

You can write :
Code: Select all
`0x000000111111 bitLeft( 24 )24 0x000000111111 bitLeft0xFFFFFF111111 bitRight( 24 )24 0xFFFFFF111111 bitRight`

There is a warning into the documentation because this is not the way the classical Forth words LSHIFT and RSHIFT work :

LSHIFT \ x1 n -- x2 : Logical shift of n bits on x1 giving x2.

This is not the same order in Oforth.

Franck