mirror of
https://github.com/dlang/phobos.git
synced 2025-05-01 07:30:33 +03:00
Merge remote-tracking branch 'upstream/stable' into merge_stable
This commit is contained in:
commit
ac821be1de
2 changed files with 17 additions and 3 deletions
|
@ -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")
|
||||
{
|
||||
|
|
16
std/math.d
16
std/math.d
|
@ -527,15 +527,21 @@ 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
|
||||
{
|
||||
static if (is(Num == short) || is(Num == byte))
|
||||
return x >= 0 ? x : cast(Num) -int(x);
|
||||
else
|
||||
return x >= 0 ? x : -x;
|
||||
}
|
||||
}
|
||||
|
||||
/// ditto
|
||||
auto abs(Num)(Num z) @safe pure nothrow @nogc
|
||||
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue