note 80108 added to function.abs

From: Date: Sat, 29 Dec 2007 23:00:59 +0000
Subject: note 80108 added to function.abs
Groups: php.notes 
Request: Send a blank email to php-notes+get-134269@lists.php.net to get a copy of this message
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. ---- Server IP: 194.145.210.3 Probable Submitter: 86.149.171.101 ---- Manual Page -- http://www.php.net/manual/en/function.abs.php Edit -- https://master.php.net/note/edit/80108 Del: integrated -- https://master.php.net/note/delete/80108/integrated Del: useless -- https://master.php.net/note/delete/80108/useless Del: bad code -- https://master.php.net/note/delete/80108/bad+code Del: spam -- https://master.php.net/note/delete/80108/spam Del: non-english -- https://master.php.net/note/delete/80108/non-english Del: in docs -- https://master.php.net/note/delete/80108/in+docs Del: other reasons-- https://master.php.net/note/delete/80108 Reject -- https://master.php.net/note/reject/80108 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#134269) next »