OT: Re: is dwt alive?
aarti_pl
aarti at interia.pl
Sun Jul 11 14:39:23 PDT 2010
W dniu 2010-07-11 22:45, "Jérôme M. Berger" pisze:
> aarti_pl wrote:
>> I just would like to say that it is a great news! After discovering that
>> for Java:
>> ----
>> double sum = 0.0;
>> for (int i = 0; i< 10; i++) sum += 0.1;
>> ----
>>
>> sum is equal: 0.9999999999999999
>>
>> I am looking at D with greater and greater sentiment :-) SWT and good
>> precision of calculations is necessary for my program...
>>
> Are you sure D is better? In C, you get 0.99999999999999988898 (not
> surprising since 0.1 cannot be represented exactly in base 2) and I
> would expect D to give the same result...
>
> Jerome
On my computer it is exactly 1.0 (one).
I know that there is explanation of why it is like that, as I found
article about it. I did not get deeper into it (good few pages of text)
as I believe there must better solution for programmers.
My calculator shows proper results, spreadsheet shows proper results and
I think that calculations in my program for such a big fractions should
also give correct result.
Just thought: maybe calculations in D are done internally in more than
64bits and then casted into 64bits? It's a bit surprising for me that C
is also wrong about this sum...
BR
Marcin Kuszczak
(aarti_pl)
More information about the Digitalmars-d-dwt
mailing list