| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 (function(global, utils) { | 5 (function(global, utils) { |
| 6 "use strict"; | 6 "use strict"; |
| 7 | 7 |
| 8 %CheckIsBootstrapping(); | 8 %CheckIsBootstrapping(); |
| 9 | 9 |
| 10 // ------------------------------------------------------------------- | 10 // ------------------------------------------------------------------- |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); | 24 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); |
| 25 | 25 |
| 26 //------------------------------------------------------------------- | 26 //------------------------------------------------------------------- |
| 27 | 27 |
| 28 // ECMA 262 - 15.8.2.1 | 28 // ECMA 262 - 15.8.2.1 |
| 29 function MathAbs(x) { | 29 function MathAbs(x) { |
| 30 x = +x; | 30 x = +x; |
| 31 return (x > 0) ? x : 0 - x; | 31 return (x > 0) ? x : 0 - x; |
| 32 } | 32 } |
| 33 | 33 |
| 34 // ECMA 262 - 15.8.2.2 | |
| 35 function MathAcosJS(x) { | |
| 36 return %_MathAcos(+x); | |
| 37 } | |
| 38 | |
| 39 // ECMA 262 - 15.8.2.3 | |
| 40 function MathAsinJS(x) { | |
| 41 return %_MathAsin(+x); | |
| 42 } | |
| 43 | |
| 44 // ECMA 262 - 15.8.2.4 | |
| 45 function MathAtanJS(x) { | |
| 46 return %_MathAtan(+x); | |
| 47 } | |
| 48 | |
| 49 // ECMA 262 - 15.8.2.5 | 34 // ECMA 262 - 15.8.2.5 |
| 50 // The naming of y and x matches the spec, as does the order in which | 35 // The naming of y and x matches the spec, as does the order in which |
| 51 // ToNumber (valueOf) is called. | 36 // ToNumber (valueOf) is called. |
| 52 function MathAtan2JS(y, x) { | 37 function MathAtan2JS(y, x) { |
| 53 y = +y; | 38 y = +y; |
| 54 x = +x; | 39 x = +x; |
| 55 return %_MathAtan2(y, x); | 40 return %MathAtan2(y, x); |
| 56 } | 41 } |
| 57 | 42 |
| 58 // ECMA 262 - 15.8.2.6 | 43 // ECMA 262 - 15.8.2.6 |
| 59 function MathCeil(x) { | 44 function MathCeil(x) { |
| 60 return -%_MathFloor(-x); | 45 return -%_MathFloor(-x); |
| 61 } | 46 } |
| 62 | 47 |
| 63 // ECMA 262 - 15.8.2.8 | 48 // ECMA 262 - 15.8.2.8 |
| 64 function MathExp(x) { | 49 function MathExp(x) { |
| 65 return %MathExpRT(TO_NUMBER(x)); | 50 return %MathExpRT(TO_NUMBER(x)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 // ECMA 262 - 15.8.2.15 | 85 // ECMA 262 - 15.8.2.15 |
| 101 function MathRound(x) { | 86 function MathRound(x) { |
| 102 return %RoundNumber(TO_NUMBER(x)); | 87 return %RoundNumber(TO_NUMBER(x)); |
| 103 } | 88 } |
| 104 | 89 |
| 105 // ECMA 262 - 15.8.2.17 | 90 // ECMA 262 - 15.8.2.17 |
| 106 function MathSqrtJS(x) { | 91 function MathSqrtJS(x) { |
| 107 return %_MathSqrt(+x); | 92 return %_MathSqrt(+x); |
| 108 } | 93 } |
| 109 | 94 |
| 110 // Non-standard extension. | |
| 111 function MathImul(x, y) { | |
| 112 return %NumberImul(TO_NUMBER(x), TO_NUMBER(y)); | |
| 113 } | |
| 114 | |
| 115 // ES6 draft 09-27-13, section 20.2.2.28. | 95 // ES6 draft 09-27-13, section 20.2.2.28. |
| 116 function MathSign(x) { | 96 function MathSign(x) { |
| 117 x = +x; | 97 x = +x; |
| 118 if (x > 0) return 1; | 98 if (x > 0) return 1; |
| 119 if (x < 0) return -1; | 99 if (x < 0) return -1; |
| 120 // -0, 0 or NaN. | 100 // -0, 0 or NaN. |
| 121 return x; | 101 return x; |
| 122 } | 102 } |
| 123 | 103 |
| 124 // ES6 draft 09-27-13, section 20.2.2.34. | 104 // ES6 draft 09-27-13, section 20.2.2.34. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 for (var i = 0; i < length; i++) { | 161 for (var i = 0; i < length; i++) { |
| 182 var n = arguments[i] / max; | 162 var n = arguments[i] / max; |
| 183 var summand = n * n - compensation; | 163 var summand = n * n - compensation; |
| 184 var preliminary = sum + summand; | 164 var preliminary = sum + summand; |
| 185 compensation = (preliminary - sum) - summand; | 165 compensation = (preliminary - sum) - summand; |
| 186 sum = preliminary; | 166 sum = preliminary; |
| 187 } | 167 } |
| 188 return %_MathSqrt(sum) * max; | 168 return %_MathSqrt(sum) * max; |
| 189 } | 169 } |
| 190 | 170 |
| 191 // ES6 draft 09-27-13, section 20.2.2.16. | |
| 192 function MathFroundJS(x) { | |
| 193 return %MathFround(TO_NUMBER(x)); | |
| 194 } | |
| 195 | |
| 196 // ES6 draft 07-18-14, section 20.2.2.11 | 171 // ES6 draft 07-18-14, section 20.2.2.11 |
| 197 function MathClz32JS(x) { | 172 function MathClz32JS(x) { |
| 198 return %_MathClz32(x >>> 0); | 173 return %_MathClz32(x >>> 0); |
| 199 } | 174 } |
| 200 | 175 |
| 201 // ES6 draft 09-27-13, section 20.2.2.9. | 176 // ES6 draft 09-27-13, section 20.2.2.9. |
| 202 // Cube root approximation, refer to: http://metamerist.com/cbrt/cbrt.htm | 177 // Cube root approximation, refer to: http://metamerist.com/cbrt/cbrt.htm |
| 203 // Using initial approximation adapted from Kahan's cbrt and 4 iterations | 178 // Using initial approximation adapted from Kahan's cbrt and 4 iterations |
| 204 // of Newton's method. | 179 // of Newton's method. |
| 205 function MathCbrt(x) { | 180 function MathCbrt(x) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 "PI", 3.1415926535897932, | 214 "PI", 3.1415926535897932, |
| 240 "SQRT1_2", 0.7071067811865476, | 215 "SQRT1_2", 0.7071067811865476, |
| 241 "SQRT2", 1.4142135623730951 | 216 "SQRT2", 1.4142135623730951 |
| 242 ]); | 217 ]); |
| 243 | 218 |
| 244 // Set up non-enumerable functions of the Math object and | 219 // Set up non-enumerable functions of the Math object and |
| 245 // set their names. | 220 // set their names. |
| 246 utils.InstallFunctions(GlobalMath, DONT_ENUM, [ | 221 utils.InstallFunctions(GlobalMath, DONT_ENUM, [ |
| 247 "random", MathRandom, | 222 "random", MathRandom, |
| 248 "abs", MathAbs, | 223 "abs", MathAbs, |
| 249 "acos", MathAcosJS, | |
| 250 "asin", MathAsinJS, | |
| 251 "atan", MathAtanJS, | |
| 252 "ceil", MathCeil, | 224 "ceil", MathCeil, |
| 253 "exp", MathExp, | 225 "exp", MathExp, |
| 254 "floor", MathFloorJS, | 226 "floor", MathFloorJS, |
| 255 "log", MathLog, | 227 "log", MathLog, |
| 256 "round", MathRound, | 228 "round", MathRound, |
| 257 "sqrt", MathSqrtJS, | 229 "sqrt", MathSqrtJS, |
| 258 "atan2", MathAtan2JS, | 230 "atan2", MathAtan2JS, |
| 259 "pow", MathPowJS, | 231 "pow", MathPowJS, |
| 260 "imul", MathImul, | |
| 261 "sign", MathSign, | 232 "sign", MathSign, |
| 262 "trunc", MathTrunc, | 233 "trunc", MathTrunc, |
| 263 "asinh", MathAsinh, | 234 "asinh", MathAsinh, |
| 264 "acosh", MathAcosh, | 235 "acosh", MathAcosh, |
| 265 "atanh", MathAtanh, | 236 "atanh", MathAtanh, |
| 266 "hypot", MathHypot, | 237 "hypot", MathHypot, |
| 267 "fround", MathFroundJS, | |
| 268 "clz32", MathClz32JS, | 238 "clz32", MathClz32JS, |
| 269 "cbrt", MathCbrt | 239 "cbrt", MathCbrt |
| 270 ]); | 240 ]); |
| 271 | 241 |
| 272 %SetForceInlineFlag(MathAbs); | 242 %SetForceInlineFlag(MathAbs); |
| 273 %SetForceInlineFlag(MathAcosJS); | |
| 274 %SetForceInlineFlag(MathAsinJS); | |
| 275 %SetForceInlineFlag(MathAtanJS); | |
| 276 %SetForceInlineFlag(MathAtan2JS); | 243 %SetForceInlineFlag(MathAtan2JS); |
| 277 %SetForceInlineFlag(MathCeil); | 244 %SetForceInlineFlag(MathCeil); |
| 278 %SetForceInlineFlag(MathClz32JS); | 245 %SetForceInlineFlag(MathClz32JS); |
| 279 %SetForceInlineFlag(MathFloorJS); | 246 %SetForceInlineFlag(MathFloorJS); |
| 280 %SetForceInlineFlag(MathRandom); | 247 %SetForceInlineFlag(MathRandom); |
| 281 %SetForceInlineFlag(MathSign); | 248 %SetForceInlineFlag(MathSign); |
| 282 %SetForceInlineFlag(MathSqrtJS); | 249 %SetForceInlineFlag(MathSqrtJS); |
| 283 %SetForceInlineFlag(MathTrunc); | 250 %SetForceInlineFlag(MathTrunc); |
| 284 | 251 |
| 285 // ------------------------------------------------------------------- | 252 // ------------------------------------------------------------------- |
| 286 // Exports | 253 // Exports |
| 287 | 254 |
| 288 utils.Export(function(to) { | 255 utils.Export(function(to) { |
| 289 to.MathAbs = MathAbs; | 256 to.MathAbs = MathAbs; |
| 290 to.MathExp = MathExp; | 257 to.MathExp = MathExp; |
| 291 to.MathFloor = MathFloorJS; | 258 to.MathFloor = MathFloorJS; |
| 292 to.IntRandom = MathRandomRaw; | 259 to.IntRandom = MathRandomRaw; |
| 293 }); | 260 }); |
| 294 | 261 |
| 295 }) | 262 }) |
| OLD | NEW |