| Andreas Rozek |
|
Rhino_01 - untersucht Datentyp-Konvertierungen"Rhino_01" untersucht implizite und explizite Typ-Konvertierungen zwischen den verschiedenen, von JavaScript unterstützten Datentypen. Der Quelltext ist äußerst einfach und bedarf keiner besonderen Erläuterung. Das Programm wird ohne Angabe von Kommandozeilen-Argumenten aufgerufen java Rhino Rhino_01.js und liefert folgende Ausgabe: Rhino_01 - investigates implicit and explicit type conversions in Rhino
- a Boolean value is printed as true or false
- a Number value is printed as 1 or 0.001, e.g.
- to investigate the latter a little further:
- 1E-1 is written as 0.1
- 1E-2 is written as 0.01
- 1E-3 is written as 0.001
- 1E-4 is written as 0.0001
- 1E-5 is written as 0.00001
- 1E-6 is written as 0.0000010000000000000002
- 1E-7 is written as 1.0000000000000002e-7
- 1E-8 is written as 1.0000000000000002e-8
- 1E-9 is written as 1.0000000000000003e-9
- "adding" true to 1 yields 2
- "adding" false to 1 yields 1
- parseInt("10101010", 2) yields 170
- parseInt("-10101010", 2) yields -170
- parseInt("123", 2) yields 1
- parseInt("-12345", 10) yields -12345
- parseInt("-abcd", 16) yields -43981
- parseInt("0xABCD", 16) yields 43981
- parseFloat("-1.2345") yields -1.2345
- parseFloat("+123e-45") yields 1.23e-43
- parseFloat("0.0000000000000000000000000000000000000001") yields 1e-40
- parseFloat("-1.2345abc") yields -1.2345
- toString(Number.MAX_VALUE) yields 1.7976931348623157e+308
- toString(Number.MIN_VALUE) yields 5e-324
- toString(Number.NaN) yields NaN
- toString(Number.NEGATIVE_INFINITY) yields -Infinity
- toString(Number.POSITIVE_INFINITY) yields Infinity
- toString(+0) yields 0
- toString(-0) yields 0
- (123456).toExponential(3) yields 1.235e+5
- (-123.456e-6).toExponential(3) yields -1.235e-4
- (-123.456e-6).toExponential(20) yields -1.234560000000000051878e-4
- (Number.NaN).toExponential(3) yields NaN
- (Number.NEGATIVE_INFINITY).toExponential(3) yields -Infinity
- (Number.POSITIVE_INFINITY).toExponential(3) yields Infinity
- (123456).toFixed(3) yields 123456.000
- (-123.456e-6).toFixed(3) yields -0.000
- (-123.456e-6).toFixed(20) yields -0.000123456000000000001
- (Number.NaN).toFixed(3) yields NaN
- (Number.NEGATIVE_INFINITY).toFixed(3) yields -Infinity
- (Number.POSITIVE_INFINITY).toFixed(3) yields Infinity
- (123456).toPrecision(3) yields 1.23e+5
- (-123.456e-6).toPrecision(3) yields -0.000123
- (-123.456e-6).toPrecision(20) yields -0.000123456000000000005189
- (Number.NaN).toPrecision(3) yields NaN
- (Number.NEGATIVE_INFINITY).toPrecision(3) yields -Infinity
- (Number.POSITIVE_INFINITY).toPrecision(3) yields Infinity
Dieses Ergebnis wird am besten zusammen mit dem Quelltext des Skriptes analysiert - wer sich mit JavaScript ein wenig auskennt, wird wohl keine Überraschungen erleben. QuelltexteDas hier vorgestellte Skript ist im Quelltext verfügbar:
|
| http://www.Andreas-Rozek.de/Rhino/Acquainting/Rhino_01.html | (letzter Stand: 06.04.2002) |