Hi John.

Tks help with ldc - will look at that shortly.

So Kingsly needs to use a predicate for canFind that returns true if the two values being compared are close enough to being the same given floating point quirks ?

Ie I think people diagnosed the problem, but what is the solution...

On Thursday, 26 February 2015 at 11:00:05 UTC, John Colvin wrote:
On Thursday, 26 February 2015 at 10:55:43 UTC, Kingsley wrote:
float oneDegree = (PI / 180.0);
float first = -(oneDegree * 10.0);
float second = (oneDegree * 10.0);
float step = 0.000001;
float[] r = iota(first,second,step).array;

writeln(r);

float item = 0.174531;
writeln(r.canFind(item));


// returns false for canFind - even though that float is in the array ???

Never check floating point numbers for equality, unless you've really thought about how the floating point arithmetic for this specific problem will go. Pretty much the only place it's useful to do is in unit tests for maths libraries.

Reply via email to