freebsd-src icon indicating copy to clipboard operation
freebsd-src copied to clipboard

pow,powf(3): Define left shift of negative values

Open karlt opened this issue 1 year ago • 0 comments

A compiler clever enough to know that z is positive with a non-zero biased exponent could, for example, optimize away the scalbnf(z,n) because behavior for left shift of negative values is undefined.

The intended behavior for operator<< in this code is to shift the two's complement representation of n, so that it can be added to the IEEE 754 exponent of z = 2^y'. n may be negative enough to underflow the biased IEEE 754 exponent below zero, which is manifested in the sign bit of j (which would correspond to the IEEE 754 sign bit).

The conversion from u_int32_t to int32_t for out-of-int32_t-range values is implementation defined. The assumed behavior of interpreting the u_int32_t value as a two's complement representation of a signed value is already assumed in many parts of the code, such as uses of GET_FLOAT_WORD() with signed integers.

karlt avatar Mar 11 '24 06:03 karlt