/    Sign up×
Community /Pin to ProfileBookmark

Math.log10() function in JavaScript

I’m using the Math.log10() function in JavaScript for logarithmic calculations. It works fine in Chrome, FireFox and Microsoft Edge, but when executing the same code in IE 11 I get an error saying ‘object doesn’t support property or method log10’. I was wondering if anyone had any ideas on why this occurs only in IE but not the other browsers and had a suggestion.

Thanks

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@shakazorbaAug 27.2016 — Well, believe it or not

Math.log10() is not

supported in ie11

or older ?
Copy linkTweet thisAlerts:
@TrainAug 28.2016 — Supported in Microsoft Edge (Edge browser). Also supported in Store apps (Microsoft Edge on Windows 10). See Version Information.

Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Not supported in Windows 8.1.

https://msdn.microsoft.com/en-us/library/mt179293(v=vs.94).aspx
Copy linkTweet thisAlerts:
@alexgm24May 30.2017 — Math.log() is the neperian logarithm ([I]ln[/I]).

So you should use [B]Math.log(value)/Math.log(10)[/B] since [I]log10(X) = ln(X)/ln(10)[/I]

and Math.log() has much greater browser support.
Copy linkTweet thisAlerts:
@rootMay 30.2017 — Make a workaround function.

It would be something like this,
if( typeof Math.log10 == "undefined" ){
Object.prototype.log10 = function(n){
return Math.log(n)/Math.log(10);
}
}

I tried Math.prototype and got errors, I tried Number.prototype and got errors, I tried Object.prototype with no errors and the following result.

The output is,

(using native) Math.log10( 45 ) = 1.6532125137753437

(using workaround) Math.log( 45 ) / Math.log(10) = 1.6532125137753435

Then any browsers not supporting Math.log10() will have an equivalent method that works.
×

Success!

Help @Buddy94 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...