Home | History | Annotate | Download | only in mjsunit
      1 // Copyright 2008 the V8 project authors. All rights reserved.
      2 // Redistribution and use in source and binary forms, with or without
      3 // modification, are permitted provided that the following conditions are
      4 // met:
      5 //
      6 //     * Redistributions of source code must retain the above copyright
      7 //       notice, this list of conditions and the following disclaimer.
      8 //     * Redistributions in binary form must reproduce the above
      9 //       copyright notice, this list of conditions and the following
     10 //       disclaimer in the documentation and/or other materials provided
     11 //       with the distribution.
     12 //     * Neither the name of Google Inc. nor the names of its
     13 //       contributors may be used to endorse or promote products derived
     14 //       from this software without specific prior written permission.
     15 //
     16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 
     28 // Ensure that operations on small integers handle -0.
     29 
     30 var zero = 0;
     31 var one = 1;
     32 var minus_one = -1;
     33 var two = 2;
     34 var four = 4;
     35 var minus_two = -2;
     36 var minus_four = -4;
     37 
     38 // variable op variable
     39 
     40 assertEquals(-Infinity, one / (-zero), "one / -0 I");
     41 
     42 assertEquals(-Infinity, one / (zero * minus_one), "one / -1");
     43 assertEquals(-Infinity, one / (minus_one * zero), "one / -0 II");
     44 assertEquals(Infinity, one / (zero * zero), "one / 0 I");
     45 assertEquals(1, one / (minus_one * minus_one), "one / 1");
     46 
     47 assertEquals(-Infinity, one / (zero / minus_one), "one / -0 III");
     48 assertEquals(Infinity, one / (zero / one), "one / 0 II");
     49 
     50 assertEquals(-Infinity, one / (minus_four % two), "foo1");
     51 assertEquals(-Infinity, one / (minus_four % minus_two), "foo2");
     52 assertEquals(Infinity, one / (four % two), "foo3");
     53 assertEquals(Infinity, one / (four % minus_two), "foo4");
     54 
     55 // literal op variable
     56 
     57 assertEquals(-Infinity, one / (0 * minus_one), "bar1");
     58 assertEquals(-Infinity, one / (-1 * zero), "bar2");
     59 assertEquals(Infinity, one / (0 * zero), "bar3");
     60 assertEquals(1, one / (-1 * minus_one), "bar4");
     61 
     62 assertEquals(-Infinity, one / (0 / minus_one), "baz1");
     63 assertEquals(Infinity, one / (0 / one), "baz2");
     64 
     65 assertEquals(-Infinity, one / (-4 % two), "baz3");
     66 assertEquals(-Infinity, one / (-4 % minus_two), "baz4");
     67 assertEquals(Infinity, one / (4 % two), "baz5");
     68 assertEquals(Infinity, one / (4 % minus_two), "baz6");
     69 
     70 // variable op literal
     71 
     72 assertEquals(-Infinity, one / (zero * -1), "fizz1");
     73 assertEquals(-Infinity, one / (minus_one * 0), "fizz2");
     74 assertEquals(Infinity, one / (zero * 0), "fizz3");
     75 assertEquals(1, one / (minus_one * -1), "fizz4");
     76 
     77 assertEquals(-Infinity, one / (zero / -1), "buzz1");
     78 assertEquals(Infinity, one / (zero / 1), "buzz2");
     79 
     80 assertEquals(-Infinity, one / (minus_four % 2), "buzz3");
     81 assertEquals(-Infinity, one / (minus_four % -2), "buzz4");
     82 assertEquals(Infinity, one / (four % 2), "buzz5");
     83 assertEquals(Infinity, one / (four % -2), "buzz6");
     84 
     85 // literal op literal
     86 
     87 assertEquals(-Infinity, one / (-0), "fisk1");
     88 
     89 assertEquals(-Infinity, one / (0 * -1), "fisk2");
     90 assertEquals(-Infinity, one / (-1 * 0), "fisk3");
     91 assertEquals(Infinity, one / (0 * 0), "fisk4");
     92 assertEquals(1, one / (-1 * -1), "fisk5");
     93 
     94 assertEquals(-Infinity, one / (0 / -1), "hest1");
     95 assertEquals(Infinity, one / (0 / 1), "hest2");
     96 
     97 assertEquals(-Infinity, one / (-4 % 2), "fiskhest1");
     98 assertEquals(-Infinity, one / (-4 % -2), "fiskhest2");
     99 assertEquals(Infinity, one / (4 % 2), "fiskhest3");
    100 assertEquals(Infinity, one / (4 % -2), "fiskhest4");
    101 
    102 
    103 // This tests against a singleton -0.0 object being overwritten.gc
    104 x = 0;
    105 z = 3044;
    106 
    107 function foo(x) {
    108   var y = -x + z;
    109   return -x;
    110 }
    111 
    112 assertEquals(-0, foo(x));
    113 assertEquals(-0, foo(x));
    114