Re: What am I doing wrong here - canFind with iota is not working

2015-02-27 Thread bearophile via Digitalmars-d
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

Re: What am I doing wrong here - canFind with iota is not working

2015-02-26 Thread Laeeth Isharc via Digitalmars-d
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...

Re: What am I doing wrong here - canFind with iota is not working

2015-02-26 Thread bearophile via Digitalmars-d
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);

Re: What am I doing wrong here - canFind with iota is not working

2015-02-26 Thread Laeeth Isharc via Digitalmars-d
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

Re: What am I doing wrong here - canFind with iota is not working

2015-02-26 Thread John Colvin via Digitalmars-d
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

Re: What am I doing wrong here - canFind with iota is not working

2015-02-26 Thread John Colvin via Digitalmars-d
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 =

Re: What am I doing wrong here - canFind with iota is not working

2015-02-26 Thread John Colvin via Digitalmars-d
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));

Re: What am I doing wrong here - canFind with iota is not working

2015-02-26 Thread Kingsley via Digitalmars-d
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

Re: What am I doing wrong here - canFind with iota is not working

2015-02-26 Thread Baz via Digitalmars-d
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

What am I doing wrong here - canFind with iota is not working

2015-02-26 Thread Kingsley via Digitalmars-d
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

Re: What am I doing wrong here - canFind with iota is not working

2015-02-26 Thread Baz via Digitalmars-d
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));

Re: What am I doing wrong here - canFind with iota is not working

2015-02-26 Thread Kingsley via Digitalmars-d
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;

Re: What am I doing wrong here - canFind with iota is not working

2015-02-26 Thread Fool via Digitalmars-d
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