Thread: Prelude
View Single Post
  #8  
Old 12-18-2010, 07:04 PM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
Quote:
Originally Posted by fowlplay4 View Post
PHP Code:
function isEven(x) { // missing divide operation
  
return int(x) == (2);
}
function 
isEven(x) {
  return 
int(2) == (2);

You're missing an operation in the isEven() function!

The way I usually look at it, checking if its even by int(x / 2) == (x / 2) requires four basic operations (int, 2 divides, and a comparison), at least two references (x twice, maybe a third for the int() function call). Modulus requires two basic operations (mod, and a comparison) and only one variable reference.

But yeah I agree, the difference is so small it probably wouldn't matter in most cases.
__________________
Reply With Quote