Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide float and double versions of fmin and fmax. Improve docs. #7604

Merged
merged 4 commits into from
Sep 9, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Just one template parameter
andralex committed Aug 30, 2020
commit ca2d5438da99f7d889b0b18b39bc725ecbaeb13a
24 changes: 8 additions & 16 deletions std/math.d
Original file line number Diff line number Diff line change
@@ -7234,17 +7234,13 @@ real fdim(real x, real y) @safe pure nothrow @nogc
*
* See_Also: $(REF max, std,algorithm,comparison) is faster because it does not perform the `isNaN` test.
*/
auto fmax(N1, N2)(const N1 x, const N2 y) @safe pure nothrow @nogc
if ((__traits(isFloating, N1) || __traits(isFloating, N2)) && is(typeof(x < y)))
F fmax(F)(const F x, const F y) @safe pure nothrow @nogc
if (__traits(isFloating, F))
{
import std.algorithm.comparison : max;
alias R = typeof(max(x, y));
// Do the more predictable test first. Generates 0 branches with ldc and 1 branch with gdc.
// See https://godbolt.org/z/erxrW9
static if (__traits(isFloating, N1))
{
if (isNaN(x)) return R(y);
}
if (isNaN(x)) return y;
import std.algorithm.comparison : max;
return max(x, y);
}

@@ -7269,17 +7265,13 @@ if ((__traits(isFloating, N1) || __traits(isFloating, N2)) && is(typeof(x < y)))
*
* See_Also: $(REF min, std,algorithm,comparison) is faster because it does not perform the `isNaN` test.
*/
auto fmin(N1, N2)(const N1 x, const N2 y) @safe pure nothrow @nogc
if ((__traits(isFloating, N1) || __traits(isFloating, N2)) && is(typeof(x < y)))
F fmin(F)(const F x, const F y) @safe pure nothrow @nogc
if (__traits(isFloating, F))
{
import std.algorithm.comparison : min;
alias R = typeof(min(x, y));
// Do the more predictable test first. Generates 0 branches with ldc and 1 branch with gdc.
// See https://godbolt.org/z/erxrW9
static if (__traits(isFloating, N1))
{
if (isNaN(x)) return R(y);
}
if (isNaN(x)) return y;
import std.algorithm.comparison : min;
return min(x, y);
}