Range and precision of float and double

Source: Internet
Author: User

1. Scope
The range of float and double is determined by the number of digits of the exponent.
Float has an exponential position of 8 bits, and a double has a 11-bit exponent, distributed as follows:
Float
1bit (sign bit) 8bits (digit digit) 23bits (trailing digit)
Double
1bit (sign bit) 11bits (digit digit) 52bits (trailing digit)
Thus, the index range of float is -127~+128, and the double index range is -1023~+1024, and the digits are divided in the form of complement.
The negative exponent determines the absolute minimum non-zero that the floating point can express, and the positive exponent determines the maximum number of absolute value that the floating point can express, which determines the range of the floating-point value.
The range of float is -2^128 ~ +2^128, that is, the range of -3.40E+38 ~ +3.40e+38;double is -2^1024 ~ +2^1024, or -1.79E+308 ~ +1.79E+308. 2. Accuracy
The precision of float and double is determined by the number of bits in the mantissa. Floating-point numbers are stored in memory by scientific notation, and the integer part is always an implied "1", because it is invariant and therefore cannot affect precision.
float:2^23 = 8388608, a total of seven, which means that there can be up to 7 valid digits, but the absolute guarantee of 6-bit, that is, the precision of float is 6~7 bit valid number;
double:2^52 = 4503599627370496, altogether 16 bits, in the same vein, the precision of the double is 15~16 bit. Excerpted from http://blog.chinaunix.net/uid-26748719-id-3316174.html

Range and precision of float and double

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.