-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc][math][c23] add c23 floating point fmaximum and fminimum functions. #86016
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
Changes from 1 commit
1c6e19c
1f82128
855925a
1ae6510
6805958
4de63fb
5b1339d
7396dfb
767035e
bdea55b
d3d2b8c
e6119bf
417c41d
d5d01c6
dde2428
329449b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
set(TARGET_LIBC_ENTRYPOINTS | ||
fset(TARGET_LIBC_ENTRYPOINTS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will fix it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you may have had a typo adding an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will fix this. |
||
# ctype.h entrypoints | ||
libc.src.ctype.isalnum | ||
libc.src.ctype.isalpha | ||
|
@@ -153,6 +153,30 @@ set(TARGET_LIBM_ENTRYPOINTS | |
libc.src.math.fmax | ||
libc.src.math.fmaxf | ||
libc.src.math.fmaxl | ||
libc.src.math.fmaximum | ||
libc.src.math.fmaximumf | ||
libc.src.math.fmaximuml | ||
libc.src.math.fmaximum_num | ||
libc.src.math.fmaximum_numf | ||
libc.src.math.fmaximum_numl | ||
libc.src.math.fmaximum_mag | ||
libc.src.math.fmaximum_magf | ||
libc.src.math.fmaximum_magl | ||
libc.src.math.fmaximum_mag_num | ||
libc.src.math.fmaximum_mag_numf | ||
libc.src.math.fmaximum_mag_numl | ||
libc.src.math.fminimum | ||
libc.src.math.fminimumf | ||
libc.src.math.fminimuml | ||
libc.src.math.fminimum_num | ||
libc.src.math.fminimum_numf | ||
libc.src.math.fminimum_numl | ||
libc.src.math.fminimum_mag | ||
libc.src.math.fminimum_magf | ||
libc.src.math.fminimum_magl | ||
libc.src.math.fminimum_mag_num | ||
libc.src.math.fminimum_mag_numf | ||
libc.src.math.fminimum_mag_numl | ||
libc.src.math.fmod | ||
libc.src.math.fmodf | ||
libc.src.math.fmodl | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,130 @@ LIBC_INLINE T fmax(T x, T y) { | |
} | ||
} | ||
|
||
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0> | ||
LIBC_INLINE T fmaximum(T x, T y) { | ||
FPBits<T> bitx(x), bity(y); | ||
|
||
if (bitx.is_nan()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: You don't need This could be
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will fix it. thanks |
||
return x; | ||
} else if (bity.is_nan()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use the form:
Here and below. When the body of the if statement returns, there's no need for the else. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok I will fix it. is it ok after I make my changes to do
So I can keep it at two commits? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's ok for you to keep multiple commits, don't need to |
||
return y; | ||
} else if (bitx.sign() != bity.sign()) { | ||
// To make sure that fmax(+0, -0) == +0 == fmax(-0, +0), whenever x and | ||
// y has different signs and both are not NaNs, we return the number | ||
// with positive sign. | ||
return (bitx.is_neg() ? y : x); | ||
} else { | ||
return (x > y ? x : y); | ||
} | ||
} | ||
|
||
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0> | ||
LIBC_INLINE T fminimum(T x, T y) { | ||
const FPBits<T> bitx(x), bity(y); | ||
|
||
if (bitx.is_nan()) { | ||
return x; | ||
} else if (bity.is_nan()) { | ||
return y; | ||
} else if (bitx.sign() != bity.sign()) { | ||
// To make sure that fmin(+0, -0) == -0 == fmin(-0, +0), whenever x and | ||
// y has different signs and both are not NaNs, we return the number | ||
// with negative sign. | ||
return (bitx.is_neg()) ? x : y; | ||
} else { | ||
return (x < y ? x : y); | ||
} | ||
} | ||
|
||
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0> | ||
LIBC_INLINE T fmaximum_num(T x, T y) { | ||
FPBits<T> bitx(x), bity(y); | ||
|
||
if (bitx.is_nan()) { | ||
return y; | ||
} else if (bity.is_nan()) { | ||
return x; | ||
} else if (bitx.sign() != bity.sign()) { | ||
// To make sure that fmax(+0, -0) == +0 == fmax(-0, +0), whenever x and | ||
// y has different signs and both are not NaNs, we return the number | ||
// with positive sign. | ||
return (bitx.is_neg() ? y : x); | ||
} else { | ||
return (x > y ? x : y); | ||
} | ||
} | ||
|
||
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0> | ||
LIBC_INLINE T fminimum_num(T x, T y) { | ||
const FPBits<T> bitx(x), bity(y); | ||
|
||
if (bitx.is_nan()) { | ||
return y; | ||
} else if (bity.is_nan()) { | ||
return x; | ||
} else if (bitx.sign() != bity.sign()) { | ||
// To make sure that fmin(+0, -0) == -0 == fmin(-0, +0), whenever x and | ||
// y has different signs and both are not NaNs, we return the number | ||
// with negative sign. | ||
return (bitx.is_neg()) ? x : y; | ||
} else { | ||
return (x < y ? x : y); | ||
} | ||
} | ||
|
||
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0> | ||
LIBC_INLINE T fmaximum_mag(T x, T y) { | ||
FPBits<T> bitx(x), bity(y); | ||
|
||
if (abs(x) > abs(y)) { | ||
return x; | ||
} else if (abs(y) > abs(x)) { | ||
return y; | ||
} else { | ||
return fmaximum(x, y); | ||
} | ||
} | ||
|
||
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0> | ||
LIBC_INLINE T fminimum_mag(T x, T y) { | ||
FPBits<T> bitx(x), bity(y); | ||
|
||
if (abs(x) < abs(y)) { | ||
return x; | ||
} else if (abs(y) < abs(x)) { | ||
return y; | ||
} else { | ||
return fminimum(x, y); | ||
} | ||
} | ||
|
||
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0> | ||
LIBC_INLINE T fmaximum_mag_num(T x, T y) { | ||
FPBits<T> bitx(x), bity(y); | ||
|
||
if (abs(x) > abs(y)) { | ||
return x; | ||
} else if (abs(y) > abs(x)) { | ||
return y; | ||
} else { | ||
return fmaximum_num(x, y); | ||
} | ||
} | ||
|
||
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0> | ||
LIBC_INLINE T fminimum_mag_num(T x, T y) { | ||
FPBits<T> bitx(x), bity(y); | ||
|
||
if (abs(x) < abs(y)) { | ||
return x; | ||
} else if (abs(y) < abs(x)) { | ||
return y; | ||
} else { | ||
return fminimum_num(x, y); | ||
} | ||
} | ||
|
||
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0> | ||
LIBC_INLINE T fdim(T x, T y) { | ||
FPBits<T> bitx(x), bity(y); | ||
|
Uh oh!
There was an error while loading. Please reload this page.