Name: stC104175 Date: 08/02/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
RFE #4074599 is about "Math.log10(double)" (base 10 logarithm). Evaluation
said "While trivial to compute, the log10 function is sufficiently common and
useful that we should eventually provide it". I think that a "Math.pow10
(double)" method may be a useful complement, especially if it is optimized for
integers power. Currently, one can compute
Math.pow(10, x);
But this method has rounding error for some integers values of 'x'. The test
case below illustrate it:
class Test
{
public static void main(String[] args)
{
int count=0;
for (int e=-308; e<=308; e++)
{
final double n1=StrictMath.pow(10, e);
final double n2=Double.parseDouble("1E"+e);
System.out.println(e+"\t "+n2+"\t "+n1);
if (n1!=n2) count++;
}
System.out.println(count+" differences found");
}
}
In 64 cases, the number computed by "pow(10, e)" is not the closest IEEE
floating point representation. Actually, "parseDouble("1E"+e)" give as close or
closer values than "Math.pow(10, e)" for all 'e'. The difference is very small.
Such a small difference may be insignificant in most case, but power of 10 may
be a special case since it is used for scaling human-readable axis, scaling SI
units (centimeters, millimeters, picometers, yoctometers (1E-24 m), etc...) and
others works related to human-readable numbers.
In summary, I'm proposing a "Math.pow10(double)" method with special
optimization (if necessary) for integer power.
Regards,
(Review ID: 107862)
======================================================================
- relates to
-
JDK-4633024 Augment Java math libraries with methods from C libm and IEEE 754
- Closed