Extend the data range and precision of as3

Source: Internet
Author: User

As3 currently only provides the int, uint, and number numeric types. The valid value range of an int is-2 ^ 31 ~
2 ^ 31-1 (-2147483648 ~ 2147483647). uint indicates the unsigned integer. The valid value range is
0 ~ 2 ^ 32-1 (0 ~ 4294967295) in Adobe official instructions, the expression of number is: "number data types can represent integers, unsigned integers, and floating
Points ." To improve performance as much as possible, the number data type should be used only for floating point numbers, or an integer greater than 32 bits that the int and uint types cannot be stored. Although
Number indicates a 64-bit double-precision value, but the precision range is only 52 bits.
Whether it is an integer that represents more than 52 or a decimal number and multiplication and division that requires a high precision is insufficient. Recently, I have encountered a project where I want to communicate with the socket server written in C ++.
In C ++, int64 type values are used for data verification. In as, number can be used to represent these integers. However, due to insufficient precision, there is a large error:
◆ Number data types Use 64-bit double precision format specified by IEEE binary floating point Arithmetic standard (IEEE-754. This Standard specifies how to use 64 available bits to store floating point numbers. Its
The first digit specifies whether the number is positive or negative. 11 bits are used for index storage in binary format. The remaining 52 bits are used to store "valid bits" (also known as "tails"). The valid bits are 2
N power, n is the index mentioned above.
All the bits of the number data type can be used for the valid bits, or some bits of the number data type can be used for the storage index. The latter can store a larger floating point number than the former. For example, if
The number data type uses all 64-bit to store the valid digits. The maximum number that can be stored is 265-1. If the 11-digit index is used to store the index, the number data type can be
The maximum valid number for storage is 21023.

◆ The minimum and maximum values of the number type can be stored in the static attributes named number. max_value and number. min_value of the number class.
Number. max_value = 1.79769313486231e + 308number. min_value = 4.940656458412467e-

324 although this number range is large, the cost is that the accuracy of this range is reduced. The number data type uses 52 bits to store valid bits. Therefore, those that require more than 52 bits can be accurate.
The number (such as the score 1/3) is an approximate value. If the application requires absolute precision for decimal places, you need to use software that implements fractional Floating Point Arithmetic (rather than binary floating point Arithmetic.
If the number data type is used to store integer values, only 52 valid digits are used. The number data type uses 52 bits and a special hidden bits to represent integers between-9,007,199,254,740,992 (-253) and 9,007,199,254,740,992 (253.

To solve my problem
Code on the crazy search, finally found in an Ajax open source data service framework (graniteds-2.2.0.RC2) for the as data accuracy solution, provides 4
Extended numeric types: Long, biginteger, bignumber, and bigdecimal. They can be understood literally.
To solve the problem of insufficient number type precision, and the efficiency is relatively high.
You can download this extension package from Google Code. The numeric type of the extension is in the graniteds/as3/framework/org/granite/Math directory.

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.