Why x**0 is always 1
Saturday, August 22, 2009 10:15:00 PM
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.
I really hope that speaks for itself.
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.











