Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dividing floating point numbers?

 
Tom Clement
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've made it over many hurdles on this one, but since it's math
intensive and I'm a graphical interface person, I'm having to bone up
on my math.
Let's say I'm calculating a negative exponent by dividing with BigDecimal.
for(int i = 1; i > power; i--)
{
test= test.divide(Dholder,5000,BigDecimal.ROUND_HALF_UP);
}
This works fine, as long as there is no floating point on the power.
But in some cases the power is something like, 223.0754233
I've tried separating the two, and using the right side as a percentage.
e,g, (newPower = Dholder * rightSide, where Dholder is the base of the equation, then dividing one last time by the newPower)
But when I test the result against a calculator, it's still not right.
Although, it's close. Anybody know the correct formula for this?
Thank you in advance,
Tom
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For division, you could divide the mantissas, then just subtract the two exponents. For Multiplication, multiply the mantissas, then add the exponents.
Tom Blough
 
Tom Clement
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, concrete example:
power = -5.300000190734863
base = 20
20 ^-5 = 3.125000E-7 using BigDecimal divide().
How do I calculate the .300000190734863
to arrive at correct answer of
1.2721571e-7
I'm using BigDecimal because of the size of some of the calculations.
Oh, and I've tested the program on whole numbers and it works fine when tested against the calculator, it's the handling of the fractional part that's killing me.
Thank you all, very much...... Tom
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic