Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma / Expressions / 11.5.3.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is Mozilla Communicator client code, released
16  * March 31, 1998.
17  *
18  * The Initial Developer of the Original Code is
19  * Netscape Communications Corporation.
20  * Portions created by the Initial Developer are Copyright (C) 1998
21  * the Initial Developer. All Rights Reserved.
22  *
23  * Contributor(s):
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39
40 /**
41    File Name:          11.5.3.js
42    ECMA Section:       11.5.3 Applying the % operator
43    Description:
44
45    The binary % operator is said to yield the remainder of its operands from
46    an implied division; the left operand is the dividend and the right operand
47    is the divisor. In C and C++, the remainder operator accepts only integral
48    operands, but in ECMAScript, it also accepts floating-point operands.
49
50    The result of a floating-point remainder operation as computed by the %
51    operator is not the same as the "remainder" operation defined by IEEE 754.
52    The IEEE 754 "remainder" operation computes the remainder from a rounding
53    division, not a truncating division, and so its behavior is not analogous
54    to that of the usual integer remainder operator. Instead the ECMAScript
55    language defines % on floating-point operations to behave in a manner
56    analogous to that of the Java integer remainder operator; this may be
57    compared with the C library function fmod.
58
59    The result of a ECMAScript floating-point remainder operation is determined by the rules of IEEE arithmetic:
60
61    If either operand is NaN, the result is NaN.
62    The sign of the result equals the sign of the dividend.
63    If the dividend is an infinity, or the divisor is a zero, or both, the result is NaN.
64    If the dividend is finite and the divisor is an infinity, the result equals the dividend.
65    If the dividend is a zero and the divisor is finite, the result is the same as the dividend.
66    In the remaining cases, where neither an infinity, nor a zero, nor NaN is involved, the floating-point remainder r
67    from a dividend n and a divisor d is defined by the mathematical relation r = n (d * q) where q is an integer that
68    is negative only if n/d is negative and positive only if n/d is positive, and whose magnitude is as large as
69    possible without exceeding the magnitude of the true mathematical quotient of n and d.
70
71    Author:             christine@netscape.com
72    Date:               12 november 1997
73 */
74 var SECTION = "11.5.3";
75 var VERSION = "ECMA_1";
76 var BUGNUMBER="111202";
77 startTest();
78
79
80 writeHeaderToLog( SECTION + " Applying the % operator");
81
82 // if either operand is NaN, the result is NaN.
83
84 new TestCase( SECTION,    "Number.NaN % Number.NaN",    Number.NaN,     Number.NaN % Number.NaN );
85 new TestCase( SECTION,    "Number.NaN % 1",             Number.NaN,     Number.NaN % 1 );
86 new TestCase( SECTION,    "1 % Number.NaN",             Number.NaN,     1 % Number.NaN );
87
88 new TestCase( SECTION,    "Number.POSITIVE_INFINITY % Number.NaN",    Number.NaN,     Number.POSITIVE_INFINITY % Number.NaN );
89 new TestCase( SECTION,    "Number.NEGATIVE_INFINITY % Number.NaN",    Number.NaN,     Number.NEGATIVE_INFINITY % Number.NaN );
90
91 //  If the dividend is an infinity, or the divisor is a zero, or both, the result is NaN.
92 //  dividend is an infinity
93
94 new TestCase( SECTION,    "Number.NEGATIVE_INFINITY % Number.NEGATIVE_INFINITY",    Number.NaN,   Number.NEGATIVE_INFINITY % Number.NEGATIVE_INFINITY );
95 new TestCase( SECTION,    "Number.POSITIVE_INFINITY % Number.NEGATIVE_INFINITY",    Number.NaN,   Number.POSITIVE_INFINITY % Number.NEGATIVE_INFINITY );
96 new TestCase( SECTION,    "Number.NEGATIVE_INFINITY % Number.POSITIVE_INFINITY",    Number.NaN,   Number.NEGATIVE_INFINITY % Number.POSITIVE_INFINITY );
97 new TestCase( SECTION,    "Number.POSITIVE_INFINITY % Number.POSITIVE_INFINITY",    Number.NaN,   Number.POSITIVE_INFINITY % Number.POSITIVE_INFINITY );
98
99 new TestCase( SECTION,    "Number.POSITIVE_INFINITY % 0",   Number.NaN,     Number.POSITIVE_INFINITY % 0 );
100 new TestCase( SECTION,    "Number.NEGATIVE_INFINITY % 0",   Number.NaN,     Number.NEGATIVE_INFINITY % 0 );
101 new TestCase( SECTION,    "Number.POSITIVE_INFINITY % -0",  Number.NaN,     Number.POSITIVE_INFINITY % -0 );
102 new TestCase( SECTION,    "Number.NEGATIVE_INFINITY % -0",  Number.NaN,     Number.NEGATIVE_INFINITY % -0 );
103
104 new TestCase( SECTION,    "Number.NEGATIVE_INFINITY % 1 ",  Number.NaN,     Number.NEGATIVE_INFINITY % 1 );
105 new TestCase( SECTION,    "Number.NEGATIVE_INFINITY % -1 ", Number.NaN,     Number.NEGATIVE_INFINITY % -1 );
106 new TestCase( SECTION,    "Number.POSITIVE_INFINITY % 1 ",  Number.NaN,     Number.POSITIVE_INFINITY % 1 );
107 new TestCase( SECTION,    "Number.POSITIVE_INFINITY % -1 ", Number.NaN,     Number.POSITIVE_INFINITY % -1 );
108
109 new TestCase( SECTION,    "Number.NEGATIVE_INFINITY % Number.MAX_VALUE ",   Number.NaN,   Number.NEGATIVE_INFINITY % Number.MAX_VALUE );
110 new TestCase( SECTION,    "Number.NEGATIVE_INFINITY % -Number.MAX_VALUE ",  Number.NaN,   Number.NEGATIVE_INFINITY % -Number.MAX_VALUE );
111 new TestCase( SECTION,    "Number.POSITIVE_INFINITY % Number.MAX_VALUE ",   Number.NaN,   Number.POSITIVE_INFINITY % Number.MAX_VALUE );
112 new TestCase( SECTION,    "Number.POSITIVE_INFINITY % -Number.MAX_VALUE ",  Number.NaN,   Number.POSITIVE_INFINITY % -Number.MAX_VALUE );
113
114 // divisor is 0
115 new TestCase( SECTION,    "0 % -0",                         Number.NaN,     0 % -0 );
116 new TestCase( SECTION,    "-0 % 0",                         Number.NaN,     -0 % 0 );
117 new TestCase( SECTION,    "-0 % -0",                        Number.NaN,     -0 % -0 );
118 new TestCase( SECTION,    "0 % 0",                          Number.NaN,     0 % 0 );
119
120 new TestCase( SECTION,    "1 % 0",                          Number.NaN,   1%0 );
121 new TestCase( SECTION,    "1 % -0",                         Number.NaN,   1%-0 );
122 new TestCase( SECTION,    "-1 % 0",                         Number.NaN,   -1%0 );
123 new TestCase( SECTION,    "-1 % -0",                        Number.NaN,   -1%-0 );
124
125 new TestCase( SECTION,    "Number.MAX_VALUE % 0",           Number.NaN,   Number.MAX_VALUE%0 );
126 new TestCase( SECTION,    "Number.MAX_VALUE % -0",          Number.NaN,   Number.MAX_VALUE%-0 );
127 new TestCase( SECTION,    "-Number.MAX_VALUE % 0",          Number.NaN,   -Number.MAX_VALUE%0 );
128 new TestCase( SECTION,    "-Number.MAX_VALUE % -0",         Number.NaN,   -Number.MAX_VALUE%-0 );
129
130 // If the dividend is finite and the divisor is an infinity, the result equals the dividend.
131
132 new TestCase( SECTION,    "1 % Number.NEGATIVE_INFINITY",   1,              1 % Number.NEGATIVE_INFINITY );
133 new TestCase( SECTION,    "1 % Number.POSITIVE_INFINITY",   1,              1 % Number.POSITIVE_INFINITY );
134 new TestCase( SECTION,    "-1 % Number.POSITIVE_INFINITY",  -1,             -1 % Number.POSITIVE_INFINITY );
135 new TestCase( SECTION,    "-1 % Number.NEGATIVE_INFINITY",  -1,             -1 % Number.NEGATIVE_INFINITY );
136
137 new TestCase( SECTION,    "Number.MAX_VALUE % Number.NEGATIVE_INFINITY",   Number.MAX_VALUE,    Number.MAX_VALUE % Number.NEGATIVE_INFINITY );
138 new TestCase( SECTION,    "Number.MAX_VALUE % Number.POSITIVE_INFINITY",   Number.MAX_VALUE,    Number.MAX_VALUE % Number.POSITIVE_INFINITY );
139 new TestCase( SECTION,    "-Number.MAX_VALUE % Number.POSITIVE_INFINITY",  -Number.MAX_VALUE,   -Number.MAX_VALUE % Number.POSITIVE_INFINITY );
140 new TestCase( SECTION,    "-Number.MAX_VALUE % Number.NEGATIVE_INFINITY",  -Number.MAX_VALUE,   -Number.MAX_VALUE % Number.NEGATIVE_INFINITY );
141
142 new TestCase( SECTION,    "0 % Number.POSITIVE_INFINITY",   0, 0 % Number.POSITIVE_INFINITY );
143 new TestCase( SECTION,    "0 % Number.NEGATIVE_INFINITY",   0, 0 % Number.NEGATIVE_INFINITY );
144 new TestCase( SECTION,    "-0 % Number.POSITIVE_INFINITY",  -0,   -0 % Number.POSITIVE_INFINITY );
145 new TestCase( SECTION,    "-0 % Number.NEGATIVE_INFINITY",  -0,   -0 % Number.NEGATIVE_INFINITY );
146
147 // If the dividend is a zero and the divisor is finite, the result is the same as the dividend.
148
149 new TestCase( SECTION,    "0 % 1",                          0,              0 % 1 );
150 new TestCase( SECTION,    "0 % -1",                        -0,              0 % -1 );
151 new TestCase( SECTION,    "-0 % 1",                        -0,              -0 % 1 );
152 new TestCase( SECTION,    "-0 % -1",                       0,               -0 % -1 );
153
154 //        In the remaining cases, where neither an infinity, nor a zero, nor NaN is involved, the floating-point remainder r
155 //      from a dividend n and a divisor d is defined by the mathematical relation r = n (d * q) where q is an integer that
156 //      is negative only if n/d is negative and positive only if n/d is positive, and whose magnitude is as large as
157 //      possible without exceeding the magnitude of the true mathematical quotient of n and d.
158
159 test();
160