Always false float comparisons
Walter Bright via Digitalmars-d
digitalmars-d at puremagic.com
Thu May 19 00:09:30 PDT 2016
On 5/18/2016 10:10 AM, Timon Gehr wrote:
> double kahan(double[] arr){
> double sum = 0.0;
> double c = 0.0;
> foreach(x;arr){
> double y=x-c;
double y = roundToDouble(x - c);
> double t=sum+y;
double t = roundToDouble(sum + y);
> c = (t-sum)-y;
> sum=t;
> }
> return sum;
> }
Those are the only two points in the program that depend on rounding. If you're
implementing Kahan, you'd know that, so there shouldn't be anything difficult
about it.
There's no reason to make the rest of the program suffer inaccuracies.
More information about the Digitalmars-d
mailing list