~ubuntu-branches/ubuntu/saucy/mozjs17/saucy

« back to all changes in this revision

Viewing changes to js/src/tests/ecma/Expressions/11.5.3.js

  • Committer: Package Import Robot
  • Author(s): Rico Tzschichholz
  • Date: 2013-05-25 12:24:23 UTC
  • Revision ID: package-import@ubuntu.com-20130525122423-zmxucrhtensw90xy
Tags: upstream-17.0.0
ImportĀ upstreamĀ versionĀ 17.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
7
/**
 
8
   File Name:          11.5.3.js
 
9
   ECMA Section:       11.5.3 Applying the % operator
 
10
   Description:
 
11
 
 
12
   The binary % operator is said to yield the remainder of its operands from
 
13
   an implied division; the left operand is the dividend and the right operand
 
14
   is the divisor. In C and C++, the remainder operator accepts only integral
 
15
   operands, but in ECMAScript, it also accepts floating-point operands.
 
16
 
 
17
   The result of a floating-point remainder operation as computed by the %
 
18
   operator is not the same as the "remainder" operation defined by IEEE 754.
 
19
   The IEEE 754 "remainder" operation computes the remainder from a rounding
 
20
   division, not a truncating division, and so its behavior is not analogous
 
21
   to that of the usual integer remainder operator. Instead the ECMAScript
 
22
   language defines % on floating-point operations to behave in a manner
 
23
   analogous to that of the Java integer remainder operator; this may be
 
24
   compared with the C library function fmod.
 
25
 
 
26
   The result of a ECMAScript floating-point remainder operation is determined by the rules of IEEE arithmetic:
 
27
 
 
28
   If either operand is NaN, the result is NaN.
 
29
   The sign of the result equals the sign of the dividend.
 
30
   If the dividend is an infinity, or the divisor is a zero, or both, the result is NaN.
 
31
   If the dividend is finite and the divisor is an infinity, the result equals the dividend.
 
32
   If the dividend is a zero and the divisor is finite, the result is the same as the dividend.
 
33
   In the remaining cases, where neither an infinity, nor a zero, nor NaN is involved, the floating-point remainder r
 
34
   from a dividend n and a divisor d is defined by the mathematical relation r = n (d * q) where q is an integer that
 
35
   is negative only if n/d is negative and positive only if n/d is positive, and whose magnitude is as large as
 
36
   possible without exceeding the magnitude of the true mathematical quotient of n and d.
 
37
 
 
38
   Author:             christine@netscape.com
 
39
   Date:               12 november 1997
 
40
*/
 
41
var SECTION = "11.5.3";
 
42
var VERSION = "ECMA_1";
 
43
var BUGNUMBER="111202";
 
44
startTest();
 
45
 
 
46
 
 
47
writeHeaderToLog( SECTION + " Applying the % operator");
 
48
 
 
49
// if either operand is NaN, the result is NaN.
 
50
 
 
51
new TestCase( SECTION,    "Number.NaN % Number.NaN",    Number.NaN,     Number.NaN % Number.NaN );
 
52
new TestCase( SECTION,    "Number.NaN % 1",             Number.NaN,     Number.NaN % 1 );
 
53
new TestCase( SECTION,    "1 % Number.NaN",             Number.NaN,     1 % Number.NaN );
 
54
 
 
55
new TestCase( SECTION,    "Number.POSITIVE_INFINITY % Number.NaN",    Number.NaN,     Number.POSITIVE_INFINITY % Number.NaN );
 
56
new TestCase( SECTION,    "Number.NEGATIVE_INFINITY % Number.NaN",    Number.NaN,     Number.NEGATIVE_INFINITY % Number.NaN );
 
57
 
 
58
//  If the dividend is an infinity, or the divisor is a zero, or both, the result is NaN.
 
59
//  dividend is an infinity
 
60
 
 
61
new TestCase( SECTION,    "Number.NEGATIVE_INFINITY % Number.NEGATIVE_INFINITY",    Number.NaN,   Number.NEGATIVE_INFINITY % Number.NEGATIVE_INFINITY );
 
62
new TestCase( SECTION,    "Number.POSITIVE_INFINITY % Number.NEGATIVE_INFINITY",    Number.NaN,   Number.POSITIVE_INFINITY % Number.NEGATIVE_INFINITY );
 
63
new TestCase( SECTION,    "Number.NEGATIVE_INFINITY % Number.POSITIVE_INFINITY",    Number.NaN,   Number.NEGATIVE_INFINITY % Number.POSITIVE_INFINITY );
 
64
new TestCase( SECTION,    "Number.POSITIVE_INFINITY % Number.POSITIVE_INFINITY",    Number.NaN,   Number.POSITIVE_INFINITY % Number.POSITIVE_INFINITY );
 
65
 
 
66
new TestCase( SECTION,    "Number.POSITIVE_INFINITY % 0",   Number.NaN,     Number.POSITIVE_INFINITY % 0 );
 
67
new TestCase( SECTION,    "Number.NEGATIVE_INFINITY % 0",   Number.NaN,     Number.NEGATIVE_INFINITY % 0 );
 
68
new TestCase( SECTION,    "Number.POSITIVE_INFINITY % -0",  Number.NaN,     Number.POSITIVE_INFINITY % -0 );
 
69
new TestCase( SECTION,    "Number.NEGATIVE_INFINITY % -0",  Number.NaN,     Number.NEGATIVE_INFINITY % -0 );
 
70
 
 
71
new TestCase( SECTION,    "Number.NEGATIVE_INFINITY % 1 ",  Number.NaN,     Number.NEGATIVE_INFINITY % 1 );
 
72
new TestCase( SECTION,    "Number.NEGATIVE_INFINITY % -1 ", Number.NaN,     Number.NEGATIVE_INFINITY % -1 );
 
73
new TestCase( SECTION,    "Number.POSITIVE_INFINITY % 1 ",  Number.NaN,     Number.POSITIVE_INFINITY % 1 );
 
74
new TestCase( SECTION,    "Number.POSITIVE_INFINITY % -1 ", Number.NaN,     Number.POSITIVE_INFINITY % -1 );
 
75
 
 
76
new TestCase( SECTION,    "Number.NEGATIVE_INFINITY % Number.MAX_VALUE ",   Number.NaN,   Number.NEGATIVE_INFINITY % Number.MAX_VALUE );
 
77
new TestCase( SECTION,    "Number.NEGATIVE_INFINITY % -Number.MAX_VALUE ",  Number.NaN,   Number.NEGATIVE_INFINITY % -Number.MAX_VALUE );
 
78
new TestCase( SECTION,    "Number.POSITIVE_INFINITY % Number.MAX_VALUE ",   Number.NaN,   Number.POSITIVE_INFINITY % Number.MAX_VALUE );
 
79
new TestCase( SECTION,    "Number.POSITIVE_INFINITY % -Number.MAX_VALUE ",  Number.NaN,   Number.POSITIVE_INFINITY % -Number.MAX_VALUE );
 
80
 
 
81
// divisor is 0
 
82
new TestCase( SECTION,    "0 % -0",                         Number.NaN,     0 % -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
 
 
87
new TestCase( SECTION,    "1 % 0",                          Number.NaN,   1%0 );
 
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
 
 
92
new TestCase( SECTION,    "Number.MAX_VALUE % 0",           Number.NaN,   Number.MAX_VALUE%0 );
 
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
 
 
97
// If the dividend is finite and the divisor is an infinity, the result equals the dividend.
 
98
 
 
99
new TestCase( SECTION,    "1 % Number.NEGATIVE_INFINITY",   1,              1 % Number.NEGATIVE_INFINITY );
 
100
new TestCase( SECTION,    "1 % Number.POSITIVE_INFINITY",   1,              1 % Number.POSITIVE_INFINITY );
 
101
new TestCase( SECTION,    "-1 % Number.POSITIVE_INFINITY",  -1,             -1 % Number.POSITIVE_INFINITY );
 
102
new TestCase( SECTION,    "-1 % Number.NEGATIVE_INFINITY",  -1,             -1 % Number.NEGATIVE_INFINITY );
 
103
 
 
104
new TestCase( SECTION,    "Number.MAX_VALUE % Number.NEGATIVE_INFINITY",   Number.MAX_VALUE,    Number.MAX_VALUE % Number.NEGATIVE_INFINITY );
 
105
new TestCase( SECTION,    "Number.MAX_VALUE % Number.POSITIVE_INFINITY",   Number.MAX_VALUE,    Number.MAX_VALUE % Number.POSITIVE_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.NEGATIVE_INFINITY",  -Number.MAX_VALUE,   -Number.MAX_VALUE % Number.NEGATIVE_INFINITY );
 
108
 
 
109
new TestCase( SECTION,    "0 % Number.POSITIVE_INFINITY",   0, 0 % Number.POSITIVE_INFINITY );
 
110
new TestCase( SECTION,    "0 % Number.NEGATIVE_INFINITY",   0, 0 % Number.NEGATIVE_INFINITY );
 
111
new TestCase( SECTION,    "-0 % Number.POSITIVE_INFINITY",  -0,   -0 % Number.POSITIVE_INFINITY );
 
112
new TestCase( SECTION,    "-0 % Number.NEGATIVE_INFINITY",  -0,   -0 % Number.NEGATIVE_INFINITY );
 
113
 
 
114
// If the dividend is a zero and the divisor is finite, the result is the same as the dividend.
 
115
 
 
116
new TestCase( SECTION,    "0 % 1",                          0,              0 % 1 );
 
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
 
 
121
//        In the remaining cases, where neither an infinity, nor a zero, nor NaN is involved, the floating-point remainder r
 
122
//      from a dividend n and a divisor d is defined by the mathematical relation r = n (d * q) where q is an integer that
 
123
//      is negative only if n/d is negative and positive only if n/d is positive, and whose magnitude is as large as
 
124
//      possible without exceeding the magnitude of the true mathematical quotient of n and d.
 
125
 
 
126
test();
 
127