mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 19:37:34 +00:00
LibM: Implement fmin/fmax
This commit is contained in:
parent
987cc904c2
commit
01a49dda85
3 changed files with 81 additions and 0 deletions
|
@ -1364,4 +1364,64 @@ long double scalblnl(long double x, long exponent) NOEXCEPT
|
||||||
{
|
{
|
||||||
return internal_scalbn(x, exponent);
|
return internal_scalbn(x, exponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long double fmaxl(long double x, long double y) NOEXCEPT
|
||||||
|
{
|
||||||
|
if (isnan(x))
|
||||||
|
return y;
|
||||||
|
if (isnan(y))
|
||||||
|
return x;
|
||||||
|
|
||||||
|
return x > y ? x : y;
|
||||||
|
}
|
||||||
|
|
||||||
|
double fmax(double x, double y) NOEXCEPT
|
||||||
|
{
|
||||||
|
if (isnan(x))
|
||||||
|
return y;
|
||||||
|
if (isnan(y))
|
||||||
|
return x;
|
||||||
|
|
||||||
|
return x > y ? x : y;
|
||||||
|
}
|
||||||
|
|
||||||
|
float fmaxf(float x, float y) NOEXCEPT
|
||||||
|
{
|
||||||
|
if (isnan(x))
|
||||||
|
return y;
|
||||||
|
if (isnan(y))
|
||||||
|
return x;
|
||||||
|
|
||||||
|
return x > y ? x : y;
|
||||||
|
}
|
||||||
|
|
||||||
|
long double fminl(long double x, long double y) NOEXCEPT
|
||||||
|
{
|
||||||
|
if (isnan(x))
|
||||||
|
return y;
|
||||||
|
if (isnan(y))
|
||||||
|
return x;
|
||||||
|
|
||||||
|
return x < y ? x : y;
|
||||||
|
}
|
||||||
|
|
||||||
|
double fmin(double x, double y) NOEXCEPT
|
||||||
|
{
|
||||||
|
if (isnan(x))
|
||||||
|
return y;
|
||||||
|
if (isnan(y))
|
||||||
|
return x;
|
||||||
|
|
||||||
|
return x < y ? x : y;
|
||||||
|
}
|
||||||
|
|
||||||
|
float fminf(float x, float y) NOEXCEPT
|
||||||
|
{
|
||||||
|
if (isnan(x))
|
||||||
|
return y;
|
||||||
|
if (isnan(y))
|
||||||
|
return x;
|
||||||
|
|
||||||
|
return x < y ? x : y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,6 +107,12 @@ float fabsf(float) NOEXCEPT;
|
||||||
long double fmodl(long double, long double) NOEXCEPT;
|
long double fmodl(long double, long double) NOEXCEPT;
|
||||||
double fmod(double, double) NOEXCEPT;
|
double fmod(double, double) NOEXCEPT;
|
||||||
float fmodf(float, float) NOEXCEPT;
|
float fmodf(float, float) NOEXCEPT;
|
||||||
|
long double fmaxl(long double, long double) NOEXCEPT;
|
||||||
|
double fmax(double, double) NOEXCEPT;
|
||||||
|
float fmaxf(float, float) NOEXCEPT;
|
||||||
|
long double fminl(long double, long double) NOEXCEPT;
|
||||||
|
double fmin(double, double) NOEXCEPT;
|
||||||
|
float fminf(float, float) NOEXCEPT;
|
||||||
long double remainderl(long double, long double) NOEXCEPT;
|
long double remainderl(long double, long double) NOEXCEPT;
|
||||||
double remainder(double, double) NOEXCEPT;
|
double remainder(double, double) NOEXCEPT;
|
||||||
float remainderf(float, float) NOEXCEPT;
|
float remainderf(float, float) NOEXCEPT;
|
||||||
|
|
|
@ -247,4 +247,19 @@ TEST_CASE(gamma)
|
||||||
EXPECT_EQ(signgam, -1);
|
EXPECT_EQ(signgam, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE(fmax_and_fmin)
|
||||||
|
{
|
||||||
|
EXPECT(fmax(-INFINITY, 0) == 0);
|
||||||
|
EXPECT(fmax(NAN, 12) == 12);
|
||||||
|
EXPECT(fmax(5, NAN) == 5);
|
||||||
|
EXPECT(isnan(fmax(NAN, NAN)));
|
||||||
|
EXPECT(isinf(fmax(1'000'000, INFINITY)));
|
||||||
|
|
||||||
|
EXPECT(isinf(fmin(-INFINITY, 0)));
|
||||||
|
EXPECT(fmin(0, INFINITY) == 0);
|
||||||
|
EXPECT(fmin(NAN, 5) == 5);
|
||||||
|
EXPECT(fmin(0, NAN) == 0);
|
||||||
|
EXPECT(isnan(fmin(NAN, NAN)));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_MAIN(Math)
|
TEST_MAIN(Math)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue