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

[REBOL] Re: Arithmetic shifts

From: tomc:darkwing:uoregon at: 17-Aug-2004 2:03

On Tue, 17 Aug 2004, Carl Read wrote:
> >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! > > > >I suspect this has speed advantages too, though I've not done any tests. > > Have now and indeed it does... > > >> t: now/time/precise loop 1000000 [2 / 2]print now/time/precise - t > 0:00:00.93 > >> t: now/time/precise loop 1000000 [2 / 2]print now/time/precise - t > 0:00:00.94 > >> t: now/time/precise loop 1000000 [2 / 2]print now/time/precise - t > 0:00:00.94 > >> t: now/time/precise loop 1000000 [3 / 2]print now/time/precise - t > 0:00:01.43 > >> t: now/time/precise loop 1000000 [3 / 2]print now/time/precise - t > 0:00:01.43 > >> t: now/time/precise loop 1000000 [3 / 2]print now/time/precise - t > 0:00:01.37 > > And using AND's quicker than TO INTEGER! too... > > >> t: now/time/precise loop 1000000 [3 and 254 / 2]print now/time/precise - t > 0:00:01.59 > >> t: now/time/precise loop 1000000 [3 and 254 / 2]print now/time/precise - t > 0:00:01.59 > >> t: now/time/precise loop 1000000 [3 and 254 / 2]print now/time/precise - t > 0:00:01.54 > >> t: now/time/precise loop 1000000 [to integer! 3 / 2]print now/time/precise - t > 0:00:02.85 > >> t: now/time/precise loop 1000000 [to integer! 3 / 2]print now/time/precise - t > 0:00:02.86 > >> t: now/time/precise loop 1000000 [to integer! 3 / 2]print now/time/precise - t > 0:00:02.8 > > -- Carl Read
it may be faster but what results are you getting? I see things like
>> 1 and 3 / 2
== 0.5 and it does not fill me with confidence that you are doing what you hope to be doing, precedence is left to right so what you may be seeing is
>> 3 and 254
== 2
>> 2 / 2
== 1
>> 3 and 255 / 2
== 1.5