mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
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:
@@ -387,8 +387,7 @@ static float Ulp_Error_Half_Float(float test, double reference)
|
||||
}
|
||||
|
||||
// reference is a normal power of two or a zero
|
||||
int ulp_exp =
|
||||
HALF_MANT_DIG - 1 - std::max(ilogb(reference) - 1, HALF_MIN_EXP - 1);
|
||||
int ulp_exp = HALF_MANT_DIG - std::max(ilogb(reference), HALF_MIN_EXP);
|
||||
|
||||
// Scale the exponent of the error
|
||||
return (float)scalbn(testVal - reference, ulp_exp);
|
||||
@@ -469,8 +468,7 @@ float Ulp_Error(float test, double reference)
|
||||
|
||||
// reference is a normal power of two or a zero
|
||||
// The unbiased exponent of the ulp unit place
|
||||
int ulp_exp =
|
||||
FLT_MANT_DIG - 1 - std::max(ilogb(reference) - 1, FLT_MIN_EXP - 1);
|
||||
int ulp_exp = FLT_MANT_DIG - std::max(ilogb(reference), FLT_MIN_EXP);
|
||||
|
||||
// Scale the exponent of the error
|
||||
return (float)scalbn(testVal - reference, ulp_exp);
|
||||
@@ -553,8 +551,7 @@ float 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);
|
||||
|
||||
// Scale the exponent of the error
|
||||
float result = (float)scalbnl(testVal - reference, ulp_exp);
|
||||
|
||||
Reference in New Issue
Block a user