jqgrid - What's the difference between 2 lines in PHP? -


i have found in jqgrid server side php example next line

$start = $limit*$page - $limit; // not put $limit*($page - 1) 

what's difference between

$start = $limit*$page - $limit; 

and

$start = $limit*($page - 1); 

why authors not recommend second way ?

i suspect numerical math issue. suppose $page huge, in 6.02e231.

($page - 1) = 6.02e231 

(the exact same floating point representation),

$limit*($page - 1) = $limit*$page 

from point of view of processor. compare

$limit*$page = [some huge value] $limit*$page - $limit = [subtraction of 2 huge values] 

which yield different result, more accurate "minus one" notation.

so although in perfect world of mathematics, 2 notations equal, in non-perfect world of computing, first 1 more prone 'catastrophic cancellation' (wiki that) second.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

c++ - Accessing inactive union member and undefined behavior? -

php - Get uncommon values from two or more arrays -