1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma/Expressions/11.5.3.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,127 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + File Name: 11.5.3.js 1.12 + ECMA Section: 11.5.3 Applying the % operator 1.13 + Description: 1.14 + 1.15 + The binary % operator is said to yield the remainder of its operands from 1.16 + an implied division; the left operand is the dividend and the right operand 1.17 + is the divisor. In C and C++, the remainder operator accepts only integral 1.18 + operands, but in ECMAScript, it also accepts floating-point operands. 1.19 + 1.20 + The result of a floating-point remainder operation as computed by the % 1.21 + operator is not the same as the "remainder" operation defined by IEEE 754. 1.22 + The IEEE 754 "remainder" operation computes the remainder from a rounding 1.23 + division, not a truncating division, and so its behavior is not analogous 1.24 + to that of the usual integer remainder operator. Instead the ECMAScript 1.25 + language defines % on floating-point operations to behave in a manner 1.26 + analogous to that of the Java integer remainder operator; this may be 1.27 + compared with the C library function fmod. 1.28 + 1.29 + The result of a ECMAScript floating-point remainder operation is determined by the rules of IEEE arithmetic: 1.30 + 1.31 + If either operand is NaN, the result is NaN. 1.32 + The sign of the result equals the sign of the dividend. 1.33 + If the dividend is an infinity, or the divisor is a zero, or both, the result is NaN. 1.34 + If the dividend is finite and the divisor is an infinity, the result equals the dividend. 1.35 + If the dividend is a zero and the divisor is finite, the result is the same as the dividend. 1.36 + In the remaining cases, where neither an infinity, nor a zero, nor NaN is involved, the floating-point remainder r 1.37 + from a dividend n and a divisor d is defined by the mathematical relation r = n (d * q) where q is an integer that 1.38 + is negative only if n/d is negative and positive only if n/d is positive, and whose magnitude is as large as 1.39 + possible without exceeding the magnitude of the true mathematical quotient of n and d. 1.40 + 1.41 + Author: christine@netscape.com 1.42 + Date: 12 november 1997 1.43 +*/ 1.44 +var SECTION = "11.5.3"; 1.45 +var VERSION = "ECMA_1"; 1.46 +var BUGNUMBER="111202"; 1.47 +startTest(); 1.48 + 1.49 + 1.50 +writeHeaderToLog( SECTION + " Applying the % operator"); 1.51 + 1.52 +// if either operand is NaN, the result is NaN. 1.53 + 1.54 +new TestCase( SECTION, "Number.NaN % Number.NaN", Number.NaN, Number.NaN % Number.NaN ); 1.55 +new TestCase( SECTION, "Number.NaN % 1", Number.NaN, Number.NaN % 1 ); 1.56 +new TestCase( SECTION, "1 % Number.NaN", Number.NaN, 1 % Number.NaN ); 1.57 + 1.58 +new TestCase( SECTION, "Number.POSITIVE_INFINITY % Number.NaN", Number.NaN, Number.POSITIVE_INFINITY % Number.NaN ); 1.59 +new TestCase( SECTION, "Number.NEGATIVE_INFINITY % Number.NaN", Number.NaN, Number.NEGATIVE_INFINITY % Number.NaN ); 1.60 + 1.61 +// If the dividend is an infinity, or the divisor is a zero, or both, the result is NaN. 1.62 +// dividend is an infinity 1.63 + 1.64 +new TestCase( SECTION, "Number.NEGATIVE_INFINITY % Number.NEGATIVE_INFINITY", Number.NaN, Number.NEGATIVE_INFINITY % Number.NEGATIVE_INFINITY ); 1.65 +new TestCase( SECTION, "Number.POSITIVE_INFINITY % Number.NEGATIVE_INFINITY", Number.NaN, Number.POSITIVE_INFINITY % Number.NEGATIVE_INFINITY ); 1.66 +new TestCase( SECTION, "Number.NEGATIVE_INFINITY % Number.POSITIVE_INFINITY", Number.NaN, Number.NEGATIVE_INFINITY % Number.POSITIVE_INFINITY ); 1.67 +new TestCase( SECTION, "Number.POSITIVE_INFINITY % Number.POSITIVE_INFINITY", Number.NaN, Number.POSITIVE_INFINITY % Number.POSITIVE_INFINITY ); 1.68 + 1.69 +new TestCase( SECTION, "Number.POSITIVE_INFINITY % 0", Number.NaN, Number.POSITIVE_INFINITY % 0 ); 1.70 +new TestCase( SECTION, "Number.NEGATIVE_INFINITY % 0", Number.NaN, Number.NEGATIVE_INFINITY % 0 ); 1.71 +new TestCase( SECTION, "Number.POSITIVE_INFINITY % -0", Number.NaN, Number.POSITIVE_INFINITY % -0 ); 1.72 +new TestCase( SECTION, "Number.NEGATIVE_INFINITY % -0", Number.NaN, Number.NEGATIVE_INFINITY % -0 ); 1.73 + 1.74 +new TestCase( SECTION, "Number.NEGATIVE_INFINITY % 1 ", Number.NaN, Number.NEGATIVE_INFINITY % 1 ); 1.75 +new TestCase( SECTION, "Number.NEGATIVE_INFINITY % -1 ", Number.NaN, Number.NEGATIVE_INFINITY % -1 ); 1.76 +new TestCase( SECTION, "Number.POSITIVE_INFINITY % 1 ", Number.NaN, Number.POSITIVE_INFINITY % 1 ); 1.77 +new TestCase( SECTION, "Number.POSITIVE_INFINITY % -1 ", Number.NaN, Number.POSITIVE_INFINITY % -1 ); 1.78 + 1.79 +new TestCase( SECTION, "Number.NEGATIVE_INFINITY % Number.MAX_VALUE ", Number.NaN, Number.NEGATIVE_INFINITY % Number.MAX_VALUE ); 1.80 +new TestCase( SECTION, "Number.NEGATIVE_INFINITY % -Number.MAX_VALUE ", Number.NaN, Number.NEGATIVE_INFINITY % -Number.MAX_VALUE ); 1.81 +new TestCase( SECTION, "Number.POSITIVE_INFINITY % Number.MAX_VALUE ", Number.NaN, Number.POSITIVE_INFINITY % Number.MAX_VALUE ); 1.82 +new TestCase( SECTION, "Number.POSITIVE_INFINITY % -Number.MAX_VALUE ", Number.NaN, Number.POSITIVE_INFINITY % -Number.MAX_VALUE ); 1.83 + 1.84 +// divisor is 0 1.85 +new TestCase( SECTION, "0 % -0", Number.NaN, 0 % -0 ); 1.86 +new TestCase( SECTION, "-0 % 0", Number.NaN, -0 % 0 ); 1.87 +new TestCase( SECTION, "-0 % -0", Number.NaN, -0 % -0 ); 1.88 +new TestCase( SECTION, "0 % 0", Number.NaN, 0 % 0 ); 1.89 + 1.90 +new TestCase( SECTION, "1 % 0", Number.NaN, 1%0 ); 1.91 +new TestCase( SECTION, "1 % -0", Number.NaN, 1%-0 ); 1.92 +new TestCase( SECTION, "-1 % 0", Number.NaN, -1%0 ); 1.93 +new TestCase( SECTION, "-1 % -0", Number.NaN, -1%-0 ); 1.94 + 1.95 +new TestCase( SECTION, "Number.MAX_VALUE % 0", Number.NaN, Number.MAX_VALUE%0 ); 1.96 +new TestCase( SECTION, "Number.MAX_VALUE % -0", Number.NaN, Number.MAX_VALUE%-0 ); 1.97 +new TestCase( SECTION, "-Number.MAX_VALUE % 0", Number.NaN, -Number.MAX_VALUE%0 ); 1.98 +new TestCase( SECTION, "-Number.MAX_VALUE % -0", Number.NaN, -Number.MAX_VALUE%-0 ); 1.99 + 1.100 +// If the dividend is finite and the divisor is an infinity, the result equals the dividend. 1.101 + 1.102 +new TestCase( SECTION, "1 % Number.NEGATIVE_INFINITY", 1, 1 % Number.NEGATIVE_INFINITY ); 1.103 +new TestCase( SECTION, "1 % Number.POSITIVE_INFINITY", 1, 1 % Number.POSITIVE_INFINITY ); 1.104 +new TestCase( SECTION, "-1 % Number.POSITIVE_INFINITY", -1, -1 % Number.POSITIVE_INFINITY ); 1.105 +new TestCase( SECTION, "-1 % Number.NEGATIVE_INFINITY", -1, -1 % Number.NEGATIVE_INFINITY ); 1.106 + 1.107 +new TestCase( SECTION, "Number.MAX_VALUE % Number.NEGATIVE_INFINITY", Number.MAX_VALUE, Number.MAX_VALUE % Number.NEGATIVE_INFINITY ); 1.108 +new TestCase( SECTION, "Number.MAX_VALUE % Number.POSITIVE_INFINITY", Number.MAX_VALUE, Number.MAX_VALUE % Number.POSITIVE_INFINITY ); 1.109 +new TestCase( SECTION, "-Number.MAX_VALUE % Number.POSITIVE_INFINITY", -Number.MAX_VALUE, -Number.MAX_VALUE % Number.POSITIVE_INFINITY ); 1.110 +new TestCase( SECTION, "-Number.MAX_VALUE % Number.NEGATIVE_INFINITY", -Number.MAX_VALUE, -Number.MAX_VALUE % Number.NEGATIVE_INFINITY ); 1.111 + 1.112 +new TestCase( SECTION, "0 % Number.POSITIVE_INFINITY", 0, 0 % Number.POSITIVE_INFINITY ); 1.113 +new TestCase( SECTION, "0 % Number.NEGATIVE_INFINITY", 0, 0 % Number.NEGATIVE_INFINITY ); 1.114 +new TestCase( SECTION, "-0 % Number.POSITIVE_INFINITY", -0, -0 % Number.POSITIVE_INFINITY ); 1.115 +new TestCase( SECTION, "-0 % Number.NEGATIVE_INFINITY", -0, -0 % Number.NEGATIVE_INFINITY ); 1.116 + 1.117 +// If the dividend is a zero and the divisor is finite, the result is the same as the dividend. 1.118 + 1.119 +new TestCase( SECTION, "0 % 1", 0, 0 % 1 ); 1.120 +new TestCase( SECTION, "0 % -1", -0, 0 % -1 ); 1.121 +new TestCase( SECTION, "-0 % 1", -0, -0 % 1 ); 1.122 +new TestCase( SECTION, "-0 % -1", 0, -0 % -1 ); 1.123 + 1.124 +// In the remaining cases, where neither an infinity, nor a zero, nor NaN is involved, the floating-point remainder r 1.125 +// from a dividend n and a divisor d is defined by the mathematical relation r = n (d * q) where q is an integer that 1.126 +// is negative only if n/d is negative and positive only if n/d is positive, and whose magnitude is as large as 1.127 +// possible without exceeding the magnitude of the true mathematical quotient of n and d. 1.128 + 1.129 +test(); 1.130 +