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.