[llvm] [llvm] Add floating point exception status for APFloat's exp function. (PR #203066)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 10 12:53:40 PDT 2026
================
@@ -6093,22 +6094,53 @@ APFloat::Storage &APFloat::Storage::operator=(APFloat::Storage &&RHS) {
return *this;
}
+namespace {
+
+APFloat::opStatus getOpStatusFromLibc(int libc_exceptions) {
+ APFloat::opStatus status = APFloat::opOK;
+ if (libc_exceptions & FE_INVALID)
+ status = static_cast<APFloat::opStatus>(status | APFloat::opInvalidOp);
+ if (libc_exceptions & FE_DIVBYZERO)
+ status = static_cast<APFloat::opStatus>(status | APFloat::opDivByZero);
+ if (libc_exceptions & FE_OVERFLOW)
+ status = static_cast<APFloat::opStatus>(status | APFloat::opOverflow);
+ if (libc_exceptions & FE_UNDERFLOW)
+ status = static_cast<APFloat::opStatus>(status | APFloat::opUnderflow);
+ if (libc_exceptions & FE_INEXACT)
+ status = static_cast<APFloat::opStatus>(status | APFloat::opInexact);
+ return status;
+}
+
+} // namespace
+
// TODO: Support other rounding modes when LLVM libc math implement static
// roundings.
-APFloat exp(const APFloat &X, RoundingMode rounding_mode) {
+std::optional<APFloat> exp(const APFloat &X, RoundingMode rounding_mode,
+ APFloat::opStatus *Status) {
+
if (rounding_mode == APFloatBase::rmNearestTiesToEven) {
if (APFloat::SemanticsToEnum(X.getSemantics()) ==
APFloatBase::S_IEEEsingle) {
- float result = LIBC_NAMESPACE::shared::expf(X.convertToFloat());
+ float x_val = X.convertToFloat();
+ int exc =
+ LIBC_NAMESPACE::shared::check::exp_exceptions(x_val, FE_TONEAREST);
----------------
lntue wrote:
It is a template defined at https://github.com/llvm/llvm-project/blob/main/libc/src/__support/math/check/exp_exceptions.h#L59
It was added in https://github.com/llvm/llvm-project/pull/202503 to centralize floating exception checking without involving fenv.
https://github.com/llvm/llvm-project/pull/203066
More information about the llvm-commits
mailing list