Avoid some undefined behavior in test_bruteforce. (#2400)

* Ulp_Error*: ilogb(reference) - 1 may overflow if reference is zero.
* binary_i_double Test: DoubleFromUInt32's result is a cl_double and the
attempt is to store it as a cl_double, but p was defined as a pointer to
cl_ulong, resulting in an unintended implicit conversion that is not
valid for out-of-range doubles.
* exp2, tanpi: ensure early exit for NaN.
* shift_right_sticky_128: avoid out-of-range shift if shift value is
exactly 64.
* scalbn: e += n may overflow if n is large, move it after the check for
large n.
This commit is contained in:
Harald van Dijk
2025-07-08 17:59:08 +01:00
committed by GitHub
parent 5997a00b2f
commit 09f43ca916
4 changed files with 15 additions and 17 deletions

View File

@@ -1330,8 +1330,7 @@ float Bruteforce_Ulp_Error_Double(double test, long double reference)
// reference is a normal power of two or a zero
// The unbiased exponent of the ulp unit place
int ulp_exp =
DBL_MANT_DIG - 1 - std::max(ilogbl(reference) - 1, DBL_MIN_EXP - 1);
int ulp_exp = DBL_MANT_DIG - std::max(ilogbl(reference), DBL_MIN_EXP);
// allow correctly rounded results to pass through unmolested. (We might add
// error to it below.) There is something of a performance optimization here