Skip to content

Commit

Permalink
Fix boundary case in log2_extended_precision_half_safe.
Browse files Browse the repository at this point in the history
log2_extended_precision_half_safe is a modified version of
log2_extended_precision_half_unsafe that avoids denormal intermediate
results via scaling. The unsafe version gives one input, 0x39f6, special
treatment because the approximation is known to be incorrect, but the
safe version did not translate this special treatment correctly: the
special casing happens before downscaling, therefore the constant needs
to be upscaled.

This fixes a pow test failure on FTZ targets.
  • Loading branch information
hvdijk committed Jan 2, 2024
1 parent f6b5f2a commit 90cf2fa
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ T log2_extended_precision_half_safe(const T &x, T *ans_lo, T *hiExp, T *loExp) {

// Single awkward boundary value fix:
const SignedType edge(abacus::detail::cast::as<UnsignedType>(x) == 0x39f6);
remainder = __abacus_select(remainder, T(-0.000144362f16), edge);
// -0.14783 ==> -0.000144362 * 2^10
remainder = __abacus_select(remainder, T(-0.14783f16), edge);

// Set return parameters
*hiExp = abacus::detail::cast::convert<T>(hiExpI);
Expand Down

0 comments on commit 90cf2fa

Please sign in to comment.