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

Side by Side Diff: src/js/math.js

Issue 1407213002: Implement Math.tanh using fdlibm port. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: delete the actual old implementation Created 5 years, 2 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
« no previous file with comments | « no previous file | src/third_party/fdlibm/fdlibm.js » ('j') | src/third_party/fdlibm/fdlibm.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 var rngstate; // Initialized to a Uint32Array during genesis. 5 var rngstate; // Initialized to a Uint32Array during genesis.
6 6
7 (function(global, utils) { 7 (function(global, utils) {
8 "use strict"; 8 "use strict";
9 9
10 %CheckIsBootstrapping(); 10 %CheckIsBootstrapping();
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 175
176 // ES6 draft 09-27-13, section 20.2.2.34. 176 // ES6 draft 09-27-13, section 20.2.2.34.
177 function MathTrunc(x) { 177 function MathTrunc(x) {
178 x = +x; 178 x = +x;
179 if (x > 0) return %_MathFloor(x); 179 if (x > 0) return %_MathFloor(x);
180 if (x < 0) return -%_MathFloor(-x); 180 if (x < 0) return -%_MathFloor(-x);
181 // -0, 0 or NaN. 181 // -0, 0 or NaN.
182 return x; 182 return x;
183 } 183 }
184 184
185 // ES6 draft 09-27-13, section 20.2.2.33.
186 function MathTanh(x) {
187 x = TO_NUMBER(x);
188 // Idempotent for +/-0.
189 if (x === 0) return x;
190 // Returns +/-1 for +/-Infinity.
191 if (!NUMBER_IS_FINITE(x)) return MathSign(x);
192 var exp1 = MathExp(x);
193 var exp2 = MathExp(-x);
194 return (exp1 - exp2) / (exp1 + exp2);
195 }
196
197 // ES6 draft 09-27-13, section 20.2.2.5. 185 // ES6 draft 09-27-13, section 20.2.2.5.
198 function MathAsinh(x) { 186 function MathAsinh(x) {
199 x = TO_NUMBER(x); 187 x = TO_NUMBER(x);
200 // Idempotent for NaN, +/-0 and +/-Infinity. 188 // Idempotent for NaN, +/-0 and +/-Infinity.
201 if (x === 0 || !NUMBER_IS_FINITE(x)) return x; 189 if (x === 0 || !NUMBER_IS_FINITE(x)) return x;
202 if (x > 0) return MathLog(x + %_MathSqrt(x * x + 1)); 190 if (x > 0) return MathLog(x + %_MathSqrt(x * x + 1));
203 // This is to prevent numerical errors caused by large negative x. 191 // This is to prevent numerical errors caused by large negative x.
204 return -MathLog(-x + %_MathSqrt(x * x + 1)); 192 return -MathLog(-x + %_MathSqrt(x * x + 1));
205 } 193 }
206 194
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 "log", MathLog, 310 "log", MathLog,
323 "round", MathRound, 311 "round", MathRound,
324 "sqrt", MathSqrtJS, 312 "sqrt", MathSqrtJS,
325 "atan2", MathAtan2JS, 313 "atan2", MathAtan2JS,
326 "pow", MathPowJS, 314 "pow", MathPowJS,
327 "max", MathMax, 315 "max", MathMax,
328 "min", MathMin, 316 "min", MathMin,
329 "imul", MathImul, 317 "imul", MathImul,
330 "sign", MathSign, 318 "sign", MathSign,
331 "trunc", MathTrunc, 319 "trunc", MathTrunc,
332 "tanh", MathTanh,
333 "asinh", MathAsinh, 320 "asinh", MathAsinh,
334 "acosh", MathAcosh, 321 "acosh", MathAcosh,
335 "atanh", MathAtanh, 322 "atanh", MathAtanh,
336 "hypot", MathHypot, 323 "hypot", MathHypot,
337 "fround", MathFroundJS, 324 "fround", MathFroundJS,
338 "clz32", MathClz32JS, 325 "clz32", MathClz32JS,
339 "cbrt", MathCbrt 326 "cbrt", MathCbrt
340 ]); 327 ]);
341 328
342 %SetForceInlineFlag(MathAbs); 329 %SetForceInlineFlag(MathAbs);
(...skipping 15 matching lines...) Expand all
358 utils.Export(function(to) { 345 utils.Export(function(to) {
359 to.MathAbs = MathAbs; 346 to.MathAbs = MathAbs;
360 to.MathExp = MathExp; 347 to.MathExp = MathExp;
361 to.MathFloor = MathFloorJS; 348 to.MathFloor = MathFloorJS;
362 to.IntRandom = MathRandomRaw; 349 to.IntRandom = MathRandomRaw;
363 to.MathMax = MathMax; 350 to.MathMax = MathMax;
364 to.MathMin = MathMin; 351 to.MathMin = MathMin;
365 }); 352 });
366 353
367 }) 354 })
OLDNEW
« no previous file with comments | « no previous file | src/third_party/fdlibm/fdlibm.js » ('j') | src/third_party/fdlibm/fdlibm.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698