Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 6 additions & 2 deletions core/libs/prx/libc/src/Math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,9 @@ double APS5_VABI exp_nid_postfix(double x) {
}
if (x > 7.09782712893383973096e+02) {
errno = ERANGE;
return huge * huge;
volatile double overflow = huge * huge;
(void)overflow;
return std::numeric_limits<double>::infinity();
}
if (x < -7.45133219101941108420e+02) {
errno = ERANGE;
Expand Down Expand Up @@ -3765,7 +3767,9 @@ double APS5_VABI cosh_nid_postfix(double x) {
const double w = exp_nid_postfix(0.5 * absolute);
result = 0.5 * w * w;
} else {
result = huge * huge;
volatile double overflow = huge * huge;
(void)overflow;
result = std::numeric_limits<double>::infinity();
}
if (std::isinf(result)) errno = ERANGE;
return result;
Expand Down
25 changes: 25 additions & 0 deletions core/libs/tests/GuestMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,30 @@ static void CheckExp2OverflowRounding() {
}
}

static void CheckExpCoshOverflowRounding() {
const RestoreFloatingPointState saved;
constexpr int modes[] = {FE_TONEAREST, FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO};
constexpr double arguments[] = {709.9, 711.0, -711.0};
for (const int mode : modes) {
Require(std::fesetround(mode) == 0);
for (std::size_t index = 0; index < std::size(arguments); ++index) {
errno = 0;
Require(std::feclearexcept(FE_ALL_EXCEPT) == 0);
const double result = index == 0 ? exp_nid_postfix(arguments[index]) : cosh_nid_postfix(arguments[index]);
Require(errno == ERANGE);
Require(std::isinf(result) && result > 0);
Require(std::fetestexcept(FE_OVERFLOW | FE_INEXACT) == (FE_OVERFLOW | FE_INEXACT));
}
errno = 0;
const double underflow = exp_nid_postfix(-745.2);
Require(errno == ERANGE);
Require(std::bit_cast<std::uint64_t>(underflow) == (mode == FE_UPWARD ? 1u : 0u));
errno = 0;
const double finite = cosh_nid_postfix(710.4);
Require(errno == 0 && std::isfinite(finite) && finite > 0x1p1023);
}
}

static void CheckNearbyintEnvironment() {
const RestoreFloatingPointState saved;
const struct {
Expand Down Expand Up @@ -5456,6 +5480,7 @@ int main() {
CheckSquareRoot();
CheckExp2Errno();
CheckExp2OverflowRounding();
CheckExpCoshOverflowRounding();
CheckFloorAndCeilWithDenormalsAreZero();
CheckExactOperations();
CheckIlogbReadsTheBits();
Expand Down
Loading