----- Original Message ----- From: "Sacha Chua" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, February 08, 2002 12:04 AM Subject: Re: [plug] Re: [OT] bitwise operations with perl
> On 07 Feb, Rowel Atienza ([EMAIL PROTECTED]) said: > > > > i know this has already been way off topic :) but exponentiation with an > > > integer exponent and base 2 is easier done by having bit shifts << > > but bit shift << consumes much less cpu cycles than > > exponentiation of 2 to an int. > > That is true, especially since exponentiation in this case involves not > only multiplication but also floating point operations. Even optimized > exponentiations are more expensive than bit shifts - if only because bit > shifts are really easy to do in hardware and have their own opcodes > already, while exponentiation requires some multiplication... > > (See, I knew that computer architecture class would come in handy...) > > Lies, damned lies, and statistics. ;) let me add to this sacha... if you are electrical, electronics, ece or computer engineer, you know how bits work on electricity especially on the logical gates circuit which doing all the arithmetic job... it takes a little circuit operation doing shifting bits than exponentiation which causes less cpu cycles or clock ticks... exponentiation is a floating point operation but still doing it on an integer calculation because real data type format is 1 bit for signed mantissa, 1 bit for signed exponent, N bits for mantissa and N bits for exponent.. the value of N depending on what real data type you are going to use.. the longer the N bits used, the more clock ticks consume (eg. in C, double data type takes more clock ticks to operate than float data type but have a higher precision). but if you are a computer scientist and dont know how bits work on a circuit, all you have to do is to look for an assembly/machine language book and find a table their that how many clock ticks does it consume for a given opcode... and you will find their that for i386 machine language for example, SHL and SHR takes N times faster than using mathco opcode EXP or LN. but for perl, all numeric data types are in floating point data type and there is no such thing as integer data type in perl... what interest me is that how efficient the algorithm of perl doing a bitwise shift in floating point format. fooler. _ Philippine Linux Users Group. Web site and archives at http://plug.linux.org.ph To leave: send "unsubscribe" in the body to [EMAIL PROTECTED] To subscribe to the Linux Newbies' List: send "subscribe" in the body to [EMAIL PROTECTED]
