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

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

Issue 181453002: Reset trunk to 3.24.35.4 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 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 | « src/globals.h ('k') | src/heap.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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); 52 if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
53 // Idempotent for NaN, +/-0 and +/-Infinity. 53 // Idempotent for NaN, +/-0 and +/-Infinity.
54 if (x === 0 || !NUMBER_IS_FINITE(x)) return x; 54 if (x === 0 || !NUMBER_IS_FINITE(x)) return x;
55 return (MathExp(x) - MathExp(-x)) / 2; 55 return (MathExp(x) - MathExp(-x)) / 2;
56 } 56 }
57 57
58 58
59 // ES6 draft 09-27-13, section 20.2.2.12. 59 // ES6 draft 09-27-13, section 20.2.2.12.
60 function MathCosh(x) { 60 function MathCosh(x) {
61 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); 61 if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
62 if (!NUMBER_IS_FINITE(x)) return MathAbs(x); 62 // Idempotent for NaN and +/-Infinity.
63 if (!NUMBER_IS_FINITE(x)) return x;
63 return (MathExp(x) + MathExp(-x)) / 2; 64 return (MathExp(x) + MathExp(-x)) / 2;
64 } 65 }
65 66
66 67
67 // ES6 draft 09-27-13, section 20.2.2.33. 68 // ES6 draft 09-27-13, section 20.2.2.33.
68 function MathTanh(x) { 69 function MathTanh(x) {
69 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); 70 if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
70 // Idempotent for +/-0. 71 // Idempotent for +/-0.
71 if (x === 0) return x; 72 if (x === 0) return x;
72 // Returns +/-1 for +/-Infinity. 73 // Returns +/-1 for +/-Infinity.
(...skipping 29 matching lines...) Expand all
102 function MathAtanh(x) { 103 function MathAtanh(x) {
103 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); 104 if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
104 // Idempotent for +/-0. 105 // Idempotent for +/-0.
105 if (x === 0) return x; 106 if (x === 0) return x;
106 // Returns NaN for NaN and +/- Infinity. 107 // Returns NaN for NaN and +/- Infinity.
107 if (!NUMBER_IS_FINITE(x)) return NAN; 108 if (!NUMBER_IS_FINITE(x)) return NAN;
108 return 0.5 * MathLog((1 + x) / (1 - x)); 109 return 0.5 * MathLog((1 + x) / (1 - x));
109 } 110 }
110 111
111 112
112 // ES6 draft 09-27-13, section 20.2.2.21. 113 //ES6 draft 09-27-13, section 20.2.2.21.
113 function MathLog10(x) { 114 function MathLog10(x) {
114 return MathLog(x) * 0.434294481903251828; // log10(x) = log(x)/log(10). 115 return MathLog(x) * 0.434294481903251828; // log10(x) = log(x)/log(10).
115 } 116 }
116 117
117 118
118 // ES6 draft 09-27-13, section 20.2.2.22. 119 //ES6 draft 09-27-13, section 20.2.2.22.
119 function MathLog2(x) { 120 function MathLog2(x) {
120 return MathLog(x) * 1.442695040888963407; // log2(x) = log(x)/log(2). 121 return MathLog(x) * 1.442695040888963407; // log2(x) = log(x)/log(2).
121 } 122 }
122 123
123 124
124 // ES6 draft 09-27-13, section 20.2.2.17. 125 //ES6 draft 09-27-13, section 20.2.2.17.
125 function MathHypot(x, y) { // Function length is 2. 126 function MathHypot(x, y) { // Function length is 2.
126 // We may want to introduce fast paths for two arguments and when 127 // We may want to introduce fast paths for two arguments and when
127 // normalization to avoid overflow is not necessary. For now, we 128 // normalization to avoid overflow is not necessary. For now, we
128 // simply assume the general case. 129 // simply assume the general case.
129 var length = %_ArgumentsLength(); 130 var length = %_ArgumentsLength();
130 var args = new InternalArray(length); 131 var args = new InternalArray(length);
131 var max = 0; 132 var max = 0;
132 for (var i = 0; i < length; i++) { 133 for (var i = 0; i < length; i++) {
133 var n = %_Arguments(i); 134 var n = %_Arguments(i);
134 if (!IS_NUMBER(n)) n = NonNumberToNumber(n); 135 if (!IS_NUMBER(n)) n = NonNumberToNumber(n);
(...skipping 12 matching lines...) Expand all
147 var n = args[i] / max; 148 var n = args[i] / max;
148 var summand = n * n - compensation; 149 var summand = n * n - compensation;
149 var preliminary = sum + summand; 150 var preliminary = sum + summand;
150 compensation = (preliminary - sum) - summand; 151 compensation = (preliminary - sum) - summand;
151 sum = preliminary; 152 sum = preliminary;
152 } 153 }
153 return MathSqrt(sum) * max; 154 return MathSqrt(sum) * max;
154 } 155 }
155 156
156 157
157 // ES6 draft 09-27-13, section 20.2.2.16.
158 function MathFround(x) {
159 return %Math_fround(TO_NUMBER_INLINE(x));
160 }
161
162
163 function MathClz32(x) {
164 x = ToUint32(TO_NUMBER_INLINE(x));
165 if (x == 0) return 32;
166 var result = 0;
167 // Binary search.
168 if ((x & 0xFFFF0000) === 0) { x <<= 16; result += 16; };
169 if ((x & 0xFF000000) === 0) { x <<= 8; result += 8; };
170 if ((x & 0xF0000000) === 0) { x <<= 4; result += 4; };
171 if ((x & 0xC0000000) === 0) { x <<= 2; result += 2; };
172 if ((x & 0x80000000) === 0) { x <<= 1; result += 1; };
173 return result;
174 }
175
176
177 //ES6 draft 09-27-13, section 20.2.2.9.
178 function MathCbrt(x) {
179 return %Math_cbrt(TO_NUMBER_INLINE(x));
180 }
181
182
183 //ES6 draft 09-27-13, section 20.2.2.14.
184 function MathExpm1(x) {
185 return %Math_expm1(TO_NUMBER_INLINE(x));
186 }
187
188
189 //ES6 draft 09-27-13, section 20.2.2.20.
190 function MathLog1p(x) {
191 return %Math_log1p(TO_NUMBER_INLINE(x));
192 }
193
194
195 function ExtendMath() { 158 function ExtendMath() {
196 %CheckIsBootstrapping(); 159 %CheckIsBootstrapping();
197 160
198 // Set up the non-enumerable functions on the Math object. 161 // Set up the non-enumerable functions on the Math object.
199 InstallFunctions($Math, DONT_ENUM, $Array( 162 InstallFunctions($Math, DONT_ENUM, $Array(
200 "sign", MathSign, 163 "sign", MathSign,
201 "trunc", MathTrunc, 164 "trunc", MathTrunc,
202 "sinh", MathSinh, 165 "sinh", MathSinh,
203 "cosh", MathCosh, 166 "cosh", MathCosh,
204 "tanh", MathTanh, 167 "tanh", MathTanh,
205 "asinh", MathAsinh, 168 "asinh", MathAsinh,
206 "acosh", MathAcosh, 169 "acosh", MathAcosh,
207 "atanh", MathAtanh, 170 "atanh", MathAtanh,
208 "log10", MathLog10, 171 "log10", MathLog10,
209 "log2", MathLog2, 172 "log2", MathLog2,
210 "hypot", MathHypot, 173 "hypot", MathHypot
211 "fround", MathFround,
212 "clz32", MathClz32,
213 "cbrt", MathCbrt,
214 "log1p", MathLog1p,
215 "expm1", MathExpm1
216 )); 174 ));
217 } 175 }
218 176
219
220 ExtendMath(); 177 ExtendMath();
OLDNEW
« no previous file with comments | « src/globals.h ('k') | src/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698