Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Arithmetic shifts

From: jacereda::users::sourceforge::net at: 17-Aug-2004 11:56

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