-
Notifications
You must be signed in to change notification settings - Fork 68
/
x9.html
1334 lines (1333 loc) · 47.5 KB
/
x9.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html class="split chapter"><head><meta charset="utf-8"><title>9 Type Conversion and Testing # Ⓣ Ⓔ ① Ⓐ — Annotated ES5</title><link rel="stylesheet" href="style.css"><link href="x8.html" title="8 Types " rel="prev">
<link href="spec.html" title="TOC" rel="index">
<link href="x10.html" title="10 Executable Code and Execution Contexts " rel="next">
</head><body><div class="head">
<h2 id="top">Annotated ECMAScript 5.1 <span id="timestamp"></span></h2>
<div id="mascot-treehouse">
<img id="mascot" align="left" src="js-mascot.svg" alt=""><img id="bubble" src="bubble.svg" alt=""></div>
<p id="slogan">‟Ex igne vita”</p>
<div id="annotations"></div>
<script src="timestamp.js"></script></div>
<nav>
<a href="x8.html">← 8 Types </a> –
<a href="spec.html" class="toc-nav">TOC</a> –
<a href="x10.html">10 Executable Code and Execution Contexts →</a>
<ol class="toc"><li><a href="x9.html#x9" id="x9-toc">9 Type Conversion and Testing</a>
<b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> <ol><li><a href="x9.html#x9.1" id="x9.1-toc">9.1 ToPrimitive</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x9.html#x9.2" id="x9.2-toc">9.2 ToBoolean</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x9.html#x9.3" id="x9.3-toc">9.3 ToNumber</a>
<b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> <ol><li><a href="x9.html#x9.3.1" id="x9.3.1-toc">9.3.1 ToNumber Applied to the String Type</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li></ol></li><li><a href="x9.html#x9.4" id="x9.4-toc">9.4 ToInteger</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x9.html#x9.5" id="x9.5-toc">9.5 ToInt32: (Signed 32 Bit Integer)</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x9.html#x9.6" id="x9.6-toc">9.6 ToUint32: (Unsigned 32 Bit Integer)</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x9.html#x9.7" id="x9.7-toc">9.7 ToUint16: (Unsigned 16 Bit Integer)</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x9.html#x9.8" id="x9.8-toc">9.8 ToString</a>
<b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> <ol><li><a href="x9.html#x9.8.1" id="x9.8.1-toc">9.8.1 ToString Applied to the Number Type</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li></ol></li><li><a href="x9.html#x9.9" id="x9.9-toc">9.9 ToObject</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x9.html#x9.10" id="x9.10-toc">9.10 CheckObjectCoercible</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x9.html#x9.11" id="x9.11-toc">9.11 IsCallable</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x9.html#x9.12" id="x9.12-toc">9.12 The SameValue Algorithm</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li></ol></li></ol></nav>
<h2 id="x9">9 Type Conversion and Testing <a href="#x9">#</a> <a href="#x9-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h2>
<p>
The
ECMAScript runtime system performs automatic type conversion as
needed. To clarify the semantics of certain constructs it is useful
to define a set of conversion abstract operations. These abstract
operations are not a part of the language; they are defined here to
aid the specification of the semantics of the language. The
conversion abstract operations are polymorphic; that is, they can
accept a value of any ECMAScript <a href="x8.html#language-type">language type</a>, but not of
<a href="x8.html#specification-type">specification types</a>.</p>
<h3 id="x9.1">9.1 ToPrimitive <a href="#x9.1">#</a> <a href="#x9.1-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h3>
<p>
The
abstract operation ToPrimitive takes an <i>input</i>
argument and an optional argument <i>PreferredType</i>.
The abstract operation ToPrimitive converts its <i>input</i>
argument to a non-Object type. If an object is capable of converting
to more than one primitive type, it may use the optional hint
<i>PreferredType</i> to
favour that type. Conversion occurs according to Table 10:</p>
<center>
<table width="690" border="1" bordercolor="#000000" cellpadding="8" cellspacing="0" rules="ROWS"><caption>Table 10 — ToPrimitive Conversions</caption>
<colgroup><col width="138"><col width="518"></colgroup><tbody><tr valign="TOP"><td width="138" height="9" bgcolor="#c0c0c0">
<p>
<i><b><span class="table-header">Input
Type</span></b></i></p>
</td>
<td width="518" bgcolor="#c0c0c0">
<p>
<i><b><span class="table-header">Result</span></b></i></p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
Undefined</p>
</td>
<td width="518">
<p>
The
result equals the <i>input</i>
argument (no conversion).</p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
Null</p>
</td>
<td width="518">
<p>
The
result equals the <i>input</i>
argument (no conversion).</p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
Boolean</p>
</td>
<td width="518">
<p>
The
result equals the <i>input</i>
argument (no conversion).</p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
Number</p>
</td>
<td width="518">
<p>
The
result equals the <i>input</i>
argument (no conversion).</p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
String</p>
</td>
<td width="518">
<p>
The
result equals the <i>input</i>
argument (no conversion).</p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
Object</p>
</td>
<td width="518">
<p>
Return
a default value for the Object. The default value of an object
is retrieved by calling the [[DefaultValue]] internal method of
the object, passing the optional hint <i>PreferredType</i>.
The behaviour of the [[DefaultValue]] internal method is defined
by this specification for all native ECMAScript objects in
<a href="x8.html#x8.12.8">8.12.8</a>.</p>
</td>
</tr></tbody></table></center>
<h3 id="x9.2">9.2 ToBoolean <a href="#x9.2">#</a> <a href="#x9.2-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h3>
<p>
The
abstract operation ToBoolean converts its argument to a value of
type Boolean according to Table 11:</p>
<center>
<table width="690" border="1" bordercolor="#000000" cellpadding="8" cellspacing="0" rules="ROWS"><caption>Table 11 — ToBoolean Conversions</caption>
<colgroup><col width="138"><col width="518"></colgroup><tbody><tr valign="TOP"><td width="138" height="11" bgcolor="#c0c0c0">
<p>
<i><b><span class="table-header">Argument
Type</span></b></i></p>
</td>
<td width="518" bgcolor="#c0c0c0">
<p>
<i><b><span class="table-header">Result</span></b></i></p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
Undefined</p>
</td>
<td width="518">
<p>
<b>false</b></p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
Null</p>
</td>
<td width="518">
<p>
<b>false</b></p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
Boolean</p>
</td>
<td width="518">
<p>
The
result equals the input argument (no conversion).</p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
Number</p>
</td>
<td width="518">
<p>
The
result is <b>false</b> if the argument is <b>+0</b>, <span class="symbol"><b>−</b></span><b>0</b>,
or <b>NaN</b>; otherwise the result is <b>true</b>.
</p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
String</p>
</td>
<td width="518">
<p>
The
result is <b>false</b> if the argument is the empty String (its
length is zero); otherwise the result is <b>true</b>.</p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>Object</p>
</td>
<td width="518">
<p><b>true</b></p>
</td>
</tr></tbody></table></center>
<h3 id="x9.3">9.3 ToNumber <a href="#x9.3">#</a> <a href="#x9.3-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h3>
<p>
The
abstract operation ToNumber converts its argument to a value of type
Number according to Table 12:</p>
<center>
<table width="690" border="1" bordercolor="#000000" cellpadding="8" cellspacing="0" rules="ROWS"><caption>Table 12 — To Number Conversions</caption>
<colgroup><col width="138"><col width="518"></colgroup><tbody><tr valign="TOP"><td width="138" height="9" bgcolor="#c0c0c0">
<p>
<i><b><span class="table-header">Argument
Type</span></b></i></p>
</td>
<td width="518" bgcolor="#c0c0c0">
<p>
<i><b><span class="table-header">Result</span></b></i></p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
Undefined</p>
</td>
<td width="518">
<p>
<b>NaN</b></p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
Null</p>
</td>
<td width="518">
<p>
<b>+0</b></p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
Boolean</p>
</td>
<td width="518">
<p>
The
result is <b>1</b> if the argument is <b>true</b>. The result is
<b>+0</b> if the argument is <b>false</b>.</p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
Number</p>
</td>
<td width="518">
<p>
The
result equals the input argument (no conversion).</p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
String</p>
</td>
<td width="518">
<p>
See
grammar and note below.</p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
Object</p>
</td>
<td width="518">
<p>
Apply
the following steps:</p>
<ol><li><p class="keep">
Let
<i>primValue</i>
be <a href="#x9.1">ToPrimitive</a>(<i>input
argument</i>, hint
Number).</p>
</li>
<li><p class="keep">
Return
ToNumber(<i>primValue</i>).</p>
</li></ol></td>
</tr></tbody></table></center>
<h4 id="x9.3.1">9.3.1 ToNumber Applied to the String Type <a href="#x9.3.1">#</a> <a href="#x9.3.1-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h4>
<p>
ToNumber
applied to Strings applies the following grammar to the input
String. If the grammar cannot interpret the String as an expansion
of <i>StringNumericLiteral</i>,
then the result of ToNumber is <b>NaN</b>.</p>
<p class="keep">
<i>StringNumericLiteral </i><b>:::</b></p>
<p class="def1-btm">
<i>StrWhiteSpace</i><sub>opt</sub><i><br>StrWhiteSpace</i><sub>opt</sub><i>StrNumericLiteral StrWhiteSpace</i><sub>opt</sub></p>
<p class="keep">
<i>StrWhiteSpace </i><b>:::</b></p>
<p class="def1-btm">
<i>StrWhiteSpaceChar
StrWhiteSpace</i><sub>opt</sub></p>
<p class="keep">
<i>StrWhiteSpaceChar </i><b>:::</b></p>
<p class="def1-btm">
<i>WhiteSpace<br>LineTerminator</i></p>
<p class="keep">
<i>StrNumericLiteral </i><b>:::</b></p>
<p class="def1-btm">
<i>StrDecimalLiteral<br>HexIntegerLiteral</i></p>
<p class="keep">
<i>StrDecimalLiteral </i><b>:::</b></p>
<p class="def1-btm">
<i>StrUnsignedDecimalLiteral<br></i><code><b>+
</b></code> <i>StrUnsignedDecimalLiteral<br></i><code><b>-
</b></code> <i>StrUnsignedDecimalLiteral</i></p>
<p class="keep">
<i>StrUnsignedDecimalLiteral </i><b>:::</b></p>
<p class="def1-btm">
<code><b>Infinity</b></code> <i><br>
DecimalDigits </i><code><b>.</b></code> <i>DecimalDigits</i><sub>opt</sub><i><sub></sub>ExponentPart</i><sub>opt</sub><i><br></i><code><b>.</b></code> <i>DecimalDigits ExponentPart</i><sub>opt</sub><i><br>DecimalDigits
ExponentPart</i><sub>opt</sub></p>
<p class="keep">
<i>DecimalDigits </i><b>:::</b></p>
<p class="def1-btm">
<i>DecimalDigit<br>DecimalDigits
DecimalDigit</i></p>
<p class="keep">
<i>DecimalDigit </i><b>:::</b><i><b>
</b></i><b>one
of</b></p>
<p class="def1-btm">
<code><b>0
1 2 3 4 5 6 7 8 9</b></code></p>
<p class="keep">
<i>ExponentPart </i><b>:::</b></p>
<p class="def1-btm">
<i>ExponentIndicator
SignedInteger</i></p>
<p class="keep">
<i>ExponentIndicator </i><b>:::</b><i><b>
</b></i><b>one
of</b></p>
<p class="def1-btm">
<code><b>e
E</b></code></p>
<p class="keep">
<i>SignedInteger </i><b>:::</b></p>
<p class="def1-btm">
<i>DecimalDigits<br></i><code><b>+
</b></code> <i>DecimalDigits<br></i><code><b>-
</b></code> <i>DecimalDigits</i></p>
<p class="keep">
<i>HexIntegerLiteral </i><b>:::</b></p>
<p class="def1-btm">
<code><b>0x</b></code> <i>HexDigit<br></i><code><b>0X</b></code> <i>HexDigit<br>HexIntegerLiteral HexDigit</i></p>
<p class="keep">
<i>HexDigit </i>::: <b>one
of</b></p>
<p class="def1-btm">
<code><b>0
1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F</b></code></p>
<p>
Some
differences should be noted between the syntax of a
<i>StringNumericLiteral</i>
and a <i>NumericLiteral</i>
(see <a href="x7.html#x7.8.3">7.8.3</a>):</p>
<ul><li><p>
A
<i>StringNumericLiteral</i>
may be preceded and/or followed by white space and/or line
terminators.</p>
</li>
<li><p>
A
<i>StringNumericLiteral</i>
that is decimal may have any number of leading <code><b>0</b></code>
digits.</p>
</li>
<li><p>
A
<i>StringNumericLiteral</i>
that is decimal may be preceded by <code><b>+</b></code>
or <code><b>-</b></code> to indicate
its sign.</p>
</li>
<li><p>
A
<i>StringNumericLiteral</i>
that is empty or contains only white space is converted to <b>+0</b>.</p>
</li></ul><p>
The
conversion of a String to a Number value is similar overall to the
determination of the Number value for a numeric literal (see <a href="x7.html#x7.8.3">7.8.3</a>),
but some of the details are different, so the process for converting
a String numeric literal to a value of Number type is given here in
full. This value is determined in two steps: first, a mathematical
value (MV) is derived from the String numeric literal; second, this
mathematical value is rounded as described below.</p>
<ul><li><p>
The
MV of <i>StringNumericLiteral</i>
<b>:::</b> [empty]
is 0.</p>
</li>
<li><p>
The
MV of <i>StringNumericLiteral</i>
<b>:::</b> <i>StrWhiteSpace</i>
is 0.</p>
</li>
<li><p>
The
MV of <i>StringNumericLiteral</i>
<b>:::</b> <i>StrWhiteSpace</i><sub>opt</sub><i>StrNumericLiteral</i>
<i>StrWhiteSpace</i><sub>opt</sub>
is the MV of <i>StrNumericLiteral</i>,
no matter whether white space is present or not.</p>
</li>
<li><p>
The
MV of <i>StrNumericLiteral</i>
<b>:::</b> <i>StrDecimalLiteral</i>
is the MV of <i>StrDecimalLiteral</i>.</p>
</li>
<li><p>
The
MV of <i>StrNumericLiteral</i>
<b>:::</b> <i>HexIntegerLiteral</i>
is the MV of <i>HexIntegerLiteral</i>.</p>
</li>
<li><p>
The
MV of <i>StrDecimalLiteral</i>
<b>:::</b> <i>StrUnsignedDecimalLiteral</i>
is the MV of <i>StrUnsignedDecimalLiteral</i>.</p>
</li>
<li><p>
The
MV of <i>StrDecimalLiteral</i>
<b>:::</b> <code><b>+</b></code>
<i>StrUnsignedDecimalLiteral</i>
is the MV of <i>StrUnsignedDecimalLiteral</i>.</p>
</li>
<li><p>
The
MV of <i>StrDecimalLiteral</i>
<b>:::</b> <code><b>-</b></code>
<i>StrUnsignedDecimalLiteral</i>
is the negative of the MV of <i>StrUnsignedDecimalLiteral</i>.
(Note that if the MV of <i>StrUnsignedDecimalLiteral</i>
is 0, the negative of this MV is also 0. The rounding rule
described below handles the conversion of this signless
mathematical zero to a floating-point <b>+0</b> or <span class="symbol"><b>−</b></span><b>0</b>
as appropriate.)</p>
</li>
<li><p>
The
MV of <i>StrUnsignedDecimalLiteral</i><b>:::
</b><code><b>Infinity</b></code><b>
</b>is 10<sup>10000</sup>
(a value so large that it will round to <b>+</b><span class="symbol"><b>∞</b></span>).</p>
</li>
<li><p>
The
MV of <i>StrUnsignedDecimalLiteral</i><b>:::
</b><i>DecimalDigits</i><code><b>.</b></code><b>
</b>is the MV of <i>DecimalDigits</i>.</p>
</li>
<li><p>
The
MV of <i>StrUnsignedDecimalLiteral</i><b>:::
</b><i>DecimalDigits </i><code><b>.</b></code> <i>DecimalDigits</i><b>
</b>is the MV of the first <i>DecimalDigits</i>
plus (the MV of the second <i>DecimalDigits</i><b>
</b>times 10<sup><span class="symbol">−</span></sup><sup><i>n</i></sup>),
where <i>n</i> is the
number of characters in the second <i>DecimalDigits</i>.</p>
</li>
<li><p>
The
MV of <i>StrUnsignedDecimalLiteral</i><b>::: </b><i>DecimalDigits</i><code><b>.</b></code> <i>ExponentPart </i>is the MV of
<i>DecimalDigits</i> times 10<sup><i>e</i></sup>, where <i>e</i>
is the MV of <i>ExponentPart</i>.</p>
</li>
<li><p>
The
MV of <i>StrUnsignedDecimalLiteral</i><b>::: </b><i>DecimalDigits</i><code><b>.</b></code> <i>DecimalDigits ExponentPart </i>is (the MV of the first
<i>DecimalDigits</i> plus (the MV of the second <i>DecimalDigits</i><i><b>
</b></i>times 10<sup><span class="symbol">−</span></sup><sup><i>n</i></sup>))
times 10<sup><i>e</i></sup>, where <i>n</i> is the number of
characters in the second <i>DecimalDigit</i>s and <i>e</i> is
the MV of <i>ExponentPart</i>.</p>
</li>
<li><p>
The
MV of <i>StrUnsignedDecimalLiteral</i><b>:::</b><code><b>.</b></code> <i>DecimalDigits</i> is the MV of
<i>DecimalDigits</i><i> </i>times 10<sup><span class="symbol">−</span></sup><sup><i>n</i></sup>,
where <i>n</i> is the number of characters in <i>DecimalDigit</i>s.</p>
</li>
<li><p>
The
MV of <i>StrUnsignedDecimalLiteral</i><b>:::</b><code><b>.</b></code> <i>DecimalDigits ExponentPart </i>is
the MV of <i>DecimalDigits</i><i> </i>times 10<sup><i>e</i></sup><sup><span class="symbol">−</span></sup><sup><i>n</i></sup>,
where <i>n</i> is the number of characters in <i>DecimalDigit</i>s
and <i>e</i> is the MV of
<i>ExponentPart</i>.</p>
</li>
<li><p>
The
MV of <i>StrUnsignedDecimalLiteral</i><b>::: </b><i>DecimalDigits</i>
is the MV of <i>DecimalDigits</i>.</p>
</li>
<li><p>
The
MV of <i>StrUnsignedDecimalLiteral</i><b>::: </b><i>DecimalDigits</i>
<i>ExponentPart </i>is the MV of
<i>DecimalDigits</i> times 10<sup><i>e</i></sup>, where <i>e</i>
is the MV of <i>ExponentPart</i>.</p>
</li>
<li><p>
The
MV of <i>DecimalDigits</i> <b>:::</b> <i>DecimalDigit</i> is
the MV of <i>DecimalDigit</i>.</p>
</li>
<li><p>
The
MV of <i>DecimalDigits</i> <b>:::</b> <i>DecimalDigits</i>
<i>DecimalDigit</i> is (the MV of <i>DecimalDigits</i> times 10)
plus the MV of <i>DecimalDigit</i>.</p>
</li>
<li><p>
The
MV of <i>ExponentPart </i><b>::: </b><i>ExponentIndicator
SignedInteger</i><i> </i>is
the MV of <i>SignedInteger</i>.</p>
</li>
<li><p>
The
MV of <i>SignedInteger </i><b>::: </b><i>DecimalDigits</i><i><b>
</b></i>is the MV of <i>DecimalDigits</i>.</p>
</li>
<li><p>
The
MV of <i>SignedInteger </i><b>::: </b><code><b>+</b></code> <i>DecimalDigits</i><i> </i>is
the MV of <i>DecimalDigits</i>.</p>
</li>
<li><p>
The
MV of <i>SignedInteger </i><b>::: </b><code><b>-</b></code> <i>DecimalDigits</i><i> </i>is the negative of the MV of
<i>DecimalDigits</i>.</p>
</li>
<li><p>
The
MV of <i>DecimalDigit</i> <b>:::</b> <code><b>0</b></code>
or of <i>HexDigit</i> <b>:::</b>
<code><b>0</b></code> is 0.</p>
</li>
<li><p>
The
MV of <i>DecimalDigit</i> <b>:::</b> <code><b>1</b></code>
or of <i>HexDigit</i> <b>:::</b>
<code><b>1</b></code> is 1.</p>
</li>
<li><p>
The
MV of <i>DecimalDigit</i> <b>:::</b> <code><b>2</b></code>
or of <i>HexDigit</i> <b>:::</b>
<code><b>2</b></code> is 2.</p>
</li>
<li><p>
The
MV of <i>DecimalDigit</i> <b>:::</b> <code><b>3</b></code>
or of <i>HexDigit</i> <b>:::</b>
<code><b>3</b></code> is 3.</p>
</li>
<li><p>
The
MV of <i>DecimalDigit</i> <b>:::</b> <code><b>4</b></code>
or of <i>HexDigit</i> <b>:::</b>
<code><b>4</b></code> is 4.</p>
</li>
<li><p>
The
MV of <i>DecimalDigit</i> <b>:::</b> <code><b>5</b></code>
or of <i>HexDigit</i> <b>:::</b>
<code><b>5</b></code> is 5.</p>
</li>
<li><p>
The
MV of <i>DecimalDigit</i> <b>:::</b> <code><b>6</b></code>
or of <i>HexDigit</i> <b>:::</b>
<code><b>6</b></code> is 6.</p>
</li>
<li><p>
The
MV of <i>DecimalDigit</i> <b>:::</b> <code><b>7</b></code>
or of <i>HexDigit</i> <b>:::</b>
<code><b>7</b></code> is 7.</p>
</li>
<li><p>
The
MV of <i>DecimalDigit</i> <b>:::</b> <code><b>8</b></code>
or of <i>HexDigit</i> <b>:::</b>
<code><b>8</b></code> is 8.</p>
</li>
<li><p>
The
MV of <i>DecimalDigit</i> <b>:::</b> <code><b>9</b></code>
or of <i>HexDigit</i> <b>:::</b>
<code><b>9</b></code> is 9.</p>
</li>
<li><p>
The
MV of <i>HexDigit</i> <b>:::</b> <code><b>a</b></code>
or of <i>HexDigit</i> <b>:::</b>
<code><b>A</b></code> is 10.</p>
</li>
<li><p>
The
MV of <i>HexDigit</i> <b>:::</b> <code><b>b</b></code>
or of <i>HexDigit</i> <b>:::</b>
<code><b>B</b></code> is 11.</p>
</li>
<li><p>
The
MV of <i>HexDigit</i> <b>:::</b> <code><b>c</b></code>
or of <i>HexDigit</i> <b>:::</b>
<code><b>C</b></code> is 12.</p>
</li>
<li><p>
The
MV of <i>HexDigit</i> <b>:::</b> <code><b>d</b></code>
or of <i>HexDigit</i> <b>:::</b>
<code><b>D</b></code> is 13.</p>
</li>
<li><p>
The
MV of <i>HexDigit</i> <b>:::</b> <code><b>e</b></code>
or of <i>HexDigit</i> <b>:::</b>
<code><b>E</b></code> is 14.</p>
</li>
<li><p>
The
MV of <i>HexDigit</i> <b>:::</b> <code><b>f</b></code>
or of <i>HexDigit</i> <b>:::</b>
<code><b>F</b></code> is 15.</p>
</li>
<li><p>
The
MV of <i>HexIntegerLiteral </i><b>:::</b> <code><b>0x</b></code>
<i>HexDigit</i> is the MV of
<i>HexDigit</i>.</p>
</li>
<li><p>
The
MV of <i>HexIntegerLiteral </i><b>:::</b> <code><b>0X</b></code>
<i>HexDigit</i> is the MV of
<i>HexDigit</i>.</p>
</li>
<li><p>
The
MV of <i>HexIntegerLiteral </i><b>:::</b> <i>HexIntegerLiteral</i>
<i>HexDigit</i> is (the MV of <i>HexIntegerLiteral</i> times 16)
plus the MV of <i>HexDigit</i>.</p>
</li></ul><p>
Once
the exact MV for a String numeric literal has been determined, it is
then rounded to a value of the Number type. If the MV is 0, then the
rounded value is +0 unless the first non white space character in
the String numeric literal is ‘<code><b>-</b></code>’,
in which case the rounded value is <span class="symbol">−</span>0.
Otherwise, the rounded value must be the Number value for the MV (in
the sense defined in <a href="x8.html#x8.5">8.5</a>), unless the literal includes a
<i>StrUnsignedDecimalLiteral</i>
and the literal has more than 20 significant digits, in which case
the Number value may be either the Number value for the MV of a
literal produced by replacing each significant digit after the 20th
with a 0 digit or the Number value for the MV of a literal produced
by replacing each significant digit after the 20th with a 0 digit
and then incrementing the literal at the 20th digit position. A
digit is <i>significant</i> if it is not part of an <i>ExponentPart</i>
and</p>
<ul><li><p>
it
is not <b>0</b>;
or</p>
</li>
<li><p>
there
is a nonzero digit to its left and there is a nonzero digit, not in
the <i>ExponentPart</i>,
to its right.</p>
</li></ul><h3 id="x9.4">9.4 ToInteger <a href="#x9.4">#</a> <a href="#x9.4-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h3>
<p>
The
abstract operation ToInteger converts its argument to an integral
numeric value. This abstract operation functions as follows:</p>
<ol><li><p>
Let
<i>number</i> be the result of calling <a href="#x9.3">ToNumber</a> on the input
argument.</p>
</li>
<li><p>
If
<i>number</i> is <b>NaN</b>, return <b>+0</b>.</p>
</li>
<li><p>
If
<i>number</i> is <b>+0</b>, <span class="symbol"><b>−</b></span><b>0</b>,
<b>+</b><span class="symbol"><b>∞</b></span><b>,</b> or <span class="symbol"><b>−∞</b></span>,
return <i>number</i>.</p>
</li>
<li><p>
Return
the result of computing <a href="x5.html#sign">sign</a>(<i>number</i>) * <a href="x5.html#floor">floor</a>(<a href="x5.html#abs">abs</a>(<i>number</i>)).</p>
</li></ol><h3 id="x9.5">9.5 ToInt32: (Signed 32 Bit Integer) <a href="#x9.5">#</a> <a href="#x9.5-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h3>
<p>
The
abstract operation ToInt32 converts its argument to one of 2<sup>32</sup>
integer values in the range <span class="symbol">−</span>2<sup>31</sup>
through 2<sup>31</sup><span class="symbol">−</span>1,
inclusive. This abstract operation functions as follows:</p>
<ol><li><p>
Let
<i>number</i> be the result of calling <a href="#x9.3">ToNumber</a> on the input
argument.</p>
</li>
<li><p>
If
<i>number</i> is <b>NaN</b>, <b>+0</b>, <span class="symbol"><b>−</b></span><b>0</b>,
<b>+</b><span class="symbol"><b>∞</b></span>, or <span class="symbol"><b>−∞</b></span>,
return <b>+0</b>.</p>
</li>
<li><p>
Let
<i>posInt</i> be <a href="x5.html#sign">sign</a>(<i>number</i>) * <a href="x5.html#floor">floor</a>(<a href="x5.html#abs">abs</a>(<i>number</i>)).</p>
</li>
<li><p>
Let
<i>int32bit</i> be <i>posInt</i> <a href="x5.html#modulo">modulo</a> 2<sup>32</sup>; that is, a
finite integer value k of Number type with positive sign and less
than 2<sup>32</sup> in magnitude such that the mathematical
difference of <i>posInt</i> and k is mathematically an integer
multiple of 2<sup>32</sup>.</p>
</li>
<li><p>
If
<i>int32bit</i> is greater than or equal to 2<sup>31</sup>, return
<i>int32bit</i> <span class="symbol">−</span> 2<sup>32</sup>,
otherwise return <i>int32bit</i>.</p>
</li></ol><p>
</p><p><b class="note">NOTE</b> Given the above definition of ToInt32:</p>
<ul><li><p>
The ToInt32
abstract operation is idempotent: if applied to a result that it
produced, the second application leaves that value unchanged.</p>
</li>
<li><p>
ToInt32(<a href="#x9.6">ToUint32</a>(<i>x</i>))
is equal to ToInt32(<i>x</i>)
for all values of <i>x</i>.
(It is to preserve this latter property that +<span class="symbol"><b>∞</b></span>
and <span class="symbol">−</span><span class="symbol"><b>∞</b></span>
are mapped to <b>+0</b>.)</p>
</li>
<li><p>
ToInt32 maps <span class="symbol"><b>−</b></span><b>0</b>
to <b>+0</b>.</p>
</li></ul><h3 id="x9.6">9.6 ToUint32: (Unsigned 32 Bit Integer) <a href="#x9.6">#</a> <a href="#x9.6-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h3>
<p>
The
abstract operation ToUint32 converts its argument to one of 2<sup>32</sup>
integer values in the range 0
through 2<sup>32</sup><span class="symbol">−</span>1,
inclusive. This abstraction operation functions as follows:</p>
<ol><li><p>
Let
<i>number</i> be the result of calling <a href="#x9.3">ToNumber</a> on the input
argument.</p>
</li>
<li><p>
If
<i>number</i> is <b>NaN</b>, +0, <span class="symbol">−</span>0,
+<span class="symbol"><b>∞</b></span>, or <span class="symbol">−</span><span class="symbol"><b>∞</b></span>,
return <b>+0</b>.</p>
</li>
<li><p>
Let
<i>posInt</i> be <a href="x5.html#sign">sign</a>(<i>number</i>) * <a href="x5.html#floor">floor</a>(<a href="x5.html#abs">abs</a>(<i>number</i>)).</p>
</li>
<li><p>
Let
<i>int32bit</i> be <i>posInt</i> <a href="x5.html#modulo">modulo</a> 2<sup>32</sup>; that is, a
finite integer value k of Number type with positive sign and less
than 2<sup>32</sup> in magnitude such that the mathematical
difference of <i>posInt</i> and k is mathematically an integer
multiple of 2<sup>32</sup>.</p>
</li>
<li><p>
Return
<i>int32bit</i>.</p>
</li></ol><p>
</p><p><b class="note">NOTE</b> Given the above definition of ToUInt32:</p>
<ul><li><p>
Step 5 is the
only difference between ToUint32 and <a href="#x9.5">ToInt32</a>.</p>
</li>
<li><p>
The ToUint32
abstract operation is idempotent: if applied to a result that it
produced, the second application leaves that value unchanged.</p>
</li>
<li><p>
ToUint32(<a href="#x9.5">ToInt32</a>(<i>x</i>))
is equal to ToUint32(<i>x</i>)
for all values of <i>x</i>.
(It is to preserve this latter property that <b>+</b><span class="symbol"><b>∞</b></span>
and <span class="symbol"><b>−∞</b></span> are mapped to
<b>+0</b>.)</p>
</li>
<li><p>
ToUint32 maps <span class="symbol"><b>−</b></span><b>0</b>
to <b>+0</b>.</p>
</li></ul><h3 id="x9.7">9.7 ToUint16: (Unsigned 16 Bit Integer) <a href="#x9.7">#</a> <a href="#x9.7-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h3>
<p>
The
abstract operation ToUint16 converts its argument to one of 2<sup>16</sup>
integer values in the range 0
through 2<sup>16</sup><span class="symbol">−</span>1,
inclusive. This abstract operation functions as follows:</p>
<ol><li><p>
Let
<i>number</i> be the result of calling <a href="#x9.3">ToNumber</a> on the input
argument.</p>
</li>
<li><p>
If
<i>number</i> is <b>NaN</b>, +0, <span class="symbol">−</span>0,
+<span class="symbol"><b>∞</b></span>, or <span class="symbol">−</span><span class="symbol"><b>∞</b></span>,
return <b>+0</b>.</p>
</li>
<li><p>
Let
<i>posInt</i> be <a href="x5.html#sign">sign</a>(<i>number</i>) * <a href="x5.html#floor">floor</a>(<a href="x5.html#abs">abs</a>(<i>number</i>)).</p>
</li>
<li><p>
Let
<i>int16bit</i> be <i>posInt</i> <a href="x5.html#modulo">modulo</a> 2<sup>16</sup>; that is, a
finite integer value <i>k</i> of Number type with positive sign and
less than 2<sup>16</sup> in magnitude such that the mathematical
difference of <i>posInt</i> and <i>k</i> is mathematically an
integer multiple of 2<sup>16</sup>.</p>
</li>
<li><p>
Return
<i>int16bit</i>.</p>
</li></ol><p>
</p><p><b class="note">NOTE</b> Given the above definition of ToUint16:</p>
<ul><li><p>
The substitution
of 2<sup>16</sup>
for 2<sup>32</sup>
in step 4 is the only difference between <a href="#x9.6">ToUint32</a> and ToUint16.</p>
</li>
<li><p>
ToUint16 maps <span class="symbol"><b>−</b></span><b>0</b>
to <b>+0</b>.</p>
</li></ul><h3 id="x9.8">9.8 ToString <a href="#x9.8">#</a> <a href="#x9.8-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h3>
<p class="sm-btm">
The
abstract operation ToString converts its argument to a value of type
String according to Table 13:</p>
<center>
<table width="690" border="1" bordercolor="#000000" cellpadding="8" cellspacing="0" rules="ROWS"><caption>Table 13 — ToString Conversions</caption>
<colgroup><col width="138"><col width="518"></colgroup><tbody><tr valign="TOP"><td width="138" height="9" bgcolor="#c0c0c0">
<p>
<i><b><span class="table-header">Argument
Type</span></b></i></p>
</td>
<td width="518" bgcolor="#c0c0c0">
<p>
<i><b><span class="table-header">Result</span></b></i></p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
Undefined</p>
</td>
<td width="518">
<p><code><b>"undefined"</b></code></p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
Null</p>
</td>
<td width="518">
<p><code><b>"null"</b></code></p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
Boolean</p>
</td>
<td width="518">
<p>If
the argument is <b>true</b>, then the result is <code><b>"true"</b></code>.</p>
<p>If
the argument is <b>false</b>, then the result is <code><b>"false"</b></code><b>.</b></p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
Number</p>
</td>
<td width="518">
<p>See
<a href="#x9.8.1">9.8.1</a>.</p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
String</p>
</td>
<td width="518">
<p>Return
the input argument (no conversion)</p>
</td>
</tr><tr valign="TOP"><td width="138">
<p>
Object</p>
</td>
<td width="518">
<p>Apply
the following steps:</p>
<p>
1.
Let <i>primValue</i>
be <a href="#x9.1">ToPrimitive</a>(input argument, hint String).</p>
<p>
2.
Return ToString(<i>primValue</i>).</p>
</td>
</tr></tbody></table></center>
<h4 id="x9.8.1">9.8.1 ToString Applied to the Number Type <a href="#x9.8.1">#</a> <a href="#x9.8.1-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h4>
<p>
The
abstract operation ToString converts a Number <i>m</i>
to String format as follows:</p>
<ol><li><p>
If
<i>m</i> is <b>NaN</b>, return the String <code><b>"NaN"</b></code>.</p>
</li>
<li><p>
If
<i>m</i> is <b>+0</b> or <span class="symbol"><b>−</b></span><b>0</b>,
return the String <code><b>"0"</b></code>.</p>
</li>
<li><p>
If
<i>m</i> is less than zero, return the String concatenation of the
String <code><b>"-"</b></code>
and ToString(<span class="symbol">−</span><i>m</i>).</p>
</li>
<li><p>
If
<i>m</i> is infinity, return the String <code><b>"Infinity"</b></code>.</p>
</li>
<li><p>
Otherwise,
let <i>n</i>, <i>k</i>, and <i>s</i> be integers such that <i>k</i>
<span class="symbol">≥</span> 1, 10<sup><i>k</i></sup><sup><span class="symbol">−</span></sup><sup>1</sup><span class="symbol">≤</span> <i>s</i> < 10<sup><i>k</i></sup>,
the Number value for <i>s</i> <span class="symbol">×</span>
10<sup><i>n</i></sup><sup><span class="symbol"><i>−</i></span></sup><sup><i>k</i></sup>
is <i>m</i>, and <i>k</i> is as small as possible. Note that <i>k</i>
is the number of digits in the decimal representation of <i>s</i>,
that <i>s</i> is not divisible by 10, and that the least
significant digit of <i>s</i> is not necessarily uniquely
determined by these criteria.</p>
</li>
<li><p>
If
<i>k</i> <span class="symbol">≤</span> <i>n</i> <span class="symbol">≤</span>
21, return the String consisting of the <i>k</i> digits of the
decimal representation of s (in order, with no leading zeroes),
followed by <i>n</i><span class="symbol"><i>−</i></span><i>k</i>
occurrences of the character ‘<code><b>0</b></code>’.</p>
</li>
<li><p>
If
0 < n <span class="symbol">≤</span> 21, return the
String consisting of the most significant <i>n</i> digits of the
decimal representation of <i>s</i>, followed by a decimal point
‘<code><b>.</b></code>’, followed
by the remaining <i>k</i><span class="symbol"><i>−</i></span><i>n</i>
digits of the decimal representation of <i>s</i>.</p>
</li>
<li><p>
If
<span class="symbol">−</span>6 < n <span class="symbol">≤</span>
0, return the String consisting of the character ‘<code><b>0</b></code>’,
followed by a decimal point ‘<code><b>.</b></code>’,
followed by <span class="symbol">−</span><i>n</i>
occurrences of the character ‘<code><b>0</b></code>’,
followed by the <i>k</i> digits of the decimal representation of <i>s</i>.</p>
</li>
<li><p>
Otherwise,
if <i>k</i> = 1, return the String consisting of the single digit
of <i>s</i>, followed by lowercase character ‘<code><b>e</b></code>’,
followed by a plus sign ‘<code><b>+</b></code>’
or minus sign ‘<span class="symbol"><b>−</b></span>’
according to whether <i>n</i><span class="symbol">−</span>1
is positive or negative, followed by the decimal representation of
the integer <a href="x5.html#abs">abs</a>(<i>n</i><span class="symbol">−</span>1)
(with no leading zeros).</p>
</li>
<li><p>
Return
the String consisting of the most significant digit of the decimal
representation of s, followed by a decimal point ‘.’, followed
by the remaining k<span class="symbol">−</span>1 digits of
the decimal representation of s, followed by the lowercase