Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4074599
Votes 3
Synopsis Math package: implement log10 (base 10 logarithm)
Category java:classes_lang
Reported Against 1.1.3
Release Fixed 1.5(tiger)
State 10-Fix Delivered, request for enhancement
Priority: 5-Very Low
Related Bugs 4323012 , 4633024 , 4886570 , 4943127
Submit Date 27-AUG-1997
Description




JDK 1.1 has Math.log which compute natural log values,
It would nice to include a method that compute log base 
10 value.
======================================================================
Work Around
Log base 10 = Math.log(x)/Math.log(10)
Log base 2 = Math.log(x)/Math.log(2)




Given a number n greater than 0.0. 

Then the log10(n) is equal to ln(n)/ln(10)

(where "ln()" is the natural logarithm (base e))

If you store ln(10) as a constant, then you can
get the log10(n) from ln(n) with one additional
divide.


======================================================================
  xxxxx@xxxxx   1997-09-04
More generally:

Given a number n greater than 0.0 and a number b
greater than 0.0

Then the log<b>(n) is equal to ln(n)/ln(b)

(where "ln()" is the natural logarithm (base e)
 and "log<b>()" is the log base b.)
Evaluation
Why was this missed in the first place?

  xxxxx@xxxxx   1997-11-05

The log10() is trivial to derive from the log(). log10(x) = log(x) / log(10). It does not worth the trouble to change the well-know Math class API.

  xxxxx@xxxxx   1998-06-12

While trivial to compute, the log10 function is sufficiently common and useful
that we should eventually provide it.  It didn't make it into 1.2 because it
was just too late; I'm reopening this so that it gets considered for the next
feature release.  --   xxxxx@xxxxx   6/12/1998

This is a library issue.

  xxxxx@xxxxx   2000-06-29

I will try to get this method added in the next major Java release, 1.4.

  xxxxx@xxxxx   2001-06-25

Being considered as part of larger math library effort in 1.5.

  xxxxx@xxxxx   2003-03-18
Comments
  
  Include a link with my name & email   

Submitted On 09-JUN-1998
MartDesruisseaux
Need also pow10(x) to compute 10^x. It would be nice to have optimized code for
the case where x in pow10(x) is a small integer.


Submitted On 11-NOV-2002
bbatman
Why not make a general log(base, x) method that computes the
log in any base (> 0)?


Submitted On 12-NOV-2002
jddarcy
Once you have one logarithm in a given base, you can convert
that result into a log in a different base using the
relationship:

log_a(x) = log_b(x)/log_b(a) = log_b(x)*log_a(b)

For example,

log_10(x) = ln(x)/ln(10)

While this works fine mathematically, the extra
floating-point operations can introduce more error than you
would have from a single log10 function.

The bases e, 2, and 10 occur often enough that having
specialized log functions for these bases is warranted; for
other bases using the formula above should suffice.


Submitted On 06-NOV-2005
Why can't we have a single generic function log(x, b) which takes "base" b as an argument and evaluate log of a given value x to that base? rather than having three functions for ln, log2, and log10?

my two cents,
-Priyank. 


Submitted On 02-MAY-2007
I fully agree with the commenter's opinions.
First and the most important argument is that of jddarcy, that additional floating point operations should be implemented within the library to allow centralized ( java core) optimalisations and tests of such features to evade prescision lost or bugs.
The second argument is according my opinion that most users forget the logarithm arithmetics ( as I did :)) and they expect the method usable to their task findable in the java.lang.Math api. The comment of such a method (log(double base, double x) could explain the arithmetic operations under the hood for the users to remain enlightened.
The final third argument is the one of 'why not' question.

thanx for replies

    tomas r



PLEASE NOTE: JDK6 is formerly known as Project Mustang