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

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

Issue 169513002: Harmony: implement Math.fround. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: updated comments 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 | « 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 function MathAtanh(x) { 102 function MathAtanh(x) {
103 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); 103 if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
104 // Idempotent for +/-0. 104 // Idempotent for +/-0.
105 if (x === 0) return x; 105 if (x === 0) return x;
106 // Returns NaN for NaN and +/- Infinity. 106 // Returns NaN for NaN and +/- Infinity.
107 if (!NUMBER_IS_FINITE(x)) return NAN; 107 if (!NUMBER_IS_FINITE(x)) return NAN;
108 return 0.5 * MathLog((1 + x) / (1 - x)); 108 return 0.5 * MathLog((1 + x) / (1 - x));
109 } 109 }
110 110
111 111
112 //ES6 draft 09-27-13, section 20.2.2.21. 112 // ES6 draft 09-27-13, section 20.2.2.21.
113 function MathLog10(x) { 113 function MathLog10(x) {
114 return MathLog(x) * 0.434294481903251828; // log10(x) = log(x)/log(10). 114 return MathLog(x) * 0.434294481903251828; // log10(x) = log(x)/log(10).
115 } 115 }
116 116
117 117
118 //ES6 draft 09-27-13, section 20.2.2.22. 118 // ES6 draft 09-27-13, section 20.2.2.22.
119 function MathLog2(x) { 119 function MathLog2(x) {
120 return MathLog(x) * 1.442695040888963407; // log2(x) = log(x)/log(2). 120 return MathLog(x) * 1.442695040888963407; // log2(x) = log(x)/log(2).
121 } 121 }
122 122
123 123
124 //ES6 draft 09-27-13, section 20.2.2.17. 124 // ES6 draft 09-27-13, section 20.2.2.17.
125 function MathHypot(x, y) { // Function length is 2. 125 function MathHypot(x, y) { // Function length is 2.
126 // We may want to introduce fast paths for two arguments and when 126 // We may want to introduce fast paths for two arguments and when
127 // normalization to avoid overflow is not necessary. For now, we 127 // normalization to avoid overflow is not necessary. For now, we
128 // simply assume the general case. 128 // simply assume the general case.
129 var length = %_ArgumentsLength(); 129 var length = %_ArgumentsLength();
130 var args = new InternalArray(length); 130 var args = new InternalArray(length);
131 var max = 0; 131 var max = 0;
132 for (var i = 0; i < length; i++) { 132 for (var i = 0; i < length; i++) {
133 var n = %_Arguments(i); 133 var n = %_Arguments(i);
134 if (!IS_NUMBER(n)) n = NonNumberToNumber(n); 134 if (!IS_NUMBER(n)) n = NonNumberToNumber(n);
(...skipping 12 matching lines...) Expand all
147 var n = args[i] / max; 147 var n = args[i] / max;
148 var summand = n * n - compensation; 148 var summand = n * n - compensation;
149 var preliminary = sum + summand; 149 var preliminary = sum + summand;
150 compensation = (preliminary - sum) - summand; 150 compensation = (preliminary - sum) - summand;
151 sum = preliminary; 151 sum = preliminary;
152 } 152 }
153 return MathSqrt(sum) * max; 153 return MathSqrt(sum) * max;
154 } 154 }
155 155
156 156
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
157 function ExtendMath() { 163 function ExtendMath() {
158 %CheckIsBootstrapping(); 164 %CheckIsBootstrapping();
159 165
160 // Set up the non-enumerable functions on the Math object. 166 // Set up the non-enumerable functions on the Math object.
161 InstallFunctions($Math, DONT_ENUM, $Array( 167 InstallFunctions($Math, DONT_ENUM, $Array(
162 "sign", MathSign, 168 "sign", MathSign,
163 "trunc", MathTrunc, 169 "trunc", MathTrunc,
164 "sinh", MathSinh, 170 "sinh", MathSinh,
165 "cosh", MathCosh, 171 "cosh", MathCosh,
166 "tanh", MathTanh, 172 "tanh", MathTanh,
167 "asinh", MathAsinh, 173 "asinh", MathAsinh,
168 "acosh", MathAcosh, 174 "acosh", MathAcosh,
169 "atanh", MathAtanh, 175 "atanh", MathAtanh,
170 "log10", MathLog10, 176 "log10", MathLog10,
171 "log2", MathLog2, 177 "log2", MathLog2,
172 "hypot", MathHypot 178 "hypot", MathHypot,
179 "fround", MathFround
173 )); 180 ));
174 } 181 }
175 182
176 ExtendMath(); 183 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