Issue 12245: Document the meaning of FLT_ROUNDS constants for sys.float_info (original) (raw)

float_info.rounds is a bit of an odd fish, and I think it was probably a mistake to include it in sys.float_info in the first place.

All the other float_info fields relate to parameters of the floating-point format, which is fixed, useful information. In contrast, float_info.rounds gives information about the current FPU settings, which are variable. Moreover, it doesn't do that very well: all it does is give information about the FPU settings at the time that Python was compiled, which isn't really very helpful (and perhaps not even that: it reports the value of FLT_ROUNDS, which may not even reflect those FPU settings accurately). I wouldn't mind seeing this field fade quietly into obscurity.

FWIW, the value is taken from C's FLT_ROUNDS, and its interpretation is supposed to be the following (C99 5.2.4.2.2, para 7):

-1: The compiler was unable to determine rounding mode. 0: Round towards zero. 1: Round to nearest (this is the most likely value for float_info.rounds on common platforms). 2: Round towards positive infinity 3: Round towards negative infinity.

all it does is give information about the FPU settings at the time that Python was compiled

Hmm. It's actually a bit better than that: as far as I can tell, it reflects the value of FLT_ROUNDS at the time that Python is started (when the sys module is initialized). OTOH, FLT_ROUNDS on my machine is #define'd to be 1, in violation of the C standards.