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