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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 for (var i = 0; i < length; i++) { | 136 for (var i = 0; i < length; i++) { |
137 var n = arguments[i] / max; | 137 var n = arguments[i] / max; |
138 var summand = n * n - compensation; | 138 var summand = n * n - compensation; |
139 var preliminary = sum + summand; | 139 var preliminary = sum + summand; |
140 compensation = (preliminary - sum) - summand; | 140 compensation = (preliminary - sum) - summand; |
141 sum = preliminary; | 141 sum = preliminary; |
142 } | 142 } |
143 return %math_sqrt(sum) * max; | 143 return %math_sqrt(sum) * max; |
144 } | 144 } |
145 | 145 |
146 // ES6 draft 07-18-14, section 20.2.2.11 | |
147 function MathClz32JS(x) { | |
148 return %_MathClz32(x >>> 0); | |
149 } | |
150 | |
151 // ES6 draft 09-27-13, section 20.2.2.9. | 146 // ES6 draft 09-27-13, section 20.2.2.9. |
152 // Cube root approximation, refer to: http://metamerist.com/cbrt/cbrt.htm | 147 // Cube root approximation, refer to: http://metamerist.com/cbrt/cbrt.htm |
153 // Using initial approximation adapted from Kahan's cbrt and 4 iterations | 148 // Using initial approximation adapted from Kahan's cbrt and 4 iterations |
154 // of Newton's method. | 149 // of Newton's method. |
155 function MathCbrt(x) { | 150 function MathCbrt(x) { |
156 x = TO_NUMBER(x); | 151 x = TO_NUMBER(x); |
157 if (x == 0 || !NUMBER_IS_FINITE(x)) return x; | 152 if (x == 0 || !NUMBER_IS_FINITE(x)) return x; |
158 return x >= 0 ? CubeRoot(x) : -CubeRoot(-x); | 153 return x >= 0 ? CubeRoot(x) : -CubeRoot(-x); |
159 } | 154 } |
160 | 155 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 "abs", MathAbs, | 197 "abs", MathAbs, |
203 "exp", MathExp, | 198 "exp", MathExp, |
204 "log", MathLog, | 199 "log", MathLog, |
205 "atan2", MathAtan2JS, | 200 "atan2", MathAtan2JS, |
206 "pow", MathPowJS, | 201 "pow", MathPowJS, |
207 "sign", MathSign, | 202 "sign", MathSign, |
208 "asinh", MathAsinh, | 203 "asinh", MathAsinh, |
209 "acosh", MathAcosh, | 204 "acosh", MathAcosh, |
210 "atanh", MathAtanh, | 205 "atanh", MathAtanh, |
211 "hypot", MathHypot, | 206 "hypot", MathHypot, |
212 "clz32", MathClz32JS, | |
213 "cbrt", MathCbrt | 207 "cbrt", MathCbrt |
214 ]); | 208 ]); |
215 | 209 |
216 %SetForceInlineFlag(MathAbs); | 210 %SetForceInlineFlag(MathAbs); |
217 %SetForceInlineFlag(MathAtan2JS); | 211 %SetForceInlineFlag(MathAtan2JS); |
218 %SetForceInlineFlag(MathClz32JS); | |
219 %SetForceInlineFlag(MathRandom); | 212 %SetForceInlineFlag(MathRandom); |
220 %SetForceInlineFlag(MathSign); | 213 %SetForceInlineFlag(MathSign); |
221 | 214 |
222 // ------------------------------------------------------------------- | 215 // ------------------------------------------------------------------- |
223 // Exports | 216 // Exports |
224 | 217 |
225 utils.Export(function(to) { | 218 utils.Export(function(to) { |
226 to.MathAbs = MathAbs; | 219 to.MathAbs = MathAbs; |
227 to.MathExp = MathExp; | 220 to.MathExp = MathExp; |
228 to.IntRandom = MathRandomRaw; | 221 to.IntRandom = MathRandomRaw; |
229 }); | 222 }); |
230 | 223 |
231 }) | 224 }) |
OLD | NEW |