Skip to content

Commit

Permalink
Merge pull request #2348 from sinkuu/fix_clamp
Browse files Browse the repository at this point in the history
Use unsigned-safe comparing in clamp contract
  • Loading branch information
monarchdodra committed Jul 19, 2014
2 parents 11c3da9 + e989418 commit abc8897
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion std/algorithm.d
Expand Up @@ -7262,7 +7262,8 @@ min(upper,val))).
auto clamp(T1, T2, T3)(T1 val, T2 lower, T3 upper)
in
{
assert(lower <= upper);
import std.functional : greaterThan;
assert(!lower.greaterThan(upper));
}
body
{
Expand All @@ -7277,6 +7278,8 @@ unittest
assert(clamp(4, 1, 3) == 3);

assert(clamp(1, 1, 1) == 1);

assert(clamp(5, -1, 2u) == 2);
}

unittest
Expand Down

0 comments on commit abc8897

Please sign in to comment.