1239310Sdim// Written in the D programming language
2239310Sdim
3239310Sdim/**
4239310Sdim * Internal math utilities.
5239310Sdim *
6239310Sdim * Copyright: The D Language Foundation 2021.
7239310Sdim * License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
8239310Sdim * Authors: Lu��s Ferreira
9239310Sdim * Source: $(DRUNTIMESRC core/internal/util/_math.d)
10239310Sdim */
11239310Sdimmodule core.internal.util.math;
12239310Sdim
13239310Sdim/**
14239310Sdim * Calculates the maximum of the passed arguments
15239310Sdim * Params:
16239310Sdim *   a = first value to select the maximum from
17249423Sdim *   b = second value to select the maximum from
18239310Sdim * Returns: The maximum of the passed-in values.
19239310Sdim */
20239310SdimT max(T)(T a, T b) pure nothrow @nogc @safe
21249423Sdim{
22239310Sdim    return b > a ? b : a;
23239310Sdim}
24239310Sdim
25239310Sdim/**
26239310Sdim * Calculates the minimum of the passed arguments
27249423Sdim * Params:
28239310Sdim *   a = first value to select the minimum from
29239310Sdim *   b = second value to select the minimum from
30249423Sdim * Returns: The minimum of the passed-in values.
31249423Sdim */
32239310SdimT min(T)(T a, T b) pure nothrow @nogc @safe
33239310Sdim{
34239310Sdim    return b < a ? b : a;
35239310Sdim}
36239310Sdim
37239310Sdim///
38249423Sdim@safe pure @nogc nothrow
39239310Sdimunittest
40239310Sdim{
41239310Sdim    assert(max(1,3) == 3);
42249423Sdim    assert(max(3,1) == 3);
43249423Sdim    assert(max(1,1) == 1);
44249423Sdim}
45249423Sdim
46239310Sdim///
47239310Sdim@safe pure @nogc nothrow
48249423Sdimunittest
49249423Sdim{
50239310Sdim    assert(min(1,3) == 1);
51249423Sdim    assert(min(3,1) == 1);
52239310Sdim    assert(min(1,1) == 1);
53249423Sdim}
54249423Sdim