1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * phpMyAdmin's BigInts library
7 * @var BigInts object to handle big integers (in string)
8 * as JS can handle upto 53 bits of precision only.
13 * Compares two integer strings
15 * @param int1 the string representation of 1st integer
16 * @param int2 the string representation of 2nd integer
18 * @return int 0 if equal, < 0 if int1 < int2, else > 0
20 compare: function(int1, int2) {
24 // length of integer strings
25 var len1 = int1.length;
26 var len2 = int2.length;
27 // integer is -ve or not
28 var isNeg1 = (int1[0] === '-');
29 var isNeg2 = (int2[0] === '-');
30 // Sign of int1 != int2 then no actual comparison
31 // is needed we can return result directly
32 if (isNeg1 !== isNeg2) {
33 return (isNeg1 === true ? -1 : 1);
35 // replace - sign with 0
36 int1[0] = isNeg1 ? '0' : int1[0];
37 int2[0] = isNeg2 ? '0' : int2[0];
38 // pad integers with 0 to make them
40 int1 = BigInts.lpad(int1, len2);
41 int2 = BigInts.lpad(int2, len1);
42 // Now they are good to compare as strings
44 return (int1 < int2 ? -1 : 1);
50 * Adds leading zeros to a integer given a total length
52 * @param int the string representation of the integer
53 * @param total the total length required
55 * @return int the integer of length given with added leading
58 lpad: function(int, total){