immutable float item = 0.174531f;
r.canFind!q{ feqrel(cast()a, cast()b) >= 21 }(item).writeln;
}
With a recent Phobos bug fix you can now write:
r.canFind!q{ feqrel(a, b) >= 21 }(item).writeln;
Bye,
bearophile
Thanks.
Rough version for Wiki here:
http://wiki.dlang.org/Floating_Point_Gotchas
It could be tidier, but I am not able to do so at moment. Feel
free to change.
On Thursday, 26 February 2015 at 14:04:17 UTC, John Colvin wrote:
On Thursday, 26 February 2015 at 12:39:20 UTC, Laeeth Isharc
wro
On Thursday, 26 February 2015 at 12:39:20 UTC, Laeeth Isharc
wrote:
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
Laeeth Isharc:
Ie I think people diagnosed the problem, but what is the
solution...
A possible solution:
void main() @safe {
import std.stdio, std.range, std.algorithm, std.math;
immutable float oneDegree = (PI / 180.0f);
immutable float first = -(oneDegree * 10.0f);
immutab
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.01;
float[] r = iota(first,second,step).array;
On Thursday, 26 February 2015 at 11:17:12 UTC, Kingsley wrote:
Hardcoding the double[] does work as expected - so why doesn't
it work with the iota generated array?
'double' represents a floating-point type with base 2.
This implies that decimal numbers like 0.1 (= 1/10 = 1/(2*5))
cannot be e
On Thursday, 26 February 2015 at 11:12:42 UTC, Kingsley wrote:
On Thursday, 26 February 2015 at 11:04:58 UTC, Baz 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 ste
On Thursday, 26 February 2015 at 11:12:42 UTC, Kingsley wrote:
On Thursday, 26 February 2015 at 11:04:58 UTC, Baz 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 ste
On Thursday, 26 February 2015 at 11:04:58 UTC, Baz 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.01;
float[] r = iota(first,second,step).array;
writel
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.01;
float[] r = iota(first,second,step).array;
writeln(r);
float item = 0.174531;
writeln(r.canFind(item));
/
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.01;
float[] r = iota(first,second,step).array;
writeln(r);
float item = 0.174531;
writeln(r.canFind(item));
/
float oneDegree = (PI / 180.0);
float first = -(oneDegree * 10.0);
float second = (oneDegree * 10.0);
float step = 0.01;
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
13 matches
Mail list logo