Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of float accuracy

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you an example of float accuracy analysis, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!

Floating-point data type, FLOAT data type is used to store single-precision or double-precision floating-point numbers. Floating point numbers use the IEEE (Society of Electrical and Electronic Engineers) format. A single-precision value of a floating-point type has 4 bytes, including a symbol bit, an 8-bit binary index, and a 23-bit Mantissa. Because the high order bit of the Mantissa is always 1, it is not stored in digital form. This representation provides a range of roughly-3.4E+38~3.4E+38 for float types.

Precision composition of float

Floating-point numbers are expressed in exponential form in the machine and are divided into four parts: number symbol, Mantissa, index symbol and index.

The number symbol occupies 1-bit binary, indicating the positive or negative of the number.

The index symbol occupies a 1-bit binary, indicating the positive or negative of the index.

The Mantissa represents a floating-point significant number, 0.xxxxxxx, but does not store the first zero and dot.

The index stores the valid number of the index.

The number of digits of the index and the Mantissa are determined by the computer system.

Float accuracy difference

Variables can be declared as float or double according to the needs of the application. The main difference between the two types is the cardinality they can represent, the storage they need, and their range.

Value range

Type bits valid numeric range

Float 326-7-3.4x10 (- 38) ~ 3.4x10 (38)

Double 64 15-16-1.7 million 10 (- 308) ~ 1.7 million 10 (308)

Longdouble 128 18-19-1.2 million 10 (- 4932) ~ 1.2 million 10 (4932)

Floating-point variables are represented by Mantissa (the value containing the number) and exponent (the order of magnitude containing the number).

The following table shows the number of Mantissa and exponent digits assigned to each floating point type. The most significant bit of any float or double is always the symbol bit. If the symbol bit is 1, the number is treated as negative; otherwise, the number is treated as positive.

Index and Mantissa

Types

Exponential length

Mantissa length

Float

8-bit

23-bit

Double

11-bit

52-bit

Because the index is stored in unsigned form, the deviation of the index is half of its possible value. For float type, the deviation is 127; for double type, the deviation is 1023. You can calculate the actual index value by subtracting the deviation value.

The Mantissa stored as a binary score is greater than or equal to 1 and less than 2. For float and double types, there is an implicit leading 1 in the Mantissa of the most significant bit position, so that the Mantissa is actually 24 and 53 bits long, respectively, even if the most significant bit has never been stored in memory.

A floating-point packet can store binary floating-point numbers as non-standardized numbers instead of using the storage method just described. A non-standardized number is a non-zero floating-point number with a reserved index value, where the most significant bit of the Mantissa is 0. By using a non-standardized format, the range of floating-point numbers can be extended, but the precision is lost. You cannot control whether floating-point numbers are represented in standardized or non-standardized form; floating-point packages determine the representation. Floating-point packages never use a non-standardized form unless the index becomes less than the minimum value that can be expressed in a standardized form.

The above is all the contents of the article "sample Analysis of float accuracy". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report