# dividing floating point numbers?

Tom Clement

Greenhorn

Posts: 26

posted 12 years ago

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

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

posted 12 years ago

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 Blough

Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>

Tom Clement

Greenhorn

Posts: 26

posted 12 years ago

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

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