diff --git a/std/algorithm/searching.d b/std/algorithm/searching.d index d14cf1a3f..9e2c76d10 100644 --- a/std/algorithm/searching.d +++ b/std/algorithm/searching.d @@ -2483,7 +2483,7 @@ Convenience function. Like find, but only returns whether or not the search was successful. See_Also: -$(LREF among) for checking a value against multiple possibilities. +$(REF among, std,algorithm,comparison) for checking a value against multiple possibilities. +/ template canFind(alias pred="a == b") { diff --git a/std/math.d b/std/math.d index 8db6acbb9..965195340 100644 --- a/std/math.d +++ b/std/math.d @@ -527,14 +527,20 @@ enum real SQRT1_2 = SQRT2/2; /** $(SQRT)$(HALF) * = hypot(z.re, z.im). */ Num abs(Num)(Num x) @safe pure nothrow -if (is(typeof(Num.init >= 0)) && is(typeof(-Num.init)) && +if ((is(typeof(Num.init >= 0)) && is(typeof(-Num.init)) || + (is(Num == short) || is(Num == byte))) && !(is(Num* : const(ifloat*)) || is(Num* : const(idouble*)) || is(Num* : const(ireal*)))) { static if (isFloatingPoint!(Num)) return fabs(x); else - return x >= 0 ? x : -x; + { + static if (is(Num == short) || is(Num == byte)) + return x >= 0 ? x : cast(Num) -int(x); + else + return x >= 0 ? x : -x; + } } /// ditto @@ -566,6 +572,14 @@ if (is(Num* : const(ifloat*)) || is(Num* : const(idouble*)) assert(abs(-1L+1i) == sqrt(2.0L)); } +@safe pure nothrow @nogc unittest +{ + short s = -8; + byte b = -8; + assert(abs(s) == 8); + assert(abs(b) == 8); +} + @safe pure nothrow @nogc unittest { import std.meta : AliasSeq;