• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Logarithm in ME

 
Stefano Malinconico
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,

Does anybody knows how to calculate logarithms in ANY base?
Math class does not have any support to logarithms...
Have you ever seen any implementation for this?

Thanks in advance,
 
Tim Holloway
Saloon Keeper
Posts: 18367
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what they teach in Calculus II in college. The standard way for computers to compute logarithms is by using an infinite series, stopping the calculations once the desired precision has been attained. As a performance boost, the calculations are generally folded into an area where results converge rapidly so that fewer terms need to be evaluated.

Although the standard logarithms are base 10 (common) and base e (natural), any other base scales from the same process.

Actually, I think your harder problem is getting the floating-point support you need to do the calculations with.
 
Stefano Malinconico
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thing is,
The MID profile API does not provide any support for logarithms (even it is 10-based or Nepperian) as J2SE does.
Diving into the source code we can see that there is a method "java.lang.StrictMath.log10(double a)" declared as native.
The implementation for this method can be found at fdlibm.tar (according to the doc) in a file called e_log10.c But, how could i use this lib on my mobile project? Before all... Is it possible?

Thanks in advance.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think your best bet is to implement an algorithm yourself in Java, rather than trying to call some C code. Wikipedia describes a couple algorithms that should work, in its "Logarithm" article (under "Computers").
 
Tim Holloway
Saloon Keeper
Posts: 18367
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stefano Malinconico:
The thing is,
The MID profile API does not provide any support for logarithms (even it is 10-based or Nepperian) as J2SE does.
Diving into the source code we can see that there is a method "java.lang.StrictMath.log10(double a)" declared as native.
The implementation for this method can be found at fdlibm.tar (according to the doc) in a file called e_log10.c But, how could i use this lib on my mobile project? Before all... Is it possible?

Thanks in advance.


Well, if you want to go that route, the actual code that does the calculations is almost identical in C and Java. The only things to watch for are differences in precision, since that affects the cutoff point for series calculation.
 
Stefano Malinconico
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I solved the problem importing a class called 'MathFP.class'. It is very useful.

Thank you all.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic