Floating-point IEEE 754

Source: Internet
Author: User
Decimal decimals converted to computer stored procedures

Take 9.625 single-precision (32-bit) as an example

  1. Decimal number to binary representation
    9.625 = 1001.101 = 1x2 3 + 0x22 + 0x21 + 1x20 + 1x2-1 + 0x2-2 + 1x2-3

  2. Binary number Normalization
    IEEE 754 stipulates that the binary representation must be ±d.dd...dxβe by format, (0≤d i <β)
    i.e. 1001.101 = 1.001 101 * 23

  3. Store to Computer
    Single-precision total length 32 bits
    1-23 Statement Mantissa: Because the normalized binary number is only a 1 to the left of the decimal point, so it can be omitted, so that 23 bits are represented by 24 bits. That is, the mantissa is 1.001 101 in 001 101
    24-30 means index: 1.001 101 * 23 of 3
    31 notation: 1 for negative, 0 for positive
    In addition, the digit has 8 digits and can represent a value between 0-255. However, the index is likely to be negative (e.g. 0.625 = 0.101 (binary) = 1.01 * 2-1). Therefore, IEEE 754 specifies that the exponent is an increment of the offset code: the normalized exponent value is +127. So the range of the index changes to-127-128. Then the upper index becomes 130.

    According to the above rule, the decimal number after the binary is stored in the computer as: [0] [1000 0010] [0011 0100 0000 0000 0000 000]

Loss of precision

  1. The number of binary digits after normalization can be much longer than 23 bits, then the computer is stored and loses the latter part. Typical is the 0.58.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes the floating-point IEEE 754, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.