Opera Fan Boy, at your service

Beware of Bad Breath

Why x**0 is always 1

Well, OK. Not true for inf and 0, but this holds for any other number.
We all know this from math, but I'll show you why this holds through coding.
While we're at it, I will point out that this is probably how they decided this in the first place.


function pow( number, exponent ){
	var result = 1; // the neutral number for multiplication
	if( exponent > 0 ){
		while( exponent > 0 ){ // so result is never altered
			result *= number; // we don't care about the rest of this; do we?
			exponent--;
		}
	} else {
		while( exponent < 0 ){
			result /= number;
			exponent++;		
		}

	}
	return result;
}



I really hope that speaks for itself.
smile

FIrst Impressions of Ubuntu Karmic KoalaThe Dying Art of Proofreading

Write a comment

New comments have been disabled for this post.