MySQL min/max for DOUBLE type

2019-04-30 11:33发布

问题:

The MySQL documentation for the DOUBLE type is really opaque as to what the minimum and maximum values are.

Permissible values are -1.7976931348623157E+308 to -2.2250738585072014E-308, 0, and 2.2250738585072014E-308 to 1.7976931348623157E+308.

This doesn't make sense to me. Maybe I'm being a mathtard, but I'm not understanding this. There appears to be two possible ranges and zero.

回答1:

Yes, it has a range of possible positive values, zero, and a range of possible negative values.

The reason they're doing it that way is to ensure you get both the maximum and minimum possible numbers on either side of zero.

Alternatively, they could state that the range is -1.7976931348623157E+308 through 1.7976931348623157E+308 but that doesn't give you any information about the numbers closest to zero that they can represent. (the ones with the -308 exponent) and you may think you can represent 1E-999 (which you can't).

For the unsigned variant, it just disallows the negative range, which is possibly another reason why they specified the two ranges separately - you can just ignore the negative range totally in that case.



回答2:

The closest Double to zero is

2.2250738585072014E-308 positive

-2.2250738585072014E-308 negative



标签: mysql double