February 26, 2015 Re: What am I doing wrong here - canFind with iota is not working | ||||
---|---|---|---|---|
| ||||
Posted in reply to Laeeth Isharc | 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 I think people diagnosed the problem, but what is the solution...
My preference would be to find a way to construct the program such that it isn't needed.
Failing that, std.math has feqrl and approxEqual for this task.
|
February 26, 2015 Re: What am I doing wrong here - canFind with iota is not working | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | 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 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 I think people diagnosed the problem, but what is the solution... > > My preference would be to find a way to construct the program such that it isn't needed. > > Failing that, std.math has feqrl and approxEqual for this task. |
February 27, 2015 Re: What am I doing wrong here - canFind with iota is not working | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | > 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
|
Copyright © 1999-2021 by the D Language Foundation