How to compute log? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to compute log?

How to compute logarithmic function without using library ? This is my attempt https://code.sololearn.com/WF2v2oX0HPa9/?ref=app But it's not 100% accurate. What are the other ways?

26th Mar 2020, 4:31 AM
Sarthak
Sarthak - avatar
2 Answers
+ 1
I think you should try this one, class Gfg1 { static int Log2n(int n) { return (n > 1) ? 1 + Log2n(n / 2) : 0; } // Driver Code public static void main(String args[]) { int n = 32; System.out.println(Log2n(n)); } }
27th Mar 2020, 10:55 AM
Yash Sehgal
Yash Sehgal - avatar
0
Yash Sehgal For what base of log it works? And how can I change that?
28th Mar 2020, 4:46 AM
Sarthak
Sarthak - avatar