----- Original Message -----
From: "Sean Luke" <email@hidden>
To: <email@hidden>
Sent: Sunday, December 19, 2004 10:26 PM
Subject: Re: Math conundrum
.
> if it's already a double, then it's already base-2 "imprecise", and
> susceptible as such. Converting it to a String buys you nothing,
> though you might do new BigDecimal("1.8");
>
This was my guess and one other person confirmed off-list. Assuming I have
been forced to a interim calculation double which has resulted in a
"imprecise" base-2 value. Then doing something like String isprecise =
Double.toString(interim); BigDecimal backtoprecise = new
BigDecimal(isprecise); will not work. Because isprecise won't be.
> An easy but inefficient way to get a numerical (non-string) value of
> the form a.b into BigDecimal precisely is to say: new
> BigDecimal(ab).movePointLeft(1)
> For example, new BigDecimal(18).movePointLeft(1) is 1.8 exactly.
>
Is what you are saying that you can sidestep the issue by trying to work
integer or fixed-point somehow and only when done convert back to the
floating-point representation? I used to be better at that when I worked
more assembler and no one really ever used the built-in floating point
stuff. If you wanted say a percentage that was represented as x/y it was
easiest to compute x*100/y where you would get a percentage result to 2
digits anyhow. But the precision isn't terrific and the extra multiplication
isn't the most efficient.
Mike Hall mikehall at spacestar dot net
http://www.spacestar.net/users/mikehall
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden
This email sent to email@hidden