Bit-shifting
- Posted by Robert Craig <robert_craig at COMPUSERVE.COM> May 04, 1997
- 841 views
Pete Eberlein writes: > I would much rather be able to > integer SHR 1 -- shift right > integer SAR 1 -- shift arithmetic right (keeps the sign) > instead of using > floor(integer / 2) Thanks for the suggestions about shift operators. Maybe some day. But I just want to point out that Euphoria already optimizes floor(integer/2) into a single right-shift machine instruction (plus a few instructions of overhead needed by any interpretive language). In general, floor(integer1/integer2) does NOT use a floating-point divide instruction. It performs a machine-level integer divide. The compiler portion of Euphoria is smart enough to see that divide of 2 integers is followed immediately by floor, so it generates an intermediate-language op-code that performs a machine-level integer divide, and then there's no need for a separate "floor" operation at all. Regards, Rob Craig Rapid Deployment Software