Debian Codegraph @

rhino/testsrc/tests/ecma/Expressions/11.5.3.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 gTestfile = '11.5.3.js';
7
8 /**
9 File Name: 11.5.3.js
10 ECMA Section: 11.5.3 Applying the % operator
11 Description:
12
13 The binary % operator is said to yield the remainder of its operands from
14 an implied division; the left operand is the dividend and the right operand
15 is the divisor. In C and C++, the remainder operator accepts only integral
16 operands, but in ECMAScript, it also accepts floating-point operands.
17
18 The result of a floating-point remainder operation as computed by the %
19 operator is not the same as the "remainder" operation defined by IEEE 754.
20 The IEEE 754 "remainder" operation computes the remainder from a rounding
21 division, not a truncating division, and so its behavior is not analogous
22 to that of the usual integer remainder operator. Instead the ECMAScript
23 language defines % on floating-point operations to behave in a manner
24 analogous to that of the Java integer remainder operator; this may be
25 compared with the C library function fmod.
26
27 The result of a ECMAScript floating-point remainder operation is determined by the rules of IEEE arithmetic:
28
29 If either operand is NaN, the result is NaN.
30 The sign of the result equals the sign of the dividend.
31 If the dividend is an infinity, or the divisor is a zero, or both, the result is NaN.
32 If the dividend is finite and the divisor is an infinity, the result equals the dividend.
33 If the dividend is a zero and the divisor is finite, the result is the same as the dividend.
34 In the remaining cases, where neither an infinity, nor a zero, nor NaN is involved, the floating-point remainder r
35 from a dividend n and a divisor d is defined by the mathematical relation r = n (d * q) where q is an integer that
36 is negative only if n/d is negative and positive only if n/d is positive, and whose magnitude is as large as
37 possible without exceeding the magnitude of the true mathematical quotient of n and d.
38
39 Author: [email protected]
40 Date: 12 november 1997
41 */
42 var SECTION = "11.5.3";
43 var VERSION = "ECMA_1";
44 var BUGNUMBER="111202";
45 startTest();
46
47
48 writeHeaderToLog( SECTION + " Applying the % operator");
49
50 // if either operand is NaN, the result is NaN.
51
52 new TestCase( SECTION, "Number.NaN % Number.NaN", Number.NaN, Number.NaN % Number.NaN );
53 new TestCase( SECTION, "Number.NaN % 1", Number.NaN, Number.NaN % 1 );
54 new TestCase( SECTION, "1 % Number.NaN", Number.NaN, 1 % Number.NaN );
55
56 new TestCase( SECTION, "Number.POSITIVE_INFINITY % Number.NaN", Number.NaN, Number.POSITIVE_INFINITY % Number.NaN );
57 new TestCase( SECTION, "Number.NEGATIVE_INFINITY % Number.NaN", Number.NaN, Number.NEGATIVE_INFINITY % Number.NaN );
58
59 // If the dividend is an infinity, or the divisor is a zero, or both, the result is NaN.
60 // dividend is an infinity
61
62 new TestCase( SECTION, "Number.NEGATIVE_INFINITY % Number.NEGATIVE_INFINITY", Number.NaN, Number.NEGATIVE_INFINITY % Number.NEGATIVE_INFINITY );
63 new TestCase( SECTION, "Number.POSITIVE_INFINITY % Number.NEGATIVE_INFINITY", Number.NaN, Number.POSITIVE_INFINITY % Number.NEGATIVE_INFINITY );
64 new TestCase( SECTION, "Number.NEGATIVE_INFINITY % Number.POSITIVE_INFINITY", Number.NaN, Number.NEGATIVE_INFINITY % Number.POSITIVE_INFINITY );
65 new TestCase( SECTION, "Number.POSITIVE_INFINITY % Number.POSITIVE_INFINITY", Number.NaN, Number.POSITIVE_INFINITY % Number.POSITIVE_INFINITY );
66
67 new TestCase( SECTION, "Number.POSITIVE_INFINITY % 0", Number.NaN, Number.POSITIVE_INFINITY % 0 );
68 new TestCase( SECTION, "Number.NEGATIVE_INFINITY % 0", Number.NaN, Number.NEGATIVE_INFINITY % 0 );
69 new TestCase( SECTION, "Number.POSITIVE_INFINITY % -0", Number.NaN, Number.POSITIVE_INFINITY % -0 );
70 new TestCase( SECTION, "Number.NEGATIVE_INFINITY % -0", Number.NaN, Number.NEGATIVE_INFINITY % -0 );
71
72 new TestCase( SECTION, "Number.NEGATIVE_INFINITY % 1 ", Number.NaN, Number.NEGATIVE_INFINITY % 1 );
73 new TestCase( SECTION, "Number.NEGATIVE_INFINITY % -1 ", Number.NaN, Number.NEGATIVE_INFINITY % -1 );
74 new TestCase( SECTION, "Number.POSITIVE_INFINITY % 1 ", Number.NaN, Number.POSITIVE_INFINITY % 1 );
75 new TestCase( SECTION, "Number.POSITIVE_INFINITY % -1 ", Number.NaN, Number.POSITIVE_INFINITY % -1 );
76
77 new TestCase( SECTION, "Number.NEGATIVE_INFINITY % Number.MAX_VALUE ", Number.NaN, Number.NEGATIVE_INFINITY % Number.MAX_VALUE );
78 new TestCase( SECTION, "Number.NEGATIVE_INFINITY % -Number.MAX_VALUE ", Number.NaN, Number.NEGATIVE_INFINITY % -Number.MAX_VALUE );
79 new TestCase( SECTION, "Number.POSITIVE_INFINITY % Number.MAX_VALUE ", Number.NaN, Number.POSITIVE_INFINITY % Number.MAX_VALUE );
80 new TestCase( SECTION, "Number.POSITIVE_INFINITY % -Number.MAX_VALUE ", Number.NaN, Number.POSITIVE_INFINITY % -Number.MAX_VALUE );
81
82 // divisor is 0
83 new TestCase( SECTION, "0 % -0", Number.NaN, 0 % -0 );
84 new TestCase( SECTION, "-0 % 0", Number.NaN, -0 % 0 );
85 new TestCase( SECTION, "-0 % -0", Number.NaN, -0 % -0 );
86 new TestCase( SECTION, "0 % 0", Number.NaN, 0 % 0 );
87
88 new TestCase( SECTION, "1 % 0", Number.NaN, 1%0 );
89 new TestCase( SECTION, "1 % -0", Number.NaN, 1%-0 );
90 new TestCase( SECTION, "-1 % 0", Number.NaN, -1%0 );
91 new TestCase( SECTION, "-1 % -0", Number.NaN, -1%-0 );
92
93 new TestCase( SECTION, "Number.MAX_VALUE % 0", Number.NaN, Number.MAX_VALUE%0 );
94 new TestCase( SECTION, "Number.MAX_VALUE % -0", Number.NaN, Number.MAX_VALUE%-0 );
95 new TestCase( SECTION, "-Number.MAX_VALUE % 0", Number.NaN, -Number.MAX_VALUE%0 );
96 new TestCase( SECTION, "-Number.MAX_VALUE % -0", Number.NaN, -Number.MAX_VALUE%-0 );
97
98 // If the dividend is finite and the divisor is an infinity, the result equals the dividend.
99
100 new TestCase( SECTION, "1 % Number.NEGATIVE_INFINITY", 1, 1 % Number.NEGATIVE_INFINITY );
101 new TestCase( SECTION, "1 % Number.POSITIVE_INFINITY", 1, 1 % Number.POSITIVE_INFINITY );
102 new TestCase( SECTION, "-1 % Number.POSITIVE_INFINITY", -1, -1 % Number.POSITIVE_INFINITY );
103 new TestCase( SECTION, "-1 % Number.NEGATIVE_INFINITY", -1, -1 % Number.NEGATIVE_INFINITY );
104
105 new TestCase( SECTION, "Number.MAX_VALUE % Number.NEGATIVE_INFINITY", Number.MAX_VALUE, Number.MAX_VALUE % Number.NEGATIVE_INFINITY );
106 new TestCase( SECTION, "Number.MAX_VALUE % Number.POSITIVE_INFINITY", Number.MAX_VALUE, Number.MAX_VALUE % Number.POSITIVE_INFINITY );
107 new TestCase( SECTION, "-Number.MAX_VALUE % Number.POSITIVE_INFINITY", -Number.MAX_VALUE, -Number.MAX_VALUE % Number.POSITIVE_INFINITY );
108 new TestCase( SECTION, "-Number.MAX_VALUE % Number.NEGATIVE_INFINITY", -Number.MAX_VALUE, -Number.MAX_VALUE % Number.NEGATIVE_INFINITY );
109
110 new TestCase( SECTION, "0 % Number.POSITIVE_INFINITY", 0, 0 % Number.POSITIVE_INFINITY );
111 new TestCase( SECTION, "0 % Number.NEGATIVE_INFINITY", 0, 0 % Number.NEGATIVE_INFINITY );
112 new TestCase( SECTION, "-0 % Number.POSITIVE_INFINITY", -0, -0 % Number.POSITIVE_INFINITY );
113 new TestCase( SECTION, "-0 % Number.NEGATIVE_INFINITY", -0, -0 % Number.NEGATIVE_INFINITY );
114
115 // If the dividend is a zero and the divisor is finite, the result is the same as the dividend.
116
117 new TestCase( SECTION, "0 % 1", 0, 0 % 1 );
118 new TestCase( SECTION, "0 % -1", -0, 0 % -1 );
119 new TestCase( SECTION, "-0 % 1", -0, -0 % 1 );
120 new TestCase( SECTION, "-0 % -1", 0, -0 % -1 );
121
122 // In the remaining cases, where neither an infinity, nor a zero, nor NaN is involved, the floating-point remainder r
123 // from a dividend n and a divisor d is defined by the mathematical relation r = n (d * q) where q is an integer that
124 // is negative only if n/d is negative and positive only if n/d is positive, and whose magnitude is as large as
125 // possible without exceeding the magnitude of the true mathematical quotient of n and d.
126
127 test();
128