Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: src/math.js

Issue 465353002: Implement Math.expm1 using port from fdlibm. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/es6/math-expm1.js » ('j') | test/mjsunit/es6/math-expm1.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "use strict"; 5 "use strict";
6 6
7 // This file relies on the fact that the following declarations have been made 7 // This file relies on the fact that the following declarations have been made
8 // in runtime.js: 8 // in runtime.js:
9 // var $Object = global.Object; 9 // var $Object = global.Object;
10 10
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 320
321 function CubeRoot(x) { 321 function CubeRoot(x) {
322 var approx_hi = MathFloor(%_DoubleHi(x) / 3) + 0x2A9F7893; 322 var approx_hi = MathFloor(%_DoubleHi(x) / 3) + 0x2A9F7893;
323 var approx = %_ConstructDouble(approx_hi, 0); 323 var approx = %_ConstructDouble(approx_hi, 0);
324 approx = NEWTON_ITERATION_CBRT(x, approx); 324 approx = NEWTON_ITERATION_CBRT(x, approx);
325 approx = NEWTON_ITERATION_CBRT(x, approx); 325 approx = NEWTON_ITERATION_CBRT(x, approx);
326 approx = NEWTON_ITERATION_CBRT(x, approx); 326 approx = NEWTON_ITERATION_CBRT(x, approx);
327 return NEWTON_ITERATION_CBRT(x, approx); 327 return NEWTON_ITERATION_CBRT(x, approx);
328 } 328 }
329 329
330 // ES6 draft 09-27-13, section 20.2.2.14.
331 // Use Taylor series to approximate.
332 // exp(x) - 1 at 0 == -1 + exp(0) + exp'(0)*x/1! + exp''(0)*x^2/2! + ...
333 // == x/1! + x^2/2! + x^3/3! + ...
334 // The closer x is to 0, the fewer terms are required.
335 function MathExpm1(x) {
336 if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
337 var xabs = MathAbs(x);
338 if (xabs < 2E-7) {
339 return x * (1 + x * (1/2));
340 } else if (xabs < 6E-5) {
341 return x * (1 + x * (1/2 + x * (1/6)));
342 } else if (xabs < 2E-2) {
343 return x * (1 + x * (1/2 + x * (1/6 +
344 x * (1/24 + x * (1/120 + x * (1/720))))));
345 } else { // Use regular exp if not close enough to 0.
346 return MathExp(x) - 1;
347 }
348 }
349
350 // ------------------------------------------------------------------- 330 // -------------------------------------------------------------------
351 331
352 function SetUpMath() { 332 function SetUpMath() {
353 %CheckIsBootstrapping(); 333 %CheckIsBootstrapping();
354 334
355 %InternalSetPrototype($Math, $Object.prototype); 335 %InternalSetPrototype($Math, $Object.prototype);
356 %AddNamedProperty(global, "Math", $Math, DONT_ENUM); 336 %AddNamedProperty(global, "Math", $Math, DONT_ENUM);
357 %FunctionSetInstanceClassName(MathConstructor, 'Math'); 337 %FunctionSetInstanceClassName(MathConstructor, 'Math');
358 338
359 // Set up math constants. 339 // Set up math constants.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 "tanh", MathTanh, 381 "tanh", MathTanh,
402 "asinh", MathAsinh, 382 "asinh", MathAsinh,
403 "acosh", MathAcosh, 383 "acosh", MathAcosh,
404 "atanh", MathAtanh, 384 "atanh", MathAtanh,
405 "log10", MathLog10, 385 "log10", MathLog10,
406 "log2", MathLog2, 386 "log2", MathLog2,
407 "hypot", MathHypot, 387 "hypot", MathHypot,
408 "fround", MathFroundJS, 388 "fround", MathFroundJS,
409 "clz32", MathClz32, 389 "clz32", MathClz32,
410 "cbrt", MathCbrt, 390 "cbrt", MathCbrt,
411 "log1p", MathLog1p, // implemented by third_party/fdlibm 391 "log1p", MathLog1p, // implemented by third_party/fdlibm
412 "expm1", MathExpm1 392 "expm1", MathExpm1 // implemented by third_party/fdlibm
413 )); 393 ));
414 394
415 %SetInlineBuiltinFlag(MathCeil); 395 %SetInlineBuiltinFlag(MathCeil);
416 %SetInlineBuiltinFlag(MathRandom); 396 %SetInlineBuiltinFlag(MathRandom);
417 %SetInlineBuiltinFlag(MathSin); 397 %SetInlineBuiltinFlag(MathSin);
418 %SetInlineBuiltinFlag(MathCos); 398 %SetInlineBuiltinFlag(MathCos);
419 } 399 }
420 400
421 SetUpMath(); 401 SetUpMath();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/es6/math-expm1.js » ('j') | test/mjsunit/es6/math-expm1.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698