diff --git a/libc/src/math/generic/coshf.cpp b/libc/src/math/generic/coshf.cpp --- a/libc/src/math/generic/coshf.cpp +++ b/libc/src/math/generic/coshf.cpp @@ -37,6 +37,7 @@ return FPBits(FPBits::MAX_NORMAL).get_val(); errno = ERANGE; + fputil::raise_except(FE_OVERFLOW); return x + FPBits::inf().get_val(); } diff --git a/libc/src/math/generic/exp10f.cpp b/libc/src/math/generic/exp10f.cpp --- a/libc/src/math/generic/exp10f.cpp +++ b/libc/src/math/generic/exp10f.cpp @@ -41,6 +41,7 @@ if (fputil::get_round() == FE_UPWARD) return static_cast(FPBits(FPBits::MIN_SUBNORMAL)); errno = ERANGE; + fputil::raise_except(FE_UNDERFLOW); return 0.0f; } // x >= log10(2^128) or nan @@ -52,6 +53,7 @@ return static_cast(FPBits(FPBits::MAX_NORMAL)); errno = ERANGE; + fputil::raise_except(FE_OVERFLOW); } // x is +inf or nan return x + static_cast(FPBits::inf()); diff --git a/libc/src/math/generic/exp2f.cpp b/libc/src/math/generic/exp2f.cpp --- a/libc/src/math/generic/exp2f.cpp +++ b/libc/src/math/generic/exp2f.cpp @@ -49,6 +49,7 @@ return static_cast(FPBits(FPBits::MAX_NORMAL)); errno = ERANGE; + fputil::raise_except(FE_OVERFLOW); } // x is +inf or nan return x + FPBits::inf().get_val(); @@ -63,8 +64,10 @@ return x; if (fputil::get_round() == FE_UPWARD) return FPBits(FPBits::MIN_SUBNORMAL).get_val(); - if (x != 0.0f) + if (x != 0.0f) { errno = ERANGE; + fputil::raise_except(FE_UNDERFLOW); + } return 0.0f; } } diff --git a/libc/src/math/generic/expf.cpp b/libc/src/math/generic/expf.cpp --- a/libc/src/math/generic/expf.cpp +++ b/libc/src/math/generic/expf.cpp @@ -51,6 +51,7 @@ if (fputil::get_round() == FE_UPWARD) return static_cast(FPBits(FPBits::MIN_SUBNORMAL)); errno = ERANGE; + fputil::raise_except(FE_UNDERFLOW); return 0.0f; } // x >= 89 or nan @@ -62,6 +63,7 @@ return static_cast(FPBits(FPBits::MAX_NORMAL)); errno = ERANGE; + fputil::raise_except(FE_OVERFLOW); } // x is +inf or nan return x + static_cast(FPBits::inf()); diff --git a/libc/src/math/generic/expm1f.cpp b/libc/src/math/generic/expm1f.cpp --- a/libc/src/math/generic/expm1f.cpp +++ b/libc/src/math/generic/expm1f.cpp @@ -70,6 +70,7 @@ return static_cast(FPBits(FPBits::MAX_NORMAL)); errno = ERANGE; + fputil::raise_except(FE_OVERFLOW); } return x + static_cast(FPBits::inf()); } diff --git a/libc/src/math/generic/sinhf.cpp b/libc/src/math/generic/sinhf.cpp --- a/libc/src/math/generic/sinhf.cpp +++ b/libc/src/math/generic/sinhf.cpp @@ -43,6 +43,7 @@ } errno = ERANGE; + fputil::raise_except(FE_OVERFLOW); return x + FPBits::inf(sign).get_val(); } diff --git a/libc/test/src/math/coshf_test.cpp b/libc/test/src/math/coshf_test.cpp --- a/libc/test/src/math/coshf_test.cpp +++ b/libc/test/src/math/coshf_test.cpp @@ -44,13 +44,16 @@ TEST(LlvmLibcCoshfTest, Overflow) { errno = 0; - EXPECT_FP_EQ(inf, __llvm_libc::coshf(float(FPBits(0x7f7fffffU)))); + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::coshf(float(FPBits(0x7f7fffffU))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); - EXPECT_FP_EQ(inf, __llvm_libc::coshf(float(FPBits(0x42cffff8U)))); + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::coshf(float(FPBits(0x42cffff8U))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); - EXPECT_FP_EQ(inf, __llvm_libc::coshf(float(FPBits(0x42d00008U)))); + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::coshf(float(FPBits(0x42d00008U))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); } diff --git a/libc/test/src/math/exp10f_test.cpp b/libc/test/src/math/exp10f_test.cpp --- a/libc/test/src/math/exp10f_test.cpp +++ b/libc/test/src/math/exp10f_test.cpp @@ -41,13 +41,16 @@ TEST(LlvmLibcExp10fTest, Overflow) { errno = 0; - EXPECT_FP_EQ(inf, __llvm_libc::exp10f(float(FPBits(0x7f7fffffU)))); + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::exp10f(float(FPBits(0x7f7fffffU))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); - EXPECT_FP_EQ(inf, __llvm_libc::exp10f(float(FPBits(0x43000000U)))); + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::exp10f(float(FPBits(0x43000000U))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); - EXPECT_FP_EQ(inf, __llvm_libc::exp10f(float(FPBits(0x43000001U)))); + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::exp10f(float(FPBits(0x43000001U))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); } diff --git a/libc/test/src/math/exp2f_test.cpp b/libc/test/src/math/exp2f_test.cpp --- a/libc/test/src/math/exp2f_test.cpp +++ b/libc/test/src/math/exp2f_test.cpp @@ -42,13 +42,16 @@ TEST(LlvmLibcExp2fTest, Overflow) { errno = 0; - EXPECT_FP_EQ(inf, __llvm_libc::exp2f(float(FPBits(0x7f7fffffU)))); + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::exp2f(float(FPBits(0x7f7fffffU))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); - EXPECT_FP_EQ(inf, __llvm_libc::exp2f(float(FPBits(0x43000000U)))); + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::exp2f(float(FPBits(0x43000000U))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); - EXPECT_FP_EQ(inf, __llvm_libc::exp2f(float(FPBits(0x43000001U)))); + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::exp2f(float(FPBits(0x43000001U))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); } @@ -79,7 +82,8 @@ TEST(LlvmLibcExp2fTest, Underflow) { errno = 0; - EXPECT_FP_EQ(0.0f, __llvm_libc::exp2f(float(FPBits(0xff7fffffU)))); + EXPECT_FP_EQ_WITH_EXCEPTION( + 0.0f, __llvm_libc::exp2f(float(FPBits(0xff7fffffU))), FE_UNDERFLOW); EXPECT_MATH_ERRNO(ERANGE); float x = float(FPBits(0xc3158000U)); diff --git a/libc/test/src/math/expf_test.cpp b/libc/test/src/math/expf_test.cpp --- a/libc/test/src/math/expf_test.cpp +++ b/libc/test/src/math/expf_test.cpp @@ -41,19 +41,23 @@ TEST(LlvmLibcExpfTest, Overflow) { errno = 0; - EXPECT_FP_EQ(inf, __llvm_libc::expf(float(FPBits(0x7f7fffffU)))); + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::expf(float(FPBits(0x7f7fffffU))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); - EXPECT_FP_EQ(inf, __llvm_libc::expf(float(FPBits(0x42cffff8U)))); + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::expf(float(FPBits(0x42cffff8U))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); - EXPECT_FP_EQ(inf, __llvm_libc::expf(float(FPBits(0x42d00008U)))); + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::expf(float(FPBits(0x42d00008U))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); } TEST(LlvmLibcExpfTest, Underflow) { errno = 0; - EXPECT_FP_EQ(0.0f, __llvm_libc::expf(float(FPBits(0xff7fffffU)))); + EXPECT_FP_EQ_WITH_EXCEPTION( + 0.0f, __llvm_libc::expf(float(FPBits(0xff7fffffU))), FE_UNDERFLOW); EXPECT_MATH_ERRNO(ERANGE); float x = float(FPBits(0xc2cffff8U)); diff --git a/libc/test/src/math/expm1f_test.cpp b/libc/test/src/math/expm1f_test.cpp --- a/libc/test/src/math/expm1f_test.cpp +++ b/libc/test/src/math/expm1f_test.cpp @@ -41,13 +41,16 @@ TEST(LlvmLibcExpm1fTest, Overflow) { errno = 0; - EXPECT_FP_EQ(inf, __llvm_libc::expm1f(float(FPBits(0x7f7fffffU)))); + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::expm1f(float(FPBits(0x7f7fffffU))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); - EXPECT_FP_EQ(inf, __llvm_libc::expm1f(float(FPBits(0x42cffff8U)))); + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::expm1f(float(FPBits(0x42cffff8U))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); - EXPECT_FP_EQ(inf, __llvm_libc::expm1f(float(FPBits(0x42d00008U)))); + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::expm1f(float(FPBits(0x42d00008U))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); } diff --git a/libc/test/src/math/sinhf_test.cpp b/libc/test/src/math/sinhf_test.cpp --- a/libc/test/src/math/sinhf_test.cpp +++ b/libc/test/src/math/sinhf_test.cpp @@ -68,13 +68,16 @@ TEST(LlvmLibcSinhfTest, Overflow) { errno = 0; - EXPECT_FP_EQ(inf, __llvm_libc::sinhf(float(FPBits(0x7f7fffffU)))); + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::sinhf(float(FPBits(0x7f7fffffU))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); - EXPECT_FP_EQ(inf, __llvm_libc::sinhf(float(FPBits(0x42cffff8U)))); + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::sinhf(float(FPBits(0x42cffff8U))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); - EXPECT_FP_EQ(inf, __llvm_libc::sinhf(float(FPBits(0x42d00008U)))); + EXPECT_FP_EQ_WITH_EXCEPTION( + inf, __llvm_libc::sinhf(float(FPBits(0x42d00008U))), FE_OVERFLOW); EXPECT_MATH_ERRNO(ERANGE); }