note 80108 deleted from function.abs by hholzgra

From: Date: Sun, 15 Apr 2012 19:28:33 +0000
Subject: note 80108 deleted from function.abs by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187146@lists.php.net to get a copy of this message
Note Submitter: thomas at tgohome dot com ---- If we want to into a war about speed with negative absolute numbers, I think bitwise operations should just about do it. <?php function n_abs($v) { return ~abs($v) + 1; } ?> A NOT operation on any number with a sign bit will produce the negative of that number minus one. All we need to do is add one. Voila! Speed test results (30000 iterations of various methods) produced very close dueling between the previous suggested method. Although I am on an overloaded Windows PC so I'm no benchmark, and I'll leave it up to you, the reader of this message.

« previous php.notes (#187146) next »