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?
This 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With