Home | History | Annotate | Download | only in mjsunit
      1 // Copyright 2015 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 var values = [true,false,null,void 0,0,0.0,-0,"",-1,-1.25,1,1.25,-2147483648,2147483648,Infinity,-Infinity,NaN];
      6 var expected = [
      7   [1,1,1,NaN,1,1,1,1,1,1,1,1.25,1,2147483648,Infinity,1,NaN],
      8   [1,0,0,NaN,0,0,0,0,0,0,1,1.25,0,2147483648,Infinity,0,NaN],
      9   [1,0,0,NaN,0,0,0,0,0,0,1,1.25,0,2147483648,Infinity,0,NaN],
     10   [NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN],
     11   [1,0,0,NaN,0,0,0,0,0,0,1,1.25,0,2147483648,Infinity,0,NaN],
     12   [1,0,0,NaN,0,0,0,0,0,0,1,1.25,0,2147483648,Infinity,0,NaN],
     13   [1,0,0,NaN,0,0,-0,0,-0,-0,1,1.25,-0,2147483648,Infinity,-0,NaN],
     14   [1,0,0,NaN,0,0,0,0,0,0,1,1.25,0,2147483648,Infinity,0,NaN],
     15   [1,0,0,NaN,0,0,-0,0,-1,-1,1,1.25,-1,2147483648,Infinity,-1,NaN],
     16   [1,0,0,NaN,0,0,-0,0,-1,-1.25,1,1.25,-1.25,2147483648,Infinity,-1.25,NaN],
     17   [1,1,1,NaN,1,1,1,1,1,1,1,1.25,1,2147483648,Infinity,1,NaN],
     18   [1.25,1.25,1.25,NaN,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,2147483648,Infinity,1.25,NaN],
     19   [1,0,0,NaN,0,0,-0,0,-1,-1.25,1,1.25,-2147483648,2147483648,Infinity,-2147483648,NaN],
     20   [2147483648,2147483648,2147483648,NaN,2147483648,2147483648,2147483648,2147483648,2147483648,2147483648,2147483648,2147483648,2147483648,2147483648,Infinity,2147483648,NaN],
     21   [Infinity,Infinity,Infinity,NaN,Infinity,Infinity,Infinity,Infinity,Infinity,Infinity,Infinity,Infinity,Infinity,Infinity,Infinity,Infinity,NaN],
     22   [1,0,0,NaN,0,0,-0,0,-1,-1.25,1,1.25,-2147483648,2147483648,Infinity,-Infinity,NaN],
     23   [NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN]
     24 ];
     25 var func = (function max(a,b) { return Math.max(a, b); });
     26 var left_funcs = [
     27   (function max_L0(b) { return Math.max(true, b); }),
     28   (function max_L1(b) { return Math.max(false, b); }),
     29   (function max_L2(b) { return Math.max(null, b); }),
     30   (function max_L3(b) { return Math.max(void 0, b); }),
     31   (function max_L4(b) { return Math.max(0, b); }),
     32   (function max_L5(b) { return Math.max(0.0, b); }),
     33   (function max_L6(b) { return Math.max(-0, b); }),
     34   (function max_L7(b) { return Math.max("", b); }),
     35   (function max_L8(b) { return Math.max(-1, b); }),
     36   (function max_L9(b) { return Math.max(-1.25, b); }),
     37   (function max_L10(b) { return Math.max(1, b); }),
     38   (function max_L11(b) { return Math.max(1.25, b); }),
     39   (function max_L12(b) { return Math.max(-2147483648, b); }),
     40   (function max_L13(b) { return Math.max(2147483648, b); }),
     41   (function max_L14(b) { return Math.max(Infinity, b); }),
     42   (function max_L15(b) { return Math.max(-Infinity, b); }),
     43   (function max_L16(b) { return Math.max(NaN, b); })
     44 ];
     45 var right_funcs = [
     46   (function max_R0(a) { return Math.max(a, true); }),
     47   (function max_R1(a) { return Math.max(a, false); }),
     48   (function max_R2(a) { return Math.max(a, null); }),
     49   (function max_R3(a) { return Math.max(a, void 0); }),
     50   (function max_R4(a) { return Math.max(a, 0); }),
     51   (function max_R5(a) { return Math.max(a, 0.0); }),
     52   (function max_R6(a) { return Math.max(a, -0); }),
     53   (function max_R7(a) { return Math.max(a, ""); }),
     54   (function max_R8(a) { return Math.max(a, -1); }),
     55   (function max_R9(a) { return Math.max(a, -1.25); }),
     56   (function max_R10(a) { return Math.max(a, 1); }),
     57   (function max_R11(a) { return Math.max(a, 1.25); }),
     58   (function max_R12(a) { return Math.max(a, -2147483648); }),
     59   (function max_R13(a) { return Math.max(a, 2147483648); }),
     60   (function max_R14(a) { return Math.max(a, Infinity); }),
     61   (function max_R15(a) { return Math.max(a, -Infinity); }),
     62   (function max_R16(a) { return Math.max(a, NaN); })
     63 ];
     64 function matrix() {
     65   return [
     66     [Math.max(true, true),Math.max(true, false),Math.max(true, null),Math.max(true, void 0),Math.max(true, 0),Math.max(true, 0.0),Math.max(true, -0),Math.max(true, ""),Math.max(true, -1),Math.max(true, -1.25),Math.max(true, 1),Math.max(true, 1.25),Math.max(true, -2147483648),Math.max(true, 2147483648),Math.max(true, Infinity),Math.max(true, -Infinity),Math.max(true, NaN)],
     67     [Math.max(false, true),Math.max(false, false),Math.max(false, null),Math.max(false, void 0),Math.max(false, 0),Math.max(false, 0.0),Math.max(false, -0),Math.max(false, ""),Math.max(false, -1),Math.max(false, -1.25),Math.max(false, 1),Math.max(false, 1.25),Math.max(false, -2147483648),Math.max(false, 2147483648),Math.max(false, Infinity),Math.max(false, -Infinity),Math.max(false, NaN)],
     68     [Math.max(null, true),Math.max(null, false),Math.max(null, null),Math.max(null, void 0),Math.max(null, 0),Math.max(null, 0.0),Math.max(null, -0),Math.max(null, ""),Math.max(null, -1),Math.max(null, -1.25),Math.max(null, 1),Math.max(null, 1.25),Math.max(null, -2147483648),Math.max(null, 2147483648),Math.max(null, Infinity),Math.max(null, -Infinity),Math.max(null, NaN)],
     69     [Math.max(void 0, true),Math.max(void 0, false),Math.max(void 0, null),Math.max(void 0, void 0),Math.max(void 0, 0),Math.max(void 0, 0.0),Math.max(void 0, -0),Math.max(void 0, ""),Math.max(void 0, -1),Math.max(void 0, -1.25),Math.max(void 0, 1),Math.max(void 0, 1.25),Math.max(void 0, -2147483648),Math.max(void 0, 2147483648),Math.max(void 0, Infinity),Math.max(void 0, -Infinity),Math.max(void 0, NaN)],
     70     [Math.max(0, true),Math.max(0, false),Math.max(0, null),Math.max(0, void 0),Math.max(0, 0),Math.max(0, 0.0),Math.max(0, -0),Math.max(0, ""),Math.max(0, -1),Math.max(0, -1.25),Math.max(0, 1),Math.max(0, 1.25),Math.max(0, -2147483648),Math.max(0, 2147483648),Math.max(0, Infinity),Math.max(0, -Infinity),Math.max(0, NaN)],
     71     [Math.max(0.0, true),Math.max(0.0, false),Math.max(0.0, null),Math.max(0.0, void 0),Math.max(0.0, 0),Math.max(0.0, 0.0),Math.max(0.0, -0),Math.max(0.0, ""),Math.max(0.0, -1),Math.max(0.0, -1.25),Math.max(0.0, 1),Math.max(0.0, 1.25),Math.max(0.0, -2147483648),Math.max(0.0, 2147483648),Math.max(0.0, Infinity),Math.max(0.0, -Infinity),Math.max(0.0, NaN)],
     72     [Math.max(-0, true),Math.max(-0, false),Math.max(-0, null),Math.max(-0, void 0),Math.max(-0, 0),Math.max(-0, 0.0),Math.max(-0, -0),Math.max(-0, ""),Math.max(-0, -1),Math.max(-0, -1.25),Math.max(-0, 1),Math.max(-0, 1.25),Math.max(-0, -2147483648),Math.max(-0, 2147483648),Math.max(-0, Infinity),Math.max(-0, -Infinity),Math.max(-0, NaN)],
     73     [Math.max("", true),Math.max("", false),Math.max("", null),Math.max("", void 0),Math.max("", 0),Math.max("", 0.0),Math.max("", -0),Math.max("", ""),Math.max("", -1),Math.max("", -1.25),Math.max("", 1),Math.max("", 1.25),Math.max("", -2147483648),Math.max("", 2147483648),Math.max("", Infinity),Math.max("", -Infinity),Math.max("", NaN)],
     74     [Math.max(-1, true),Math.max(-1, false),Math.max(-1, null),Math.max(-1, void 0),Math.max(-1, 0),Math.max(-1, 0.0),Math.max(-1, -0),Math.max(-1, ""),Math.max(-1, -1),Math.max(-1, -1.25),Math.max(-1, 1),Math.max(-1, 1.25),Math.max(-1, -2147483648),Math.max(-1, 2147483648),Math.max(-1, Infinity),Math.max(-1, -Infinity),Math.max(-1, NaN)],
     75     [Math.max(-1.25, true),Math.max(-1.25, false),Math.max(-1.25, null),Math.max(-1.25, void 0),Math.max(-1.25, 0),Math.max(-1.25, 0.0),Math.max(-1.25, -0),Math.max(-1.25, ""),Math.max(-1.25, -1),Math.max(-1.25, -1.25),Math.max(-1.25, 1),Math.max(-1.25, 1.25),Math.max(-1.25, -2147483648),Math.max(-1.25, 2147483648),Math.max(-1.25, Infinity),Math.max(-1.25, -Infinity),Math.max(-1.25, NaN)],
     76     [Math.max(1, true),Math.max(1, false),Math.max(1, null),Math.max(1, void 0),Math.max(1, 0),Math.max(1, 0.0),Math.max(1, -0),Math.max(1, ""),Math.max(1, -1),Math.max(1, -1.25),Math.max(1, 1),Math.max(1, 1.25),Math.max(1, -2147483648),Math.max(1, 2147483648),Math.max(1, Infinity),Math.max(1, -Infinity),Math.max(1, NaN)],
     77     [Math.max(1.25, true),Math.max(1.25, false),Math.max(1.25, null),Math.max(1.25, void 0),Math.max(1.25, 0),Math.max(1.25, 0.0),Math.max(1.25, -0),Math.max(1.25, ""),Math.max(1.25, -1),Math.max(1.25, -1.25),Math.max(1.25, 1),Math.max(1.25, 1.25),Math.max(1.25, -2147483648),Math.max(1.25, 2147483648),Math.max(1.25, Infinity),Math.max(1.25, -Infinity),Math.max(1.25, NaN)],
     78     [Math.max(-2147483648, true),Math.max(-2147483648, false),Math.max(-2147483648, null),Math.max(-2147483648, void 0),Math.max(-2147483648, 0),Math.max(-2147483648, 0.0),Math.max(-2147483648, -0),Math.max(-2147483648, ""),Math.max(-2147483648, -1),Math.max(-2147483648, -1.25),Math.max(-2147483648, 1),Math.max(-2147483648, 1.25),Math.max(-2147483648, -2147483648),Math.max(-2147483648, 2147483648),Math.max(-2147483648, Infinity),Math.max(-2147483648, -Infinity),Math.max(-2147483648, NaN)],
     79     [Math.max(2147483648, true),Math.max(2147483648, false),Math.max(2147483648, null),Math.max(2147483648, void 0),Math.max(2147483648, 0),Math.max(2147483648, 0.0),Math.max(2147483648, -0),Math.max(2147483648, ""),Math.max(2147483648, -1),Math.max(2147483648, -1.25),Math.max(2147483648, 1),Math.max(2147483648, 1.25),Math.max(2147483648, -2147483648),Math.max(2147483648, 2147483648),Math.max(2147483648, Infinity),Math.max(2147483648, -Infinity),Math.max(2147483648, NaN)],
     80     [Math.max(Infinity, true),Math.max(Infinity, false),Math.max(Infinity, null),Math.max(Infinity, void 0),Math.max(Infinity, 0),Math.max(Infinity, 0.0),Math.max(Infinity, -0),Math.max(Infinity, ""),Math.max(Infinity, -1),Math.max(Infinity, -1.25),Math.max(Infinity, 1),Math.max(Infinity, 1.25),Math.max(Infinity, -2147483648),Math.max(Infinity, 2147483648),Math.max(Infinity, Infinity),Math.max(Infinity, -Infinity),Math.max(Infinity, NaN)],
     81     [Math.max(-Infinity, true),Math.max(-Infinity, false),Math.max(-Infinity, null),Math.max(-Infinity, void 0),Math.max(-Infinity, 0),Math.max(-Infinity, 0.0),Math.max(-Infinity, -0),Math.max(-Infinity, ""),Math.max(-Infinity, -1),Math.max(-Infinity, -1.25),Math.max(-Infinity, 1),Math.max(-Infinity, 1.25),Math.max(-Infinity, -2147483648),Math.max(-Infinity, 2147483648),Math.max(-Infinity, Infinity),Math.max(-Infinity, -Infinity),Math.max(-Infinity, NaN)],
     82     [Math.max(NaN, true),Math.max(NaN, false),Math.max(NaN, null),Math.max(NaN, void 0),Math.max(NaN, 0),Math.max(NaN, 0.0),Math.max(NaN, -0),Math.max(NaN, ""),Math.max(NaN, -1),Math.max(NaN, -1.25),Math.max(NaN, 1),Math.max(NaN, 1.25),Math.max(NaN, -2147483648),Math.max(NaN, 2147483648),Math.max(NaN, Infinity),Math.max(NaN, -Infinity),Math.max(NaN, NaN)]
     83   ];
     84 }
     85 function test() {
     86   for (var i = 0; i < values.length; i++) {
     87     for (var j = 0; j < values.length; j++) {
     88       var a = values[i];
     89       var b = values[j];
     90       var x = expected[i][j];
     91       assertEquals(x, func(a,b));
     92       assertEquals(x, left_funcs[i](b));
     93       assertEquals(x, right_funcs[j](a));
     94     }
     95   }
     96 
     97   var result = matrix();
     98   for (var i = 0; i < values.length; i++) {
     99     for (var j = 0; j < values.length; j++) {
    100       assertEquals(expected[i][j], result[i][j]);
    101     }
    102   }
    103 }
    104 test();
    105 test();
    106