admin管理员组文章数量:1184808
I wrote an html5 canvas based app for plotting the electric potential as a color-map. I was using Math.log10 to re-scale the values and this worked well on quite a few systems (Chrome-Firefox-Opera; laptops and PC; Windows and Ubuntu; integrated and dedicate graphics). And then I found one PC and one laptop both with Windows where the plot would not work. The error was showing that Math.log10() could not be called as a function and just typing Math.log10 in the js console returned undefined. I got around this glitch by replacing Math.log10(someValue) with Math.log(someValue)/2.3. So my questions are: why does this happens and are there any other similar annoying differences?
I wrote an html5 canvas based app for plotting the electric potential as a color-map. I was using Math.log10 to re-scale the values and this worked well on quite a few systems (Chrome-Firefox-Opera; laptops and PC; Windows and Ubuntu; integrated and dedicate graphics). And then I found one PC and one laptop both with Windows where the plot would not work. The error was showing that Math.log10() could not be called as a function and just typing Math.log10 in the js console returned undefined. I got around this glitch by replacing Math.log10(someValue) with Math.log(someValue)/2.3. So my questions are: why does this happens and are there any other similar annoying differences?
Share Improve this question asked Feb 3, 2015 at 10:43 DorinPopescuDorinPopescu 7256 silver badges10 bronze badges 03 Answers
Reset to default 15This is browser-specific. Not all browsers support the experimental Math.log10()
function - the main one being Internet Explorer.
Math.log()
however is a separate function which was introduced long before Math.log10()
, and has much greater browser support.
The Mozilla Developer Network lists browser support for Math.log10()
:
Desktop Browsers
Chrome Firefox (Gecko) Internet Explorer Opera Safari 38 25 (25) Not supported 25 7.1
Mobile Browsers
Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Not supported Not supported 25.0 (25) Not supported Not supported iOS 8
Math.log10 = Math.log10 || function(x) {
return Math.log(x) * Math.LOG10E;
};
Paste this in your common JS file and this will resolve the issue if log10 will not be supported by browser.
I know it is too late, but it might help if someone will reach your post while searching.
Math.log()
is the Napierian logarithm (ln).
So you should use Math.log(value)/Math.log(10)
since log10(X) = ln(X)/ln(10)
and Math.log()
has much greater browser support as stated in the previous post.
本文标签: javascriptWhy does Mathlog10 work on some systems but return undefined on othersStack Overflow
版权声明:本文标题:javascript - Why does Math.log10 work on some systems but return undefined on others? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738330723a2075989.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论