What is a short, fast way of testing whether x in [a, b]?
Enjoys Math via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Feb 7 19:09:53 PST 2016
On Monday, 8 February 2016 at 02:47:24 UTC, Enjoys Math wrote:
> Right now I'm using a logical ||:
>
> if (!(2*PI - EPS!float <= t1-t0 || t1-t0 <= 2*PI + EPS!float)) {
>
> But I'll be doing this a lot, so was wondering if there's a D
> native way of doing it.
>
> Thanks.
Currently I have:
@property T EPS(T)() {
static if (is(T == double)) {
return 0.000_000_001;
}
static if (is(T == float)) {
return 0.000_001;
}
static if (is(T == int)) {
return 1;
}
}
alias EPS!float EPSF;
alias EPS!double EPSD;
bool epsEq(T)(T x, T y) {
return x >= y - EPS!T && x <= y + EPS!T;
}
More information about the Digitalmars-d-learn
mailing list