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// Flags: --allow-natives-syntax 6 7var DOUBLE_ZERO = %AllocateHeapNumber(); 8var SMI_ZERO = 0; 9var MINUS_ZERO = -0.0; 10 11function min1(a, b) { 12 a = +a; 13 b = +b; 14 return +(a < b ? a : b); 15} 16 17function min2(a, b) { 18 a = +a; 19 b = +b; 20 return a < b ? a : b; 21} 22 23for (f of [min1, min2]) { 24 for (var i = 0; i < 5; i++) { 25 assertEquals(3, f(3, 4)); 26 assertEquals(3, f(4, 3)); 27 assertEquals(3.3, f(3.3, 4)); 28 assertEquals(3.4, f(4, 3.4)); 29 30 assertEquals(-Infinity, 1 / f(SMI_ZERO, MINUS_ZERO)); 31 assertEquals(-Infinity, 1 / f(DOUBLE_ZERO, MINUS_ZERO)); 32 assertEquals(Infinity, 1 / f(MINUS_ZERO, SMI_ZERO)); 33 assertEquals(Infinity, 1 / f(MINUS_ZERO, DOUBLE_ZERO)); 34 35 assertEquals(NaN, f(NaN, NaN)); 36 assertEquals(NaN, f(3, NaN)); 37 assertEquals(3, f(NaN, 3)); 38 } 39} 40 41function min3(a, b) { 42 a = +a; 43 b = +b; 44 return +(a > b ? b : a); 45} 46 47function min4(a, b) { 48 a = +a; 49 b = +b; 50 return a > b ? b : a; 51} 52 53for (f of [min3, min4]) { 54 for (var i = 0; i < 5; i++) { 55 assertEquals(3, f(3, 4)); 56 assertEquals(3, f(4, 3)); 57 assertEquals(3.3, f(3.3, 4)); 58 assertEquals(3.4, f(4, 3.4)); 59 60 assertEquals(Infinity, 1 / f(SMI_ZERO, MINUS_ZERO)); 61 assertEquals(Infinity, 1 / f(DOUBLE_ZERO, MINUS_ZERO)); 62 assertEquals(-Infinity, 1 / f(MINUS_ZERO, SMI_ZERO)); 63 assertEquals(-Infinity, 1 / f(MINUS_ZERO, DOUBLE_ZERO)); 64 65 assertEquals(NaN, f(NaN, NaN)); 66 assertEquals(3, f(3, NaN)); 67 assertEquals(NaN, f(NaN, 3)); 68 } 69} 70