double trouble
John C
johnch_atms at hotmail.com
Wed Mar 1 08:09:03 PST 2006
"Don Clugston" <dac at nospam.com.au> wrote in message
news:du48kq$i5i$1 at digitaldaemon.com...
>
> The trick to maximal efficiency in these conversions is to make sure that
> you only do ONE division (because that's the point at which the rounding
> error occurs). Don't divide by 10 every time, and definitely don't use
> pow. Instead, keep track of a denominator, and every time you'd do a
> v/=10, do denominator*=10 instead. Then, right at the end, divide v by
> denominator.
> The reason this works is that integers can be exactly represented in
> reals, so the multiplies aren't introducing any error. But every time you
> divide by something that isn't a multiple of 2, a tiny roundoff error
> creeps in.
> You'll also reduce the error if you use
> real v=0.0;
> instead of double. Even if you ultimately want a double.
Thanks. Working on the raw bits (actually a 64-bit integer) eventually
proved easier (relatively speaking).
More information about the Digitalmars-d
mailing list