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

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

Issue 102023003: Implement hyperbolic math functions for ES6. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: add test cases Created 7 years 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 | src/runtime.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 29 matching lines...) Expand all
40 // ES6 draft 09-27-13, section 20.2.2.34. 40 // ES6 draft 09-27-13, section 20.2.2.34.
41 function MathTrunc(x) { 41 function MathTrunc(x) {
42 x = TO_NUMBER_INLINE(x); 42 x = TO_NUMBER_INLINE(x);
43 if (x > 0) return MathFloor(x); 43 if (x > 0) return MathFloor(x);
44 if (x < 0) return MathCeil(x); 44 if (x < 0) return MathCeil(x);
45 if (x === 0) return x; 45 if (x === 0) return x;
46 return NAN; 46 return NAN;
47 } 47 }
48 48
49 49
50 // ES6 draft 09-27-13, section 20.2.2.30.
51 function MathSinh(x) {
52 if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
53 // Idempotent for NaN, +/-0 and +/-Infinity.
54 if (x === 0 || !NUMBER_IS_FINITE(x)) return x;
55 return (MathExp(x) - MathExp(-x)) / 2;
56 }
57
58
59 // ES6 draft 09-27-13, section 20.2.2.12.
60 function MathCosh(x) {
61 if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
62 // Idempotent for NaN and +/-Infinity.
63 if (!NUMBER_IS_FINITE(x)) return x;
64 return (MathExp(x) + MathExp(-x)) / 2;
65 }
66
67
68 // ES6 draft 09-27-13, section 20.2.2.33.
69 function MathTanh(x) {
70 if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
71 // Idempotent for +/-0.
72 if (x === 0) return x;
73 // Returns +/-1 for +/-Infinity.
74 if (!NUMBER_IS_FINITE(x)) return MathSign(x);
75 var exp1 = MathExp(x);
76 var exp2 = MathExp(-x);
77 return (exp1 - exp2) / (exp1 + exp2);
78 }
79
80
81 // ES6 draft 09-27-13, section 20.2.2.5.
82 function MathAsinh(x) {
83 if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
84 // Idempotent for NaN, +/-0 and +/-Infinity.
85 if (x === 0 || !NUMBER_IS_FINITE(x)) return x;
86 return %Math_asinh(x);
87 }
88
89
90 // ES6 draft 09-27-13, section 20.2.2.3.
91 function MathAcosh(x) {
92 if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
93 if (x < 1) return NAN;
94 // Idempotent for NaN and +Infinity.
95 if (!NUMBER_IS_FINITE(x)) return x;
96 return %Math_acosh(x);
97 }
98
99
100 // ES6 draft 09-27-13, section 20.2.2.7.
101 function MathAtanh(x) {
102 if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
103 // Idempotent for +/-0.
104 if (x === 0) return x;
105 // Returns NaN for NaN and +/- Infinity.
106 if (!NUMBER_IS_FINITE(x)) return NAN;
107 return %Math_atanh(x);
108 }
109
110
50 function ExtendMath() { 111 function ExtendMath() {
51 %CheckIsBootstrapping(); 112 %CheckIsBootstrapping();
52 113
53 // Set up the non-enumerable functions on the Math object. 114 // Set up the non-enumerable functions on the Math object.
54 InstallFunctions($Math, DONT_ENUM, $Array( 115 InstallFunctions($Math, DONT_ENUM, $Array(
55 "sign", MathSign, 116 "sign", MathSign,
56 "trunc", MathTrunc 117 "trunc", MathTrunc,
118 "sinh", MathSinh,
119 "cosh", MathCosh,
120 "tanh", MathTanh,
121 "asinh", MathAsinh,
122 "acosh", MathAcosh,
123 "atanh", MathAtanh
57 )); 124 ));
58 } 125 }
59 126
60 ExtendMath(); 127 ExtendMath();
OLDNEW
« no previous file with comments | « no previous file | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698