OLD | NEW |
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 function MathAtanh(x) { | 103 function MathAtanh(x) { |
104 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); | 104 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
105 // Idempotent for +/-0. | 105 // Idempotent for +/-0. |
106 if (x === 0) return x; | 106 if (x === 0) return x; |
107 // Returns NaN for NaN and +/- Infinity. | 107 // Returns NaN for NaN and +/- Infinity. |
108 if (!NUMBER_IS_FINITE(x)) return NAN; | 108 if (!NUMBER_IS_FINITE(x)) return NAN; |
109 return 0.5 * MathLog((1 + x) / (1 - x)); | 109 return 0.5 * MathLog((1 + x) / (1 - x)); |
110 } | 110 } |
111 | 111 |
112 | 112 |
| 113 //ES6 draft 09-27-13, section 20.2.2.21. |
| 114 function MathLog10(x) { |
| 115 return MathLog(x) * 0.434294481903251828; // log10(x) = log(x)/log(10). |
| 116 } |
| 117 |
| 118 |
| 119 //ES6 draft 09-27-13, section 20.2.2.22. |
| 120 function MathLog2(x) { |
| 121 return MathLog(x) * 1.442695040888963407; // log2(x) = log(x)/log(2). |
| 122 } |
| 123 |
| 124 |
113 function ExtendMath() { | 125 function ExtendMath() { |
114 %CheckIsBootstrapping(); | 126 %CheckIsBootstrapping(); |
115 | 127 |
116 // Set up the non-enumerable functions on the Math object. | 128 // Set up the non-enumerable functions on the Math object. |
117 InstallFunctions($Math, DONT_ENUM, $Array( | 129 InstallFunctions($Math, DONT_ENUM, $Array( |
118 "sign", MathSign, | 130 "sign", MathSign, |
119 "trunc", MathTrunc, | 131 "trunc", MathTrunc, |
120 "sinh", MathSinh, | 132 "sinh", MathSinh, |
121 "cosh", MathCosh, | 133 "cosh", MathCosh, |
122 "tanh", MathTanh, | 134 "tanh", MathTanh, |
123 "asinh", MathAsinh, | 135 "asinh", MathAsinh, |
124 "acosh", MathAcosh, | 136 "acosh", MathAcosh, |
125 "atanh", MathAtanh | 137 "atanh", MathAtanh, |
| 138 "log10", MathLog10, |
| 139 "log2", MathLog2 |
126 )); | 140 )); |
127 } | 141 } |
128 | 142 |
129 ExtendMath(); | 143 ExtendMath(); |
OLD | NEW |