tor-browser

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

ceil.js (1694B)


      1 setJitCompilerOption("baseline.warmup.trigger", 10);
      2 setJitCompilerOption("ion.warmup.trigger", 20);
      3 
      4 //var log = print;
      5 var log = function(x){}
      6 
      7 function ceil(x) {
      8    // A nice but not always efficient polyfill.
      9    return -Math.floor(-x);
     10 }
     11 
     12 function doubleCheck(g) {
     13    for (var j = 0; j < 200; j++) {
     14        var i = j;
     15        assertEq(g(i), i);
     16        assertEq(g(i+.5), i+1);
     17        assertEq(g(-i), -i);
     18        assertEq(g(-i-.5), -i);
     19    }
     20 }
     21 
     22 function floatCheck(g, val) {
     23    for (var j = 0; j < 200; j++) {
     24        var i = Math.fround(j);
     25        assertEq(g(i), i);
     26        assertEq(g(i+.5), i+1);
     27        assertEq(g(-i), -i);
     28        assertEq(g(-i-.5), -i);
     29    }
     30 }
     31 
     32 function testBailout(value) {
     33    var dceil = eval('(function(x) { return Math.ceil(x) })');
     34    log('start double');
     35    doubleCheck(dceil);
     36    log('bailout');
     37    // At this point, the compiled code should bailout, if 'value' is in the
     38    // edge case set.
     39    assertEq(dceil(value), ceil(value));
     40 
     41    var fceil = eval('(function(x) { return Math.ceil(Math.fround(x)) })');
     42    log('start float');
     43    floatCheck(fceil, value);
     44    log('bailout');
     45    assertEq(fceil(Math.fround(value)), ceil(Math.fround(value)));
     46 }
     47 
     48 var INT_MAX = Math.pow(2, 31) - 1;
     49 var INT_MIN = INT_MAX + 1 | 0;
     50 var UINT_MAX = Math.pow(2, 32) - 1;
     51 
     52 // Values in ]-1; -0]
     53 testBailout(-0);
     54 testBailout(-.5);
     55 // Values outside the INT32 range, when represented in either double or
     56 // single precision
     57 testBailout(INT_MAX + .5);
     58 testBailout(INT_MIN - 129);
     59 // (UINT_MAX; +inf] have special behavior on ARM
     60 testBailout(UINT_MAX);
     61 testBailout(UINT_MAX + .5);
     62 testBailout(UINT_MAX + 1);
     63 testBailout(UINT_MAX + 2);
     64 // BatNaN
     65 testBailout(NaN);