Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How did you get the range of floating-point variables?
How did you get the range of floating-point variables?
The float variable is 4 bytes long and 32 bits binary, and its value range is 1. 18e-38 ~ 3.40e38, that is, (2*2- 126) ~ (2*2 128). Includes sign bit (1 bit), exponent bit (8 bits) and mantissa bit (23 bits).

0 of the sign bit is positive and 1 is negative; The index bit ***8 can represent 0~255 or-126 ~128; Because its value range is determined by exponent, the 23 bits of the remaining mantissa can represent 223 significant bits at most. Calculated by log, log 10(2*223)=6.92, so its significant digits are 6~7.

Floating-point notation uses scientific counting methods to represent real numbers and is used when calculating expressions that require precision. For example, the calculation of square root, or sine, cosine and other calculations beyond human experience, the accuracy of the calculation results needs to use floating-point type.

Extended data

Eight basic data types and their range of values

Integer:

Bytes:-2 7 ~ 2 7-1,that is,-128 ~ 127. 1 byte. Bytes. Add b at the end

Abbreviation:-215 ~ 215-1,namely -32768 ~ 32767. 2 bytes. Short. Add an S at the end.

Signed int:-231~ 231-1,namely-2147483648 ~ 2147483647. 4 bytes. Integer

Unsigned integer: 0 ~ 2 32- 1.

Long:-2 63 ~ 2 63- 1, that is, -922337203685474808 ~ 9233547 8 bytes. Dragon. Add L at the end. (without l)

Floating-point type:

Floating-point type: 4 bytes. Floating. Add an f at the end. (f can also be omitted)

Double: 8 bytes. Double.

Character type:

Character: 2 bytes. Character.

Boolean type:

Boolean type: Boolean type.