js/src/tests/ecma/Math/15.8.2.15.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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: 15.8.2.15.js
michael@0 9 ECMA Section: 15.8.2.15 Math.round(x)
michael@0 10 Description: return the greatest number value that is closest to the
michael@0 11 argument and is an integer. if two integers are equally
michael@0 12 close to the argument. then the result is the number value
michael@0 13 that is closer to Infinity. if the argument is an integer,
michael@0 14 return the argument.
michael@0 15 special cases:
michael@0 16 - if x is NaN return NaN
michael@0 17 - if x = +0 return +0
michael@0 18 - if x = -0 return -0
michael@0 19 - if x = Infinity return Infinity
michael@0 20 - if x = -Infinity return -Infinity
michael@0 21 - if 0 < x < 0.5 return 0
michael@0 22 - if -0.5 <= x < 0 return -0
michael@0 23 example:
michael@0 24 Math.round( 3.5 ) == 4
michael@0 25 Math.round( -3.5 ) == 3
michael@0 26 also:
michael@0 27 - Math.round(x) == Math.floor( x + 0.5 )
michael@0 28 except if x = -0. in that case, Math.round(x) = -0
michael@0 29
michael@0 30 and Math.floor( x+0.5 ) = +0
michael@0 31
michael@0 32
michael@0 33 Author: christine@netscape.com
michael@0 34 Date: 7 july 1997
michael@0 35 */
michael@0 36
michael@0 37 var SECTION = "15.8.2.15";
michael@0 38 var VERSION = "ECMA_1";
michael@0 39 var TITLE = "Math.round(x)";
michael@0 40 var BUGNUMBER="331411";
michael@0 41
michael@0 42 var EXCLUDE = "true";
michael@0 43
michael@0 44 startTest();
michael@0 45
michael@0 46 writeHeaderToLog( SECTION + " "+ TITLE);
michael@0 47
michael@0 48 new TestCase( SECTION,
michael@0 49 "Math.round.length",
michael@0 50 1,
michael@0 51 Math.round.length );
michael@0 52
michael@0 53 new TestCase( SECTION,
michael@0 54 "Math.round()",
michael@0 55 Number.NaN,
michael@0 56 Math.round() );
michael@0 57
michael@0 58 new TestCase( SECTION,
michael@0 59 "Math.round(null)",
michael@0 60 0,
michael@0 61 Math.round(0) );
michael@0 62
michael@0 63 new TestCase( SECTION,
michael@0 64 "Math.round(void 0)",
michael@0 65 Number.NaN,
michael@0 66 Math.round(void 0) );
michael@0 67
michael@0 68 new TestCase( SECTION,
michael@0 69 "Math.round(true)",
michael@0 70 1,
michael@0 71 Math.round(true) );
michael@0 72
michael@0 73 new TestCase( SECTION,
michael@0 74 "Math.round(false)",
michael@0 75 0,
michael@0 76 Math.round(false) );
michael@0 77
michael@0 78 new TestCase( SECTION,
michael@0 79 "Math.round('.99999')",
michael@0 80 1,
michael@0 81 Math.round('.99999') );
michael@0 82
michael@0 83 new TestCase( SECTION,
michael@0 84 "Math.round('12345e-2')",
michael@0 85 123,
michael@0 86 Math.round('12345e-2') );
michael@0 87
michael@0 88 new TestCase( SECTION,
michael@0 89 "Math.round(NaN)",
michael@0 90 Number.NaN,
michael@0 91 Math.round(Number.NaN) );
michael@0 92
michael@0 93 new TestCase( SECTION,
michael@0 94 "Math.round(0)",
michael@0 95 0,
michael@0 96 Math.round(0) );
michael@0 97
michael@0 98 new TestCase( SECTION,
michael@0 99 "Math.round(-0)",
michael@0 100 -0,
michael@0 101 Math.round(-0));
michael@0 102
michael@0 103 new TestCase( SECTION,
michael@0 104 "Infinity/Math.round(-0)",
michael@0 105 -Infinity,
michael@0 106 Infinity/Math.round(-0) );
michael@0 107
michael@0 108 new TestCase( SECTION,
michael@0 109 "Math.round(Infinity)",
michael@0 110 Number.POSITIVE_INFINITY,
michael@0 111 Math.round(Number.POSITIVE_INFINITY));
michael@0 112
michael@0 113 new TestCase( SECTION,
michael@0 114 "Math.round(-Infinity)",
michael@0 115 Number.NEGATIVE_INFINITY,
michael@0 116 Math.round(Number.NEGATIVE_INFINITY));
michael@0 117
michael@0 118 new TestCase( SECTION,
michael@0 119 "Math.round(0.49)",
michael@0 120 0,
michael@0 121 Math.round(0.49));
michael@0 122
michael@0 123 new TestCase( SECTION,
michael@0 124 "Math.round(0.5)",
michael@0 125 1,
michael@0 126 Math.round(0.5));
michael@0 127
michael@0 128 new TestCase( SECTION,
michael@0 129 "Math.round(0.51)",
michael@0 130 1,
michael@0 131 Math.round(0.51));
michael@0 132
michael@0 133 new TestCase( SECTION,
michael@0 134 "Math.round(-0.49)",
michael@0 135 -0,
michael@0 136 Math.round(-0.49));
michael@0 137
michael@0 138 new TestCase( SECTION,
michael@0 139 "Math.round(-0.5)",
michael@0 140 -0,
michael@0 141 Math.round(-0.5));
michael@0 142
michael@0 143 new TestCase( SECTION,
michael@0 144 "Infinity/Math.round(-0.49)",
michael@0 145 -Infinity,
michael@0 146 Infinity/Math.round(-0.49));
michael@0 147
michael@0 148 new TestCase( SECTION,
michael@0 149 "Infinity/Math.round(-0.5)",
michael@0 150 -Infinity,
michael@0 151 Infinity/Math.round(-0.5));
michael@0 152
michael@0 153 new TestCase( SECTION,
michael@0 154 "Math.round(-0.51)",
michael@0 155 -1,
michael@0 156 Math.round(-0.51));
michael@0 157
michael@0 158 new TestCase( SECTION,
michael@0 159 "Math.round(3.5)",
michael@0 160 4,
michael@0 161 Math.round(3.5));
michael@0 162
michael@0 163 new TestCase( SECTION,
michael@0 164 "Math.round(-3.5)",
michael@0 165 -3,
michael@0 166 Math.round(-3));
michael@0 167
michael@0 168 test();

mercurial