Skip to main content
added 129 characters in body
Source Link
Davislor
  • 9.1k
  • 19
  • 39

Bug With Floating-Point NaN

The a > b ? a : b check will fail when b is NaN and a is not, since comparison with NaN is always false. The expected behavior is to return a. Use fmaxfmaximum_num, fmaxffmaximum_numf or fmaxlfmaximum_numl for these types. (Unlike the fmax family, these are defined to handle NaN and comparisons between +0 and -0 correctly.)

Prior to C23, there is theoretically another issue that could come up with the sign-and-magnitude representation of -0. In C23, all signed integral types are two’s-complement.

Bug With Floating-Point NaN

The a > b ? a : b check will fail when b is NaN and a is not, since comparison with NaN is always false. The expected behavior is to return a. Use fmax, fmaxf or fmaxl for these types.

Prior to C23, there is theoretically another issue that could come up with the sign-and-magnitude representation of -0. In C23, all signed integral types are two’s-complement.

Bug With Floating-Point NaN

The a > b ? a : b check will fail when b is NaN and a is not, since comparison with NaN is always false. The expected behavior is to return a. Use fmaximum_num, fmaximum_numf or fmaximum_numl for these types. (Unlike the fmax family, these are defined to handle NaN and comparisons between +0 and -0 correctly.)

Prior to C23, there is theoretically another issue that could come up with the sign-and-magnitude representation of -0. In C23, all signed integral types are two’s-complement.

Source Link
Davislor
  • 9.1k
  • 19
  • 39

Bug With Floating-Point NaN

The a > b ? a : b check will fail when b is NaN and a is not, since comparison with NaN is always false. The expected behavior is to return a. Use fmax, fmaxf or fmaxl for these types.

Prior to C23, there is theoretically another issue that could come up with the sign-and-magnitude representation of -0. In C23, all signed integral types are two’s-complement.