ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | |
| 29 | // Keep reference to original values of some global properties. This |
| 30 | // has the added benefit that the code in this file is isolated from |
| 31 | // changes to these properties. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 32 | const $floor = MathFloor; |
| 33 | const $random = MathRandom; |
| 34 | const $abs = MathAbs; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 35 | |
| 36 | // Instance class name can only be set on functions. That is the only |
| 37 | // purpose for MathConstructor. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 38 | function MathConstructor() {} |
| 39 | %FunctionSetInstanceClassName(MathConstructor, 'Math'); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | const $Math = new MathConstructor(); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame^] | 41 | $Math.__proto__ = $Object.prototype; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 42 | %SetProperty(global, "Math", $Math, DONT_ENUM); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 43 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 44 | // ECMA 262 - 15.8.2.1 |
| 45 | function MathAbs(x) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 46 | if (%_IsSmi(x)) return x >= 0 ? x : -x; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 47 | if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 48 | if (x === 0) return 0; // To handle -0. |
| 49 | return x > 0 ? x : -x; |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 50 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 51 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 52 | // ECMA 262 - 15.8.2.2 |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 53 | function MathAcos(x) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 54 | if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 55 | return %Math_acos(x); |
| 56 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 57 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 58 | // ECMA 262 - 15.8.2.3 |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 59 | function MathAsin(x) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 60 | if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 61 | return %Math_asin(x); |
| 62 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 63 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 64 | // ECMA 262 - 15.8.2.4 |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 65 | function MathAtan(x) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 66 | if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 67 | return %Math_atan(x); |
| 68 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 69 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 70 | // ECMA 262 - 15.8.2.5 |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 71 | // The naming of y and x matches the spec, as does the order in which |
| 72 | // ToNumber (valueOf) is called. |
| 73 | function MathAtan2(y, x) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 74 | if (!IS_NUMBER(y)) y = NonNumberToNumber(y); |
| 75 | if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 76 | return %Math_atan2(y, x); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 77 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 78 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 79 | // ECMA 262 - 15.8.2.6 |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 80 | function MathCeil(x) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 81 | if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 82 | return %Math_ceil(x); |
| 83 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 84 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 85 | // ECMA 262 - 15.8.2.7 |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 86 | function MathCos(x) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 87 | if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 88 | return %_MathCos(x); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 89 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 90 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 91 | // ECMA 262 - 15.8.2.8 |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 92 | function MathExp(x) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 93 | if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 94 | return %Math_exp(x); |
| 95 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 96 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 97 | // ECMA 262 - 15.8.2.9 |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 98 | function MathFloor(x) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 99 | if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 100 | // It's more common to call this with a positive number that's out |
| 101 | // of range than negative numbers; check the upper bound first. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 102 | if (x < 0x80000000 && x > 0) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 103 | // Numbers in the range [0, 2^31) can be floored by converting |
| 104 | // them to an unsigned 32-bit value using the shift operator. |
| 105 | // We avoid doing so for -0, because the result of Math.floor(-0) |
| 106 | // has to be -0, which wouldn't be the case with the shift. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 107 | return TO_UINT32(x); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 108 | } else { |
| 109 | return %Math_floor(x); |
| 110 | } |
| 111 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 112 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 113 | // ECMA 262 - 15.8.2.10 |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 114 | function MathLog(x) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 115 | if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 116 | return %_MathLog(x); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 117 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 118 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 119 | // ECMA 262 - 15.8.2.11 |
| 120 | function MathMax(arg1, arg2) { // length == 2 |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 121 | var length = %_ArgumentsLength(); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 122 | if (length == 0) { |
| 123 | return -1/0; // Compiler constant-folds this to -Infinity. |
| 124 | } |
| 125 | var r = arg1; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 126 | if (!IS_NUMBER(r)) r = NonNumberToNumber(r); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 127 | if (NUMBER_IS_NAN(r)) return r; |
| 128 | for (var i = 1; i < length; i++) { |
| 129 | var n = %_Arguments(i); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 130 | if (!IS_NUMBER(n)) n = NonNumberToNumber(n); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 131 | if (NUMBER_IS_NAN(n)) return n; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 132 | // Make sure +0 is considered greater than -0. -0 is never a Smi, +0 can be |
| 133 | // a Smi or heap number. |
| 134 | if (n > r || (r === 0 && n === 0 && !%_IsSmi(r) && 1 / r < 0)) r = n; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 135 | } |
| 136 | return r; |
| 137 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 138 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 139 | // ECMA 262 - 15.8.2.12 |
| 140 | function MathMin(arg1, arg2) { // length == 2 |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 141 | var length = %_ArgumentsLength(); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 142 | if (length == 0) { |
| 143 | return 1/0; // Compiler constant-folds this to Infinity. |
| 144 | } |
| 145 | var r = arg1; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 146 | if (!IS_NUMBER(r)) r = NonNumberToNumber(r); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 147 | if (NUMBER_IS_NAN(r)) return r; |
| 148 | for (var i = 1; i < length; i++) { |
| 149 | var n = %_Arguments(i); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 150 | if (!IS_NUMBER(n)) n = NonNumberToNumber(n); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 151 | if (NUMBER_IS_NAN(n)) return n; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 152 | // Make sure -0 is considered less than +0. -0 is never a Smi, +0 can b a |
| 153 | // Smi or a heap number. |
| 154 | if (n < r || (r === 0 && n === 0 && !%_IsSmi(n) && 1 / n < 0)) r = n; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 155 | } |
| 156 | return r; |
| 157 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 158 | |
| 159 | // ECMA 262 - 15.8.2.13 |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 160 | function MathPow(x, y) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 161 | if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
| 162 | if (!IS_NUMBER(y)) y = NonNumberToNumber(y); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 163 | return %_MathPow(x, y); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 164 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 165 | |
| 166 | // ECMA 262 - 15.8.2.14 |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 167 | function MathRandom() { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 168 | return %_RandomHeapNumber(); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 169 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 170 | |
| 171 | // ECMA 262 - 15.8.2.15 |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 172 | function MathRound(x) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 173 | if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 174 | return %RoundNumber(x); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 175 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 176 | |
| 177 | // ECMA 262 - 15.8.2.16 |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 178 | function MathSin(x) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 179 | if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 180 | return %_MathSin(x); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 181 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 182 | |
| 183 | // ECMA 262 - 15.8.2.17 |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 184 | function MathSqrt(x) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 185 | if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 186 | return %_MathSqrt(x); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 187 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 188 | |
| 189 | // ECMA 262 - 15.8.2.18 |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 190 | function MathTan(x) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 191 | if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 192 | return %Math_tan(x); |
| 193 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 194 | |
| 195 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 196 | // ------------------------------------------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 197 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame^] | 198 | function SetUpMath() { |
| 199 | %CheckIsBootstrapping(); |
| 200 | // Set up math constants. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 201 | // ECMA-262, section 15.8.1.1. |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 202 | %OptimizeObjectForAddingMultipleProperties($Math, 8); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 203 | %SetProperty($Math, |
| 204 | "E", |
| 205 | 2.7182818284590452354, |
| 206 | DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 207 | // ECMA-262, section 15.8.1.2. |
| 208 | %SetProperty($Math, |
| 209 | "LN10", |
| 210 | 2.302585092994046, |
| 211 | DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 212 | // ECMA-262, section 15.8.1.3. |
| 213 | %SetProperty($Math, |
| 214 | "LN2", |
| 215 | 0.6931471805599453, |
| 216 | DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 217 | // ECMA-262, section 15.8.1.4. |
| 218 | %SetProperty($Math, |
| 219 | "LOG2E", |
| 220 | 1.4426950408889634, |
| 221 | DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 222 | %SetProperty($Math, |
| 223 | "LOG10E", |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 224 | 0.4342944819032518, |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 225 | DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 226 | %SetProperty($Math, |
| 227 | "PI", |
| 228 | 3.1415926535897932, |
| 229 | DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 230 | %SetProperty($Math, |
| 231 | "SQRT1_2", |
| 232 | 0.7071067811865476, |
| 233 | DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 234 | %SetProperty($Math, |
| 235 | "SQRT2", |
| 236 | 1.4142135623730951, |
| 237 | DONT_ENUM | DONT_DELETE | READ_ONLY); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 238 | %ToFastProperties($Math); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 239 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame^] | 240 | // Set up non-enumerable functions of the Math object and |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 241 | // set their names. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 242 | InstallFunctionsOnHiddenPrototype($Math, DONT_ENUM, $Array( |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 243 | "random", MathRandom, |
| 244 | "abs", MathAbs, |
| 245 | "acos", MathAcos, |
| 246 | "asin", MathAsin, |
| 247 | "atan", MathAtan, |
| 248 | "ceil", MathCeil, |
| 249 | "cos", MathCos, |
| 250 | "exp", MathExp, |
| 251 | "floor", MathFloor, |
| 252 | "log", MathLog, |
| 253 | "round", MathRound, |
| 254 | "sin", MathSin, |
| 255 | "sqrt", MathSqrt, |
| 256 | "tan", MathTan, |
| 257 | "atan2", MathAtan2, |
| 258 | "pow", MathPow, |
| 259 | "max", MathMax, |
| 260 | "min", MathMin |
| 261 | )); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame^] | 262 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 263 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame^] | 264 | SetUpMath(); |