tor-browser

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

math-indirect-truncate.js (791B)


      1 function testCeil() {
      2  function ceil(a, b) {
      3    return Math.ceil(a / b) | 0;
      4  }
      5 
      6  // Warm-up
      7  for (var i = 0; i < 50; i++) {
      8    ceil(5, 5);
      9  }
     10 
     11  assertEq(ceil(5, 3), 2);
     12 }
     13 testCeil();
     14 
     15 function testFloor() {
     16  function floor(a, b) {
     17    return Math.floor(a / b) | 0;
     18  }
     19 
     20  // Warm-up
     21  for (var i = 0; i < 50; i++) {
     22    floor(5, 5);
     23  }
     24 
     25  assertEq(floor(-5, 3), -2);
     26 }
     27 testFloor();
     28 
     29 function testRound() {
     30  function round(a, b) {
     31    return Math.round(a / b) | 0;
     32  }
     33 
     34  // Warm-up
     35  for (var i = 0; i < 50; i++) {
     36    round(5, 5);
     37  }
     38 
     39  assertEq(round(5, 3), 2);
     40 }
     41 testRound();
     42 
     43 function testTrunc() {
     44  function trunc(a, b) {
     45    return Math.trunc(a / b) | 0;
     46  }
     47 
     48  // Warm-up
     49  for (var i = 0; i < 50; i++) {
     50    trunc(5, 5);
     51  }
     52 
     53  assertEq(trunc(5, 3), 1);
     54 }
     55 testTrunc();