Jeg har brug for at vide hvor store hhv. String og Number er. Jeg antager at Number er 64-bit og String er 32-bit, men jeg har svært ved at finde dokumentation for det. Nogen der ved det eller kan trylle et link frem?
Number er 53-bit signed, int er 32-bit signed, uint er 32-bit unsigned. Så vidt, jeg ved, har String ikke rigtigt nogen begrænsning. Det bliver i hvert fald ikke noget, du kommer til at opleve. Det tør jeg næsten garantere.
Nej vent lige. Number er 64-bit, men de 52-/53-bit kommer ind i billedet, når værdien overstiger en vis grænse tror jeg nok, fordi så stryges præcisionen, og tallet er skrevet med brug af e:
"In ActionScript 3.0, the Number data type can represent integers, unsigned integers, and floating-point numbers. However, to maximize performance, you should use the Number data type only for integer values larger than the 32-bit int and uint types can store or for floating-point numbers. To store a floating-point number, include a decimal point in the number. If you omit a decimal point, the number will be stored as an integer.
The Number data type uses the 64-bit double-precision format as specified by the IEEE Standard for Binary Floating-Point Arithmetic (IEEE-754). This standard dictates how floating-point numbers are stored using the 64 available bits. One bit is used to designate whether the number is positive or negative. Eleven bits are used for the exponent, which is stored as base 2. The remaining 52 bits are used to store the significand (also called the mantissa), which is the number that is raised to the power indicated by the exponent."
Der har du forklaringen selv. Men uanset hvad går Flash ind på ét eller andet tidspunkt og gør tallet meget upræcist. Jeg ved dog ikke helt hvor grænsen går. Om det er noget, du skal bruge til noget, er jo op til dig at vurdere.
Nu er det AS2 jeg er interesseret i, og der er mig bekendt ikke int og uint typer. At Number skulle være 53-bit lyder meget mystisk...tror du ikke du har misforstået opbygningen af floating points?
Mht. String er det ikke begrænsninger det handler om, men memory footprint. Jeg har brug for at vide hvor meget hver karakter fylder.
var t0:Number = 7654321987654321; trace(t0 % 10); // tracer korrekt nok 1 var t1:Number = 87654321987654321; trace(t1 % 10); // her tracer den 0, fordi den af cuttet enerne væk trace(t1); // demonstration af manglende enere
Du er vidst mere inde i det dér end mig. Jeg bruger aldrig så store tal alligevel. Dette her står der på siden:
Number data type In ActionScript 3.0, the Number data type can represent integers, unsigned integers, and floating-point numbers. However, to maximize performance, you should use the Number data type only for integer values larger than the 32-bit int and uint types can store or for floating-point numbers. To store a floating-point number, include a decimal point in the number. If you omit a decimal point, the number will be stored as an integer.
The Number data type uses the 64-bit double-precision format as specified by the IEEE Standard for Binary Floating-Point Arithmetic (IEEE-754). This standard dictates how floating-point numbers are stored using the 64 available bits. One bit is used to designate whether the number is positive or negative. Eleven bits are used for the exponent, which is stored as base 2. The remaining 52 bits are used to store the significand (also called the mantissa), which is the number that is raised to the power indicated by the exponent.
By using some of its bits to store an exponent, the Number data type can store floating-point numbers significantly larger than if it used all of its bits for the significand. For example, if the Number data type used all 64 bits to store the significand, it could store a number as large as 265 - 1. By using 11 bits to store an exponent, the Number data type can raise its significand to a power of 21023.
The maximum and minimum values that the Number type can represent are stored in static properties of the Number class called Number.MAX_VALUE and Number.MIN_VALUE.
Number.MAX_VALUE == 1.79769313486231e+308 Number.MIN_VALUE == 4.940656458412467e-324 Although this range of numbers is enormous, the cost of this range is precision. The Number data type uses 52 bits to store the significand, with the result that numbers that require more than 52 bits to represent precisely, such as the fraction 1/3, are only approximations. If your application requires absolute precision with decimal numbers, you need to use software that implements decimal floating-point arithmetic as opposed to binary floating-point arithmetic.
When you store integer values with the Number data type, only the 52 bits of the significand are used. The Number data type uses these 52 bits and a special hidden bit to represent integers from -9,007,199,254,740,992 (-253) to 9,007,199,254,740,992 (253).
Flash Player uses the NaN value not only as the default value for variables of type Number, but also as the result of any operation that should return a number but does not. For example, if you attempt to calculate the square root of a negative number, the result will be NaN. Other special Number values include positive infinity and negative infinity.
NOTE
The result of division by 0 is only NaN if the divisor is also 0. Division by 0 produces infinity when the dividend is positive or -infinity when the dividend is negative.
String data type The String data type represents a sequence of 16-bit characters. Strings are stored internally as Unicode characters, using the UTF-16 format. Strings are immutable values, just as they are in the Java programming language. An operation on a String value returns a new instance of the string. The default value for a variable declared with the String data type is null. The value null is not the same as the empty string (""), even though they both represent the absence of any characters.
Det er data der skal sendes via sattelit, og det koster knaster - derfor skal det fylde så lidt som muligt, og sandsynligvis kan integers puttes ned i Strings. Men jeg kan ikke bruge "jer er ret sikker" til noget - jeg skal være 100% sikker.
Hmmm....faldt over flg. på wikipedia omkring AS3: "String - The String data type represents a sequence of 16-bit characters. Strings are stored internally as Unicode characters, using the UTF-16 format. Previous versions of flash used the UTF-8 format."
Noget tyder altså på at det er 8-bit strings i AS2.
Ja, AS2 bruger UTF-8 og AS3 bruger UTF-16, så det er ændret.
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.