From: Ken Bloom Date: 2006-10-26T13:05:05+09:00 Subject: Re: simple math question On Thu, 26 Oct 2006 01:19:08 +0000, Jeffrey Schwab wrote: > Paul Lutus wrote: >> Brad Tilley wrote: >> >>> Thanks for all the examples guys! Being Ruby, I thought there might be >>> some super simple method that just magically did this. I'll stick with >>> the old-fashioned modulo test. >> >> If speed matters, the modulo test is way slower than testing the LSB. > > Do you mean on a specific architecture, or is there a Ruby-specific > reason for one to be slower than the other? Modulo uses division hardware, which is slower than the hardware for bitwise operations. Most C compilers know how to optimize this sort of thing when it's known in advance that you're doing mod 2. I doubt Ruby's that smart. --Ken -- Ken Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/ I've added a signing subkey to my GPG key. Please update your keyring.