17d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// Copyright 2012 the V8 project authors. All rights reserved. 27d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// Redistribution and use in source and binary forms, with or without 37d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// modification, are permitted provided that the following conditions are 47d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// met: 57d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// 67d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// * Redistributions of source code must retain the above copyright 77d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// notice, this list of conditions and the following disclaimer. 87d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// * Redistributions in binary form must reproduce the above 97d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// copyright notice, this list of conditions and the following 107d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// disclaimer in the documentation and/or other materials provided 117d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// with the distribution. 127d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// * Neither the name of Google Inc. nor the names of its 137d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// contributors may be used to endorse or promote products derived 147d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// from this software without specific prior written permission. 157d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// 167d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 177d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 187d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 197d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 207d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 217d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 227d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 237d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 247d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 257d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 267d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 277d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org 287d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// Flags: --allow-natives-syntax 297d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org 307d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.orgvar cases = [ 317d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org [0.0, 0.0, 0.0, 0,0], 327d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org [undefined, 0.0, NaN, NaN], 337d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org [0.0, undefined, NaN, NaN], 347d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org [NaN, 0.0, NaN, NaN], 357d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org [0.0, NaN, NaN, NaN], 367d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org [-NaN, 0.0, NaN, NaN], 377d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org [0.0, -NaN, NaN, NaN], 387d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org [Infinity, 0.0, Infinity, 0.0], 397d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org [0.0, Infinity, Infinity, 0.0], 407d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org [-Infinity, 0.0, 0.0, -Infinity], 417d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org [0.0, -Infinity, 0.0, -Infinity] 427d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org]; 437d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org 447d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.orgfunction do_min(a, b) { 457d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org return Math.min(a, b); 467d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org} 477d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org 487d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.orgfunction do_max(a, b) { 497d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org return Math.max(a, b); 507d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org} 517d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org 527d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// Make sure that non-crankshaft results match expectations. 537d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.orgfor (i = 0; i < cases.length; ++i) { 547d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org var c = cases[i]; 557d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org assertEquals(c[3], do_min(c[0], c[1])); 567d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org assertEquals(c[2], do_max(c[0], c[1])); 577d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org} 587d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org 597d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org// Make sure that crankshaft results match expectations. 607d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.orgfor (i = 0; i < cases.length; ++i) { 617d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org var c = cases[i]; 627d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org %OptimizeFunctionOnNextCall(do_min); 637d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org %OptimizeFunctionOnNextCall(do_max); 647d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org assertEquals(c[3], do_min(c[0], c[1])); 657d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org assertEquals(c[2], do_max(c[0], c[1])); 667d10be581a91ab5eefa1139ff0b86c64ac8f6e59fschneider@chromium.org} 67