This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Bad precision Math.log10? [solved: user error] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Bad precision Math.log10? [solved: user error]" Watch "Bad precision Math.log10? [solved: user error]" New topic
Author

Bad precision Math.log10? [solved: user error]

Carl Pettersson
Ranch Hand

Joined: Sep 09, 2003
Posts: 73
I'm having trouble getting good results with quite simple calculations with Math.log10. For instance, I get Math.log10(16)/Math.log10(2)=3.906890595..., but I should get 4.0... Why is this? I'm not doing anything fancy at all, just

to do a base conversion...
I'm using JDK1.6.0_05-b13 on SunOS(sparc SUNW,ultra-4)
[ July 03, 2008: Message edited by: Carl Pettersson ]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13868
    
  10

I tried this just now on Windows XP, with Sun Java 1.6.0 update 6:

The output is: 4.0

You probably know that data types such as double are not infinitely precise. Do you yet 3.90... if you run that exact code? That would be strange. You could try searching the Sun bug database if there's a known issue with regard to this on SunOS.

Do you have another computer (with maybe a different OS) on which you can test your code?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Carl Pettersson
Ranch Hand

Joined: Sep 09, 2003
Posts: 73
It is never too late to be stupid... I've been misreading my output for a few hours straight now About time I call it a day I think. Sorry for any wasted effort...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bad precision Math.log10? [solved: user error]
 
Similar Threads
Double problem - small numbers
Project Euler Problem 25
For Loop Performance
Recursive sum of terms
Working with Verrry Large Numbers