1// Copyright 2012 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// Test number predicates that Harmony adds to the Number constructor: 29// isFinite(), isNaN(), isInteger(), isSafeInteger(). 30 31assertTrue(Number.isFinite(0)); 32assertTrue(Number.isFinite(Number.MIN_VALUE)); 33assertTrue(Number.isFinite(Number.MAX_VALUE)); 34assertTrue(Number.isFinite(Number.MIN_SAFE_INTEGER)); 35assertTrue(Number.isFinite(Number.MIN_SAFE_INTEGER - 13)); 36assertTrue(Number.isFinite(Number.MAX_SAFE_INTEGER)); 37assertTrue(Number.isFinite(Number.MAX_SAFE_INTEGER + 23)); 38assertFalse(Number.isFinite(Number.NaN)); 39assertFalse(Number.isFinite(Number.POSITIVE_INFINITY)); 40assertFalse(Number.isFinite(Number.NEGATIVE_INFINITY)); 41assertFalse(Number.isFinite(new Number(0))); 42assertFalse(Number.isFinite(1/0)); 43assertFalse(Number.isFinite(-1/0)); 44assertFalse(Number.isFinite({})); 45assertFalse(Number.isFinite([])); 46assertFalse(Number.isFinite("s")); 47assertFalse(Number.isFinite(null)); 48assertFalse(Number.isFinite(undefined)); 49 50assertFalse(Number.isNaN(0)); 51assertFalse(Number.isNaN(Number.MIN_VALUE)); 52assertFalse(Number.isNaN(Number.MAX_VALUE)); 53assertFalse(Number.isNaN(Number.MIN_SAFE_INTEGER - 13)); 54assertFalse(Number.isNaN(Number.MAX_SAFE_INTEGER + 23)); 55assertTrue(Number.isNaN(Number.NaN)); 56assertFalse(Number.isNaN(Number.POSITIVE_INFINITY)); 57assertFalse(Number.isNaN(Number.NEGATIVE_INFINITY)); 58assertFalse(Number.isNaN(Number.EPSILON)); 59assertFalse(Number.isNaN(new Number(0))); 60assertFalse(Number.isNaN(1/0)); 61assertFalse(Number.isNaN(-1/0)); 62assertFalse(Number.isNaN({})); 63assertFalse(Number.isNaN([])); 64assertFalse(Number.isNaN("s")); 65assertFalse(Number.isNaN(null)); 66assertFalse(Number.isNaN(undefined)); 67 68assertFalse(Number.isInteger({})); 69assertFalse(Number.isInteger([])); 70assertFalse(Number.isInteger("s")); 71assertFalse(Number.isInteger(null)); 72assertFalse(Number.isInteger(undefined)); 73assertFalse(Number.isInteger(new Number(2))); 74assertTrue(Number.isInteger(0)); 75assertFalse(Number.isInteger(Number.MIN_VALUE)); 76assertTrue(Number.isInteger(Number.MAX_VALUE)); 77assertTrue(Number.isInteger(Number.MIN_SAFE_INTEGER)); 78assertTrue(Number.isInteger(Number.MIN_SAFE_INTEGER - 13)); 79assertTrue(Number.isInteger(Number.MAX_SAFE_INTEGER)); 80assertTrue(Number.isInteger(Number.MAX_SAFE_INTEGER + 23)); 81assertFalse(Number.isInteger(Number.NaN)); 82assertFalse(Number.isInteger(Number.POSITIVE_INFINITY)); 83assertFalse(Number.isInteger(Number.NEGATIVE_INFINITY)); 84assertFalse(Number.isInteger(1/0)); 85assertFalse(Number.isInteger(-1/0)); 86assertFalse(Number.isInteger(Number.EPSILON)); 87 88assertFalse(Number.isSafeInteger({})); 89assertFalse(Number.isSafeInteger([])); 90assertFalse(Number.isSafeInteger("s")); 91assertFalse(Number.isSafeInteger(null)); 92assertFalse(Number.isSafeInteger(undefined)); 93assertFalse(Number.isSafeInteger(new Number(2))); 94assertTrue(Number.isSafeInteger(0)); 95assertTrue(Number.isSafeInteger(Number.MIN_SAFE_INTEGER)); 96assertFalse(Number.isSafeInteger(Number.MIN_SAFE_INTEGER - 13)); 97assertTrue(Number.isSafeInteger(Number.MIN_SAFE_INTEGER + 13)); 98assertTrue(Number.isSafeInteger(Number.MAX_SAFE_INTEGER)); 99assertFalse(Number.isSafeInteger(Number.MAX_SAFE_INTEGER + 23)); 100assertTrue(Number.isSafeInteger(Number.MAX_SAFE_INTEGER - 23)); 101assertFalse(Number.isSafeInteger(Number.MIN_VALUE)); 102assertFalse(Number.isSafeInteger(Number.MAX_VALUE)); 103assertFalse(Number.isSafeInteger(Number.NaN)); 104assertFalse(Number.isSafeInteger(Number.POSITIVE_INFINITY)); 105assertFalse(Number.isSafeInteger(Number.NEGATIVE_INFINITY)); 106assertFalse(Number.isSafeInteger(1/0)); 107assertFalse(Number.isSafeInteger(-1/0)); 108assertFalse(Number.isSafeInteger(Number.EPSILON)); 109 110var near_upper = Math.pow(2, 52); 111assertTrue(Number.isSafeInteger(near_upper)); 112assertFalse(Number.isSafeInteger(2 * near_upper)); 113assertTrue(Number.isSafeInteger(2 * near_upper - 1)); 114assertTrue(Number.isSafeInteger(2 * near_upper - 2)); 115assertFalse(Number.isSafeInteger(2 * near_upper + 1)); 116assertFalse(Number.isSafeInteger(2 * near_upper + 2)); 117assertFalse(Number.isSafeInteger(2 * near_upper + 7)); 118 119var near_lower = -near_upper; 120assertTrue(Number.isSafeInteger(near_lower)); 121assertFalse(Number.isSafeInteger(2 * near_lower)); 122assertTrue(Number.isSafeInteger(2 * near_lower + 1)); 123assertTrue(Number.isSafeInteger(2 * near_lower + 2)); 124assertFalse(Number.isSafeInteger(2 * near_lower - 1)); 125assertFalse(Number.isSafeInteger(2 * near_lower - 2)); 126assertFalse(Number.isSafeInteger(2 * near_lower - 7)); 127