On 17/08/2004, at 9:43, Carl Read wrote:

>
>> Hi Jorge,
>>
>> JAM> How can I perform an arithmetic shift (or a floored division) in
>> JAM> REBOL?
>>
>> to integer! value / radix
>
> Note that to-integer (or to integer!) isn't always required to return 
> an integer with division...
>
>>> type? 3 / 2
> == decimal!
>>> type? 4 / 2
> == integer!
>>> type? 12 / 4
> == integer!
>
> Which also allows us to do the likes of this...
>
>>> x: 5 and 254 / 2
> == 2
>>> type? x
> == integer!
>

The to-integer approach seems invalid for my purposes, but this one 
seems correct:

fdiv: func[n1 [integer!] n2 [integer!]][
        n1 and (negate n2) / n2 ]

ashift: func [n [integer!] amount [integer!]][
        fdiv n to-integer (2 ** amount)]

ashift -1 10
== -1

Thanks to all for your responses.
   Jorge Acereda


-- 
To unsubscribe from the list, just send an email to rebol-request
at rebol.com with unsubscribe as the subject.

Reply via email to