tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

mathRound.js (1039B)


      1 assertEq(Math.round(3.14), 3);
      2 assertEq(Math.round(0.5), 1);
      3 assertEq(Math.round(-0), -0);
      4 assertEq(Math.round(0), 0);
      5 assertEq(Math.round(-1.03), -1);
      6 assertEq(Math.round(2147483649), 2147483649);
      7 assertEq(Math.round(2147483647.5), 2147483648);
      8 assertEq(Math.floor(2147483647.1), 2147483647);
      9 
     10 /* Inferred as round(double). */
     11 function round1(x) {
     12    return Math.round(x);
     13 }
     14 assertEq(round1(10.3), 10);
     15 assertEq(round1(-3.14), -3);
     16 assertEq(round1(-3.5), -3);
     17 assertEq(round1(-3.6), -4);
     18 assertEq(round1(3.5), 4);
     19 assertEq(round1(3.6), 4);
     20 assertEq(round1(0), 0);
     21 assertEq(round1(-0), -0); // recompile to return double
     22 assertEq(round1(12345), 12345);
     23 assertEq(round1(654.6), 655);
     24 
     25 /* Inferred as round(double). */
     26 function round2(x) {
     27    return Math.round(x);
     28 }
     29 assertEq(round2(1234.5), 1235);
     30 assertEq(round2(NaN), NaN); // recompile to return double
     31 assertEq(round2(4.6), 5);
     32 
     33 /* Inferred as round(int). */
     34 function round3(x) {
     35    return Math.round(x);
     36 }
     37 assertEq(round3(4), 4);
     38 assertEq(round3(-5), -5);
     39 assertEq(round3(0), 0);