forked from tc39/proposal-bigint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec.html
2235 lines (2091 loc) · 124 KB
/
spec.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>
<meta charset="utf-8">
<pre class="metadata">
title: BigInt
status: proposal
stage: 3
location: https://github.com/tc39/proposal-bigint
copyright: false
contributors: Daniel Ehrenberg, Brendan Eich
</pre>
<style>
emu-issue, emu-todo, emu-motivation, emu-my-example, emu-integration-plans {
margin: 1em 0;
padding: .5em;
padding-left: 1em;
display: block;
}
emu-issue:before, emu-todo:before, emu-motivation:before, emu-my-example:before, emu-integration-plans:before {
display: block;
padding-bottom: .5em;
margin-left: -.5em;
}
emu-issue {
border-left: 5px solid #ff0000;
background: #ffdddd;
}
emu-issue:before {
color: #770000;
content: "ISSUE";
}
emu-motivation {
border-left: 5px solid #aaaa00;
background: #ffffdd;
}
emu-motivation:before {
color: #666600;
content: "MOTIVATION";
}
emu-todo {
border-left: 5px solid #00aa00;
background: #ddffdd;
}
emu-todo:before {
color: #006600;
content: "TODO";
}
emu-my-example {
border-left: 5px solid #0000aa;
background: #ddddff;
}
emu-my-example:before {
color: #000066;
content: "EXAMPLE";
}
emu-integration-plans {
border-left: 5px solid #aa00aa;
background: #ffddff;
}
emu-integration-plans:before {
color: #660066;
content: "INTEGRATION PLANS";
}
</style>
<emu-intro id="sec-intro">
<h1>Introduction</h1>
<p>This proposal adds arbitrary-precision integers to ECMAScript. For motivation and a high-level introduction, see <a href="https://github.com/tc39/proposal-bigint/blob/master/README.md">the explainer document</a>.</p>
<emu-integration-plans>
<p>I attempted to write this specification draft with an eye towards intelligibility and clarifying issues, rather than looking exactly like the final specification. In particular, the translation of the operations on the Number type into the new form are omitted, as they are identical to the previous definitions and would be expressed only as a lengthy refactoring to skip when reading this text.</p>
<p>If you find any part of this specification unclear or confusing, please <a href="https://github.com/tc39/proposal-bigint/issues/new">file an issue</a>.</p>
</emu-integration-plans>
</emu-intro>
<emu-clause id="sec-numeric-types">
<h1>Numeric Types</h1>
<p>ECMAScript has two built-in numeric types: Number and BigInt. In this specification, every numeric type _T_ contains a multiplicative identity value denoted _T_::unit. The specification types also have the following abstract operations, likewise denoted _T_::<i>op</i> for a given operation with specification name <i>op</i>. Unless noted otherwise, argument and result types are all _T_.</p>
<emu-table id="table-numeric-type-ops" caption="Numeric Type Operations">
<table>
<tbody>
<tr>
<th>
Invocation Synopsis
</th>
<th>
Value and Purpose
</th>
</tr>
<tr>
<td>
_T_::unaryMinus(x)
</td>
<td>
A specification function invoked when applying the unary minus operator. Called by the semantics of the <emu-xref href="#sec-unary-minus-operator">unary - operator</emu-xref>.
</td>
</tr>
<tr>
<td>
_T_::bitwiseNOT(x)
</td>
<td>
A specification function invoked when applying the bitwise NOT operator. Called by the semantics of the <emu-xref href="#sec-bitwise-not-operator">bitwise NOT operator</emu-xref> for `~x`.
</td>
</tr>
<tr>
<td>
_T_::exponentiate(x, y)
</td>
<td>
A specification function invoked when applying the exponentiation operator. Called by the semantics of the <emu-xref href="#sec-exp-operator">exponentiation operator</emu-xref> for `x ** y`.
</td>
</tr>
<tr>
<td>
_T_::multiply(x, y)
</td>
<td>
A specification function invoked when applying the multiplication operator. Called by the semantics of the <emu-xref href="#sec-applying-the-mul-operator">`*` operator</emu-xref> for `x * y`.
</td>
</tr>
<tr>
<td>
_T_::divide(x, y)
</td>
<td>
A specification function invoked when applying the division operator. Called by the semantics of the <emu-xref href="#sec-applying-the-div-operator">`/` operator</emu-xref> for `x / y`.
</td>
</tr>
<tr>
<td>
_T_::remainder(x, y)
</td>
<td>
A specification function invoked when applying the truncating remainder ("mod") operator. Called by the semantics of the <emu-xref href="#sec-applying-the-mod-operator">`%` operator</emu-xref> for `x % y`.
<emu-todo>Revisit this name, as Number::remainder explicitly doesn't do the IEEE 754 remainder operation. However, modulo also seems problematic. (<a href="https://github.com/tc39/proposal-bigint/issues/37">issue</a>)</emu-todo>
</td>
</tr>
<tr>
<td>
_T_::add(x, y)
</td>
<td>
A specification function invoked when applying the addition operator. Called by the semantics of the <emu-xref href="#sec-addition-operator-plus">`+` operator</emu-xref> for `x + y`.
</td>
</tr>
<tr>
<td>
_T_::subtract(x, y)
</td>
<td>
A specification function invoked when applying the subtraction operator. Called by the semantics of the <emu-xref href="#sec-subtraction-operator-minus">`-` operator</emu-xref> for `x - y`.
</td>
</tr>
<tr>
<td>
_T_::leftShift(x, y)
</td>
<td>
A specification function invoked when applying the left shift operator to two operands, both of type _T_. Called by the semantics of the <emu-xref href="#sec-left-shift-operator">`<<` operator</emu-xref> for `x << y`.
</td>
</tr>
<tr>
<td>
_T_::signedRightShift(x, y)
</td>
<td>
A specification function invoked when applying the right shift operator to two operands, both of type _T_. Called by the semantics of the <emu-xref href="#sec-signed-right-shift-operator">`>>` operator</emu-xref> for `x >> y`.
</td>
</tr>
<tr>
<td>
_T_::unsignedRightShift(x, y)
</td>
<td>
A specification function invoked when applying the right shift operator to two operands, both of type _T_. Called by the semantics of the <emu-xref href="#sec-unsigned-right-shift-operator">`>>>` operator</emu-xref> for `x >>> y`.
</td>
</tr>
<tr>
<td>
_T_::lessThan(x, y)
</td>
<td>
A specification function invoked when applying one of the four partial-order <emu-xref href="#sec-relational-operators">relational operators</emu-xref>. The return value must be *false*, *true*, or *undefined* (for unordered inputs). Called by the <emu-xref href="#sec-abstract-relational-comparison">Abstract Relational Comparison</emu-xref> algorithm for `x < y`, `x > y`, `x <= y`, and `x >= y`.
</td>
</tr>
<tr>
<td>
_T_::equal(x, y)
</td>
<td>
A specification function invoked when applying <emu-xref href="#sec-equality-operators">equality operators</emu-xref>. The return value must be *false* or *true*. Called by the <emu-xref href="#sec-strict-equality-comparison">Strict Equality Comparison</emu-xref> algorithm for `x == y`, `x != y`, `x === y`, and `x !== y`.
</td>
</tr>
<tr>
<td>
_T_::sameValue(x, y)
</td>
<td>
A specification function invoked when applying <emu-xref href="#sec-samevalue">abstract operation SameValue</emu-xref>. The return value must be *false* or *true*. Called from Object internal methods to test exact value equality. May not throw an exception.
</td>
</tr>
<tr>
<td>
_T_::sameValueZero(x, y)
</td>
<td>
A specification function invoked when applying <emu-xref href="#sec-samevaluezero">abstract operation SameValueZero</emu-xref>. The return value must be *false* or *true*. Called from Array, Map, and Set methods to test value equality ignoring differences among members of the zero cohort (e.g., *-0* and *+0*). May not throw an exception.
</td>
</tr>
<tr>
<td>
_T_::bitwiseAND(x, y)
</td>
<td>
A specification function invoked when applying <emu-xref href="#sec-binary-bitwise-operators">binary bitwise AND operator</emu-xref>. Called by the <emu-xref href="#sec-binary-bitwise-operators-runtime-semantics-evaluation">Binary Bitwise Operators</emu-xref> algorithm for `x & y`.
</td>
</tr>
<tr>
<td>
_T_::bitwiseXOR(x, y)
</td>
<td>
A specification function invoked when applying <emu-xref href="#sec-binary-bitwise-operators">binary bitwise XOR operator</emu-xref>. Called by the <emu-xref href="#sec-binary-bitwise-operators-runtime-semantics-evaluation">Binary Bitwise Operators</emu-xref> algorithm for `x ^ y`.
</td>
</tr>
<tr>
<td>
_T_::bitwiseOR(x, y)
</td>
<td>
A specification function invoked when applying <emu-xref href="#sec-binary-bitwise-operators">binary bitwise OR operator</emu-xref>. Called by the <emu-xref href="#sec-binary-bitwise-operators-runtime-semantics-evaluation">Binary Bitwise Operators</emu-xref> algorithm for `x | y`.
</td>
</tr>
</tbody>
</table>
</emu-table>
<p>The _T_::unit value and _T_::_op_ operations are not a part of the ECMAScript language; they are defined here solely to aid the specification of the semantics of the ECMAScript language. Other abstract operations are defined throughout this specification.</p>
<p>Because the numeric types are in general not convertible without loss of precision or truncation, the ECMAScript language provides no implicit conversion among these types. Programmers must explicitly call `Number` and `BigInt` functions to convert among types when calling a function which requires another type.</p>
<emu-note>
<p>The first and subsequent editions of ECMAScript have provided, for certain operators, implicit numeric conversions that could lose precision or truncate. These legacy implicit conversions are maintained for backward compatibility, but not provided for BigInt in order to minimize opportunity for programmer error, and to leave open the option of generalized <em>value types</em> in a future edition.</p>
</emu-note>
<emu-clause id="sec-ecmascript-language-types-bigint-type">
<h1>The BigInt Type</h1>
<p>The BigInt type represents a mathematical integer value. The value may be any size and is not limited to a particular bit-width. Generally, where not otherwise noted, operations are designed to return exact mathematically-based answers. For binary operations, BigInts act as two's complement binary strings, with negative numbers treated as having bits set infinitely to the left.</p>
<p>The BigInt::unit value is *1n*.</p>
<emu-clause id="sec-numeric-types-bigint-unaryMinus">
<h1>BigInt::unaryMinus (_x_)</h1>
<p>The abstract operation BigInt::unaryMinus with an argument _x_ of BigInt type returns the result of negating _x_.</p>
<emu-note>There is only one *0n* value; `-0n` is the same as *0n*.</emu-note>
</emu-clause>
<emu-clause id="sec-numeric-types-bigint-bitwiseNOT">
<h1>BigInt::bitwiseNOT (_x_)</h1>
<p>The abstract operation BigInt::bitwiseNOT with an argument _x_ of BigInt type returns the one's complement of _x_; that is, -_x_ - 1.</p>
</emu-clause>
<emu-clause id="sec-numeric-types-bigint-exponentiate">
<h1>BigInt::exponentiate (_base_, _exponent_)</h1>
<emu-alg>
1. If _exponent_ < 0, throw a *RangeError* exception.
1. If _base_ is *0n* and _exponent_ is *0n*, return *1n*.
1. Return a BigInt representing the mathematical value of _base_ raised to the power _exponent_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-numeric-types-bigint-multiply">
<h1>BigInt::multiply (_x_, _y_)</h1>
<p>The abstract operation BigInt::multiply with two arguments _x_ and _y_ of BigInt type returns a BigInt representing the result of multiplying _x_ and _y_.</p>
<emu-note>Even if the result has a much larger bit width than the input, the exact mathematical answer is given.</emu-note>
</emu-clause>
<emu-clause id="sec-numeric-types-bigint-divide">
<h1>BigInt::divide (_x_, _y_)</h1>
<emu-alg>
1. If _y_ is *0n*, throw a *RangeError* exception.
1. Let _quotient_ be the mathematical value of _x_ divided by _y_.
1. Return a BigInt representing _quotient_ rounded towards 0 to the next integral value.
</emu-alg>
</emu-clause>
<emu-clause id="sec-numeric-types-bigint-remainder">
<h1>BigInt::remainder (_n_, _d_)</h1>
<emu-alg>
1. If _d_ is *0n*, throw a *RangeError* exception.
1. If _n_ is *0n*, return *0n*.
1. Let _r_ be the BigInt defined by the mathematical relation _r_ = _n_ - (_d_ × _q_) where _q_ is a BigInt that is negative only if _n_/_d_ is negative and positive only if _n_/_d_ is positive, and whose magnitude is as large as possible without exceeding the magnitude of the true mathematical quotient of _n_ and _d_.
1. Return _r_.
</emu-alg>
<emu-note>The sign of the result equals the sign of the dividend.</emu-note>
</emu-clause>
<emu-clause id="sec-numeric-types-bigint-add">
<h1>BigInt::add (_x_, _y_)</h1>
<p>The abstract operation BigInt::add with two arguments _x_ and _y_ of BigInt type returns a BigInt representing the sum of _x_ and _y_.</p>
</emu-clause>
<emu-clause id="sec-numeric-types-bigint-subtract">
<h1>BigInt::subtract (_x_, _y_)</h1>
<p>The abstract operation BigInt::subtract with two arguments _x_ and _y_ of BigInt type returns the BigInt representing the difference _x_ minus _y_.</p>
</emu-clause>
<emu-clause id="sec-numeric-types-bigint-leftShift">
<h1>BigInt::leftShift (_x_, _y_)</h1>
<p>The abstract operation BigInt::leftShift with two arguments _x_ and _y_ of BigInt:</p>
<emu-alg>
1. If _y_ < 0, then
1. Return a BigInt representing _x_ ÷ 2<sup>-_y_</sup>, rounding down to the nearest integer, including for negative numbers.
1. Return a BigInt representing _x_ × 2<sup>_y_</sup>.
</emu-alg>
<emu-note>Semantics here should be equivalent to a bitwise shift, treating the BigInt as an infinite length string of binary two's complement digits.</emu-note>
</emu-clause>
<emu-clause id="sec-numeric-types-bigint-signedRightShift">
<h1>BigInt::signedRightShift (_x_, _y_)</h1>
<p>The abstract operation BigInt::signedRightShift with arguments _x_ and _y_ of type BigInt:</p>
<emu-alg>
1. Return BigInt::leftShift(_x_, -_y_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-numeric-types-bigint-unsignedRightShift">
<h1>BigInt::unsignedRightShift (_x_, _y_)</h1>
<p>The abstract operation BigInt::unsignedRightShift with two arguments _x_ and _y_ of type BigInt:</p>
<emu-alg>
1. Throw a *TypeError* exception.
</emu-alg>
</emu-clause>
<emu-clause id="sec-numeric-types-bigint-lessThan">
<h1>BigInt::lessThan (_x_, _y_)</h1>
<p>The abstract operation BigInt::lessThan with two arguments _x_ and _y_ of BigInt type returns *true* if _x_ is less than _y_ and *false* otherwise.</p>
</emu-clause>
<emu-clause id="sec-numeric-types-bigint-equal">
<h1>BigInt::equal (_x_, _y_)</h1>
<p>The abstract operation BigInt::equal with two arguments _x_ and _y_ of BigInt type returns *true* if _x_ and _y_ have the same mathematical integer value and *false* otherwise.</p>
</emu-clause>
<emu-clause id="sec-numeric-types-bigint-sameValue">
<h1>BigInt::sameValue (_x_, _y_)</h1>
<p>The abstract operation BigInt::sameValue with two arguments _x_ and _y_ of BigInt type:</p>
<emu-alg>
1. Return BigInt::equal(_x_, _y_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-numeric-types-bigint-sameValueZero">
<h1>BigInt::sameValueZero (_x_, _y_)</h1>
<p>The abstract operation BigInt::sameValueZero with two arguments _x_ and _y_ of BigInt type:</p>
<emu-alg>
1. Return BigInt::equal(_x_, _y_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-bitwise-op">
<h1>BitwiseOp(_op_, _x_, _y_)</h1>
<emu-alg>
1. Let _result_ be 0.
1. Let _shift_ be 0.
1. Repeat, until (_x_ = 0 or _x_ = -1) and (_y_ = 0 or _y_ = -1),
1. Let _xDigit_ be _x_ modulo 2.
1. Let _yDigit_ be _y_ modulo 2.
1. Let _result_ be _result_ + 2<sup>_shift_</sup> × _op_(_xDigit_, _yDigit_).
1. Let _shift_ be _shift_ + 1.
1. Let _x_ be (_x_ - _xDigit_) / 2.
1. Let _y_ be (_y_ - _yDigit_) / 2.
1. If _op_(_x_ modulo 2, _y_ modulo 2) ≠ 0, then
1. Let _result_ be _result_ - 2<sup>_shift_</sup>. NOTE: This extends the sign.
1. Return _result_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-numeric-types-bigint-bitwiseAND">
<h1>BigInt::bitwiseAND (_x_, _y_)</h1>
<emu-alg>
1. Return BitwiseOp(`&`, _x_, _y_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-numeric-types-bigint-bitwiseXOR">
<h1>BigInt::bitwiseXOR (_x_, _y_)</h1>
<emu-alg>
1. Return BitwiseOp(`^`, _x_, _y_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-numeric-types-bigint-bitwiseOR">
<h1>BigInt::bitwiseOR (_x_, _y_)</h1>
<emu-alg>
1. Return BitwiseOp(`|`, _x_, _y_).
</emu-alg>
</emu-clause>
</emu-clause>
<emu-integration-plans>
As part of the integration with the main specification, the Number type will have a similar definition of operations, derived from the current operator definitions. Because the semantics are not proposed to change, for ease of review, the refactoring is omitted from this spec draft.
</emu-integration-plans>
</emu-clause>
<emu-clause id="sec-grammar-change">
<h1>Modifications to the Number grammar</h1>
<emu-grammar>
NumericLiteral ::
DecimalLiteral
<ins>DecimalIntegerLiteral BigIntLiteralSuffix</ins>
<del>BinaryIntegerLiteral</del>
<del>OctalIntegerLiteral</del>
<del>HexIntegerLiteral</del>
<ins>NumericLiteralBase</ins>
<ins>NumericLiteralBase BigIntLiteralSuffix</ins>
LegacyOctalIntegerLiteral
<ins>NumericLiteralBase ::
BinaryIntegerLiteral
OctalIntegerLiteral
HexIntegerLiteral</ins>
<ins>BigIntLiteralSuffix :: `n`</ins>
</emu-grammar>
<emu-clause id="sec-numeric-literal-static-semantics-bigint-value">
<h1>Static Semantics: BigInt Value</h1>
<emu-grammar>NumericLiteral :: NumericLiteralBase BigIntLiteralSuffix</emu-grammar>
<ul>
<li>
Let the value of |NumericLiteral| be the MV of |NumericLiteralBase| represented as BigInt.
</li>
</ul>
<emu-grammar>NumericLiteral :: DecimalIntegerLiteral BigIntLiteralSuffix</emu-grammar>
<ul>
<li>
Let the value of |NumericLiteral| be the MV of |DecimalIntegerLiteral| represented as BigInt.
</li>
</ul>
</emu-clause>
<emu-clause id="sec-numeric-literal-static-semantics-number-value">
<h1>Static Semantics: Number Value</h1>
<emu-grammar>NumericLiteral :: NumericLiteralBase</emu-grammar>
<p>The MV is rounded to a value of the Number type.</p>
<emu-integration-plans>
Rounding to the nearest Number will be moved from the MV calculation to a Number Value Static Semantics section so that it doesn't apply to BigInts.
</emu-integration-plans>
</emu-clause>
</emu-clause>
<emu-clause id="sec-abstract-operations">
<h1>Abstract Operations</h1>
<emu-clause id="sec-type-conversion">
<h1>Type Conversion</h1>
<p>The BigInt type has no implicit conversions in the ECMAScript language; programmers must call BigInt explicitly to convert values from other types.</p>
<emu-clause id="sec-toprimitive" aoid="ToPrimitive">
<h1>ToPrimitive ( _input_ [ , _PreferredType_ ] )</h1>
<emu-table id="table-9" caption="ToPrimitive Conversions">
<table>
<tbody>
<tr>
<th>
Input Type
</th>
<th>
Result
</th>
</tr>
<tr>
<td>
<ins>BigInt</ins>
</td>
<td>
<ins>Return _input_.</ins>
</td>
</tr>
</tbody>
</table>
</emu-table>
</emu-clause>
<emu-clause id="sec-toboolean" aoid="ToBoolean">
<h1>ToBoolean ( _argument_ )</h1>
<p>The abstract operation ToBoolean converts _argument_ to a value of type Boolean according to <emu-xref href="#table-10"></emu-xref>:</p>
<emu-table id="table-10" caption="ToBoolean Conversions">
<table>
<tbody>
<tr>
<th>
Argument Type
</th>
<th>
Result
</th>
</tr>
<tr>
<td>
<ins>BigInt</ins>
</td>
<td>
<ins>Return *false* if _argument_ is *0n*; otherwise return *true*.</ins>
</td>
</tr>
</tbody>
</table>
</emu-table>
</emu-clause>
<emu-clause id="sec-tonumber" aoid="ToNumber">
<h1>ToNumber ( _argument_ )</h1>
<p>The abstract operation ToNumber converts _argument_ to a value of type Number according to <emu-xref href="#table-11"></emu-xref>:</p>
<emu-table id="table-11" caption="ToNumber Conversions">
<table>
<tbody>
<tr>
<th>
Argument Type
</th>
<th>
Result
</th>
</tr>
<tr>
<td>
<ins>BigInt</ins>
</td>
<td>
<ins>Throw a *TypeError* exception</ins>
</td>
</tr>
</tbody>
</table>
</emu-table>
<emu-motivation>
Although it would be possible to define a conversion here, to find the nearest Number for a BigInt, such a conversion may lose precision. ToNumber is called implicitly from so many places, but BigInts would not add any value if they lost precision all the time; you might as well just use Numbers instead in the first place. A key <a href="https://github.com/tc39/proposal-bigint/blob/master/README.md#no-implicit-conversions-or-mixed-operands">design decision</a> of this specification is to disallow implicit conversions, and force programmers to use explicit conversions themselves instead.
</emu-motivation>
<emu-clause id="sec-tonumber-applied-to-the-string-type">
<h1>ToNumber Applied to the String Type</h1>
<emu-note>
<p>Some differences should be noted between the syntax of a |StringNumericLiteral| and a |NumericLiteral|:</p>
<ul>
<li>
<ins>A |StringNumericLiteral| may not include a |BigIntLiteralSuffix|.</ins>
</li>
</ul>
</emu-note>
</emu-clause>
</emu-clause>
<emu-clause id="sec-tostring" aoid="ToString">
<h1>ToString ( _argument_ )</h1>
<p>The abstract operation ToString converts _argument_ to a value of type String according to <emu-xref href="#table-12"></emu-xref>:</p>
<emu-table id="table-12" caption="ToString Conversions">
<table>
<tbody>
<tr>
<th>
Argument Type
</th>
<th>
Result
</th>
</tr>
<tr>
<td>
BigInt
</td>
<td>
See <emu-xref href="#sec-tostring-applied-to-the-bigint-type"></emu-xref>.
</td>
</tr>
</tbody>
</table>
</emu-table>
<emu-clause id="sec-tostring-applied-to-the-bigint-type" aoid="ToString Applied to the BigInt Type">
<h1>ToString Applied to the BigInt Type</h1>
<p>The abstract operation ToString converts a BigInt _i_ to String format as follows:</p>
<emu-alg>
1. If _i_ is less than zero, return the string-concatenation of the String `"-"` and ToString(-_i_).
1. Return the String value consisting of the code units of the digits of the decimal representation of _i_.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-toobject" aoid="ToObject">
<h1>ToObject ( _argument_ )</h1>
<p>The abstract operation ToObject converts _argument_ to a value of type Object according to <emu-xref href="#table-13"></emu-xref>:</p>
<emu-table id="table-13" caption="ToObject Conversions">
<table>
<tbody>
<tr>
<th>
Argument Type
</th>
<th>
Result
</th>
</tr>
<tr>
<td>
<ins>BigInt</ins>
</td>
<td>
<ins>Return a new BigInt object whose [[BigIntData]] internal slot is set to _argument_. See <a href="#sec-bigint-objects">BigInt Objects</a> for a description of BigInt objects.</ins>
</td>
</tr>
</tbody>
</table>
</emu-table>
</emu-clause>
<emu-clause id="sec-tonumeric" aoid="ToNumeric">
<h1>ToNumeric ( _value_ )</h1>
<p>The abstract operation ToNumeric returns _value_ converted to a numeric value of type Number or BigInt. This abstract operation functions as follows:</p>
<emu-alg>
1. Let _primValue_ be ? ToPrimitive(_value_, hint Number).
1. If Type(_primValue_) is BigInt, return _primValue_.
1. Return ToNumber(_primValue_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-requireobjectcoercible" aoid="RequireObjectCoercible">
<h1>RequireObjectCoercible ( _argument_ )</h1>
<p>The abstract operation RequireObjectCoercible throws an error if _argument_ is a value that cannot be converted to an Object using ToObject. It is defined by <emu-xref href="#table-14"></emu-xref>:</p>
<emu-table id="table-14" caption="RequireObjectCoercible Results">
<table>
<tbody>
<tr>
<th>
Argument Type
</th>
<th>
Result
</th>
</tr>
<tr>
<td>
BigInt
</td>
<td>
Return _argument_.
</td>
</tr>
</tbody>
</table>
</emu-table>
</emu-clause>
</emu-clause>
<emu-clause id="sec-testing-and-comparison-operations">
<h1>Testing and Comparison Operations</h1>
<emu-clause id="sec-samevalue" aoid="SameValue">
<h1>SameValue ( _x_, _y_ )</h1>
<p>The internal comparison abstract operation SameValue(_x_, _y_), where _x_ and _y_ are ECMAScript language values, produces *true* or *false*. Such a comparison is performed as follows:</p>
<emu-alg>
1. If Type(_x_) is different from Type(_y_), return *false*.
1. If Type(_x_) is Number <ins>or BigInt</ins>, then
1. <del>If _x_ is *NaN* and _y_ is *NaN*, return *true*.</del>
1. <del>If _x_ is *+0* and _y_ is *-0*, return *false*.</del>
1. <del>If _x_ is *-0* and _y_ is *+0*, return *false*.</del>
1. <del>If _x_ is the same Number value as _y_, return *true*.</del>
1. <del>Return *false*.</del>
1. <ins>Return ! Type(_x_)::sameValue(_x_, _y_).</ins>
1. Return <a href="sec-samevaluenonnumber">SameValueNon<del>Number</del><ins>Numeric</ins></a>(_x_, _y_).
</emu-alg>
<emu-integration-plans>The previous Number-related contents of this algorithm will be moved into Number::sameValue.</emu-integration-plans>
</emu-clause>
<!-- es6num="7.2.10" -->
<emu-clause id="sec-samevaluezero" aoid="SameValueZero">
<h1>SameValueZero ( _x_, _y_ )</h1>
<p>The internal comparison abstract operation SameValueZero(_x_, _y_), where _x_ and _y_ are ECMAScript language values, produces *true* or *false*. Such a comparison is performed as follows:</p>
<emu-alg>
1. If Type(_x_) is different from Type(_y_), return *false*.
1. If Type(_x_) is Number <ins>or BigInt</ins>, then
1. <del>If _x_ is *NaN* and _y_ is *NaN*, return *true*.</del>
1. <del>If _x_ is *+0* and _y_ is *-0*, return *true*.</del>
1. <del>If _x_ is *-0* and _y_ is *+0*, return *true*.</del>
1. <del>If _x_ is the same Number value as _y_, return *true*.</del>
1. <del>Return *false*.</del>
1. <ins>Return ! Type(_x_)::sameValueZero(_x_, _y_).</ins>
1. Return <a href="sec-samevaluenonnumber">SameValueNon<del>Number</del><ins>Numeric</ins></a>(_x_, _y_).
</emu-alg>
<emu-integration-plans>The previous Number-related contents of this algorithm will be moved into Number::sameValueZero.</emu-integration-plans>
</emu-clause>
<emu-clause id="sec-samevaluenonnumber" aoid="SameValueNonNumeric">
<h1>SameValueNon<del>Number</del><ins>Numeric</ins> ( _x_, _y_ )</h1>
<p>The internal comparison abstract operation SameValueNonNumeric(_x_, _y_), where neither _x_ nor _y_ are numeric type values, produces *true* or *false*. Such a comparison is performed as follows:</p>
<emu-alg>
1. Assert: Type(_x_) is not Number <ins>or BigInt</ins>.
1. Assert: Type(_x_) is the same as Type(_y_).
1. If Type(_x_) is Undefined, return *true*.
1. If Type(_x_) is Null, return *true*.
1. If Type(_x_) is String, then
1. If _x_ and _y_ are exactly the same sequence of code units (same length and same code units at corresponding indices), return *true*; otherwise, return *false*.
1. If Type(_x_) is Boolean, then
1. If _x_ and _y_ are both *true* or both *false*, return *true*; otherwise, return *false*.
1. If Type(_x_) is Symbol, then
1. If _x_ and _y_ are both the same Symbol value, return *true*; otherwise, return *false*.
1. If _x_ and _y_ are the same Object value, return *true*. Otherwise, return *false*.
</emu-alg>
</emu-clause>
<!-- es6num="7.2.11" -->
<emu-clause id="sec-abstract-relational-comparison" aoid="Abstract Relational Comparison">
<h1>Abstract Relational Comparison</h1>
<p>The comparison _x_ < _y_, where _x_ and _y_ are values, produces *true*, *false*, or *undefined* (which indicates that at least one operand is *NaN*). In addition to _x_ and _y_ the algorithm takes a Boolean flag named _LeftFirst_ as a parameter. The flag is used to control the order in which operations with potentially visible side-effects are performed upon _x_ and _y_. It is necessary because ECMAScript specifies left to right evaluation of expressions. The default value of _LeftFirst_ is *true* and indicates that the _x_ parameter corresponds to an expression that occurs to the left of the _y_ parameter's corresponding expression. If _LeftFirst_ is *false*, the reverse is the case and operations must be performed upon _y_ before _x_. Such a comparison is performed as follows:</p>
<emu-alg>
1. If the _LeftFirst_ flag is *true*, then
1. Let _px_ be ? ToPrimitive(_x_, hint Number).
1. Let _py_ be ? ToPrimitive(_y_, hint Number).
1. Else the order of evaluation needs to be reversed to preserve left to right evaluation,
1. Let _py_ be ? ToPrimitive(_y_, hint Number).
1. Let _px_ be ? ToPrimitive(_x_, hint Number).
1. If both _px_ and _py_ are Strings, then
1. If _py_ is a prefix of _px_, return *false*. (A String value _p_ is a prefix of String value _q_ if _q_ can be the result of concatenating _p_ and some other String _r_. Note that any String is a prefix of itself, because _r_ may be the empty String.)
1. If _px_ is a prefix of _py_, return *true*.
1. Let _k_ be the smallest nonnegative integer such that the code unit at index _k_ within _px_ is different from the code unit at index _k_ within _py_. (There must be such a _k_, for neither String is a prefix of the other.)
1. Let _m_ be the integer that is the code unit at index _k_ within _px_.
1. Let _n_ be the integer that is the code unit at index _k_ within _py_.
1. If _m_ < _n_, return *true*. Otherwise, return *false*.
1. Else,
1. <ins>Let _nx_ be ? ToNumeric(_px_). Because _px_ and _py_ are primitive values evaluation order is not important.</ins>
1. <del>Let _nx_ be ? ToNumber(_px_). Because _px_ and _py_ are primitive values evaluation order is not important.</del>
1. <del>Let _ny_ be ? ToNumber(_py_).</del>
1. <del>If _nx_ is *NaN*, return *undefined*.</del>
1. <del>If _ny_ is *NaN*, return *undefined*.</del>
1. <del>If _nx_ and _ny_ are the same Number value, return *false*.</del>
1. <del>If _nx_ is *+0* and _ny_ is *-0*, return *false*.</del>
1. <del>If _nx_ is *-0* and _ny_ is *+0*, return *false*.</del>
1. <del>If _nx_ is *+∞*, return *false*.</del>
1. <del>If _ny_ is *+∞*, return *true*.</del>
1. <del>If _ny_ is *-∞*, return *false*.</del>
1. <del>If _nx_ is *-∞*, return *true*.</del>
1. <del>If the mathematical value of _nx_ is less than the mathematical value of _ny_ —note that these mathematical values are both finite and not both zero—return *true*. Otherwise, return *false*.</del>
1. <ins>Let _ny_ be ? ToNumeric(_py_).</ins>
1. <ins>If Type(_nx_) is the same as Type(_ny_), return ? Type(_nx_)::lessThan(_nx_, _ny_).</ins>
1. <ins>Assert: Type(_nx_) is BigInt and Type(_ny_) is Number, or Type(_nx_) is Number and Type(_ny_) is BigInt.</ins>
1. <ins>If _x_ or _y_ is *NaN*, return *undefined*.</ins>
1. <ins>If _x_ is *-∞* or _y_ is *+∞*, return *true*.</ins>
1. <ins>If _x_ is *+∞* or _y_ is *-∞*, return *false*.</ins>
1. <ins>If the mathematical value of _nx_ is less than the mathematical value of _ny_, return *true*, otherwise return *false*.</ins>
</emu-alg>
<emu-integration-plans>The previous Number-related contents of this algorithm will be moved into Number::lessThan.</emu-integration-plans>
</emu-clause>
<!-- es6num="7.2.12" -->
<emu-clause id="sec-abstract-equality-comparison" aoid="Abstract Equality Comparison">
<h1>Abstract Equality Comparison</h1>
<p>The comparison _x_ == _y_, where _x_ and _y_ are values, produces *true* or *false*. Such a comparison is performed as follows:</p>
<emu-alg>
1. If Type(_x_) is the same as Type(_y_), then
1. Return the result of performing Strict Equality Comparison _x_ === _y_.
1. If _x_ is *null* and _y_ is *undefined*, return *true*.
1. If _x_ is *undefined* and _y_ is *null*, return *true*.
1. If Type(_x_) is Number and Type(_y_) is String, return the result of the comparison _x_ == ToNumber(_y_).
1. If Type(_x_) is String and Type(_y_) is Number, return the result of the comparison ToNumber(_x_) == _y_.
1. <ins>If Type(_x_) is BigInt and Type(_y_) is String, then</ins>
1. <ins>Let _n_ be StringToBigInt(_y_).</ins>
1. <ins>If _n_ is *NaN*, return *false*.</ins>
1. <ins>Return the result of the comparison _x_ == _n_.</ins>
1. <ins>If Type(_x_) is String and Type(_y_) is BigInt, return the result of the comparison _y_ == _x_.</ins>
1. If Type(_x_) is Boolean, return the result of the comparison ToNumber(_x_) == _y_.
1. If Type(_y_) is Boolean, return the result of the comparison _x_ == ToNumber(_y_).
1. If Type(_x_) is either String, Number, <ins>BigInt,</ins> or Symbol and Type(_y_) is Object, return the result of the comparison _x_ == ? ToPrimitive(_y_).
1. If Type(_x_) is Object and Type(_y_) is either String, Number, <ins>BigInt,</ins> or Symbol, return the result of the comparison ? ToPrimitive(_x_) == _y_.
1. <ins>If Type(_x_) is BigInt and Type(_y_) is Number, or if Type(_x_) is Number and Type(_y_) is BigInt, then</ins>
1. <ins>If _x_ or _y_ are any of *NaN*, *+∞*, or *-∞*, return *false*.</ins>
1. <ins>If the mathematical value of _x_ is equal to the mathematical value of _y_, return *true*, otherwise return *false*.</ins>
1. Return *false*.
</emu-alg>
</emu-clause>
<!-- es6num="7.2.13" -->
<emu-clause id="sec-strict-equality-comparison" aoid="Strict Equality Comparison">
<h1>Strict Equality Comparison</h1>
<p>The comparison _x_ === _y_, where _x_ and _y_ are values, produces *true* or *false*. Such a comparison is performed as follows:</p>
<emu-alg>
1. If Type(_x_) is different from Type(_y_), return *false*.
1. If Type(_x_) is Number <ins>or BigInt</ins>, then
1. <del>If _x_ is *NaN*, return *false*.</del>
1. <del>If _y_ is *NaN*, return *false*.</del>
1. <del>If _x_ is the same Number value as _y_, return *true*.</del>
1. <del>If _x_ is *+0* and _y_ is *-0*, return *true*.</del>
1. <del>If _x_ is *-0* and _y_ is *+0*, return *true*.</del>
1. <del>Return *false*.</del>
1. <ins>Return ! Type(_x_)::equal(_x_, _y_).</ins>
1. Return <a href="sec-samevaluenonnumber">SameValueNon<del>Number</del><ins>Numeric</ins></a>(_x_, _y_).
</emu-alg>
<emu-integration-plans>The previous Number-related contents of this algorithm will be moved into Number::equal.</emu-integration-plans>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-ecmascript-language-expressions">
<h1>ECMAScript Language: Expressions</h1>
<emu-clause id="sec-update-expressions">
<h1>Update Expressions</h1>
<!-- es6num="12.4.4" -->
<emu-clause id="sec-postfix-increment-operator">
<h1>Postfix Increment Operator</h1>
<!-- es6num="12.4.4.1" -->
<emu-clause id="sec-postfix-increment-operator-runtime-semantics-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>UpdateExpression : LeftHandSideExpression `++`</emu-grammar>
<emu-alg>
1. Let _lhs_ be the result of evaluating |LeftHandSideExpression|.
1. <del>Let _oldValue_ be ? ToNumber(? GetValue(_lhs_)).</del>
1. <del>Let _newValue_ be the result of adding the value 1 to _oldValue_, using the same rules as for the `+` operator (see <emu-xref href="#sec-applying-the-additive-operators-to-numbers"></emu-xref>).</del>
1. <ins>Let _oldValue_ be ? ToNumeric(? GetValue(_lhs_)).</ins>
1. <ins>Let _newValue_ be ? Type(_oldvalue_)::add(_oldValue_, Type(_oldValue_)::unit).</ins>
1. Perform ? PutValue(_lhs_, _newValue_).
1. Return _oldValue_.
</emu-alg>
</emu-clause>
</emu-clause>
<!-- es6num="12.4.5" -->
<emu-clause id="sec-postfix-decrement-operator">
<h1>Postfix Decrement Operator</h1>
<!-- es6num="12.4.5.1" -->
<emu-clause id="sec-postfix-decrement-operator-runtime-semantics-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>UpdateExpression : LeftHandSideExpression `--`</emu-grammar>
<emu-alg>
1. Let _lhs_ be the result of evaluating |LeftHandSideExpression|.
1. <del>Let _oldValue_ be ? ToNumber(? GetValue(_lhs_)).</del>
1. <del>Let _newValue_ be the result of subtracting the value 1 from _oldValue_, using the same rules as for the `-` operator (see <emu-xref href="#sec-applying-the-additive-operators-to-numbers"></emu-xref>).</del>
1. <ins>Let _oldValue_ be ? ToNumeric(? GetValue(_lhs_)).</ins>
1. <ins>Let _newValue_ be ? Type(_oldvalue_)::subtract(_oldValue_, Type(_oldValue_)::unit).</ins>
1. Perform ? PutValue(_lhs_, _newValue_).
1. Return _oldValue_.
</emu-alg>
</emu-clause>
</emu-clause>
<!-- es6num="12.5.7" -->
<emu-clause id="sec-prefix-increment-operator">
<h1>Prefix Increment Operator</h1>
<!-- es6num="12.5.7.1" -->
<emu-clause id="sec-prefix-increment-operator-runtime-semantics-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>UpdateExpression : `++` UnaryExpression</emu-grammar>
<emu-alg>
1. Let _expr_ be the result of evaluating |UnaryExpression|.
1. <del>Let _oldValue_ be ? ToNumber(? GetValue(_expr_)).</del>
1. <del>Let _newValue_ be the result of adding the value 1 to _oldValue_, using the same rules as for the `+` operator (see <emu-xref href="#sec-applying-the-additive-operators-to-numbers"></emu-xref>).</del>
1. <ins>Let _oldValue_ be ? ToNumeric(? GetValue(_expr_)).</ins>
1. <ins>Let _newValue_ be ? Type(_oldvalue_)::add(_oldValue_, Type(_oldValue_)::unit).</ins>
1. Perform ? PutValue(_expr_, _newValue_).
1. Return _newValue_.
</emu-alg>
</emu-clause>
</emu-clause>
<!-- es6num="12.5.8" -->
<emu-clause id="sec-prefix-decrement-operator">
<h1>Prefix Decrement Operator</h1>
<!-- es6num="12.5.8.1" -->
<emu-clause id="sec-prefix-decrement-operator-runtime-semantics-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>UpdateExpression : `--` UnaryExpression</emu-grammar>
<emu-alg>
1. Let _expr_ be the result of evaluating |UnaryExpression|.
1. <del>Let _oldValue_ be ? ToNumber(? GetValue(_expr_)).</del>
1. <del>Let _newValue_ be the result of subtracting the value 1 from _oldValue_, using the same rules as for the `-` operator (see <emu-xref href="#sec-applying-the-additive-operators-to-numbers"></emu-xref>).</del>
1. <ins>Let _oldValue_ be ? ToNumeric(? GetValue(_expr_)).</ins>
1. <ins>Let _newValue_ be ? Type(_oldvalue_)::subtract(_oldValue_, Type(_oldValue_)::unit).</ins>
1. Perform ? PutValue(_expr_, _newValue_).
1. Return _newValue_.
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-unary-operators">
<h1>Unary Operators</h1>
<!-- es6num="12.5.6" -->
<emu-clause id="sec-typeof-operator">
<h1>The `typeof` Operator</h1>
<!-- es6num="12.5.6.1" -->
<emu-clause id="sec-typeof-operator-runtime-semantics-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>UnaryExpression : `typeof` UnaryExpression</emu-grammar>
<emu-table id="table-35" caption="typeof Operator Results">
<table>
<tbody>
<tr>
<th>
Type of _val_
</th>
<th>
Result
</th>
</tr>
<tr>
<td>
<ins>BigInt</ins>
</td>
<td>
<ins>`"bigint"`</ins>
</td>
</tr>
</tbody>
</table>
</emu-table>
</emu-clause>
</emu-clause>
<!-- es6num="12.5.9" -->
<emu-clause id="sec-unary-plus-operator">
<h1>Unary `+` Operator</h1>
<emu-note>
<p>The unary + operator converts its operand to Number type.</p>
</emu-note>
<!-- es6num="12.5.9.1" -->
<emu-clause id="sec-unary-plus-operator-runtime-semantics-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>UnaryExpression : `+` UnaryExpression</emu-grammar>
<emu-alg>
1. Let _expr_ be the result of evaluating |UnaryExpression|.
1. Return ? ToNumber(? GetValue(_expr_)).
</emu-alg>
<emu-motivation>The definition here is unchanged, and still uses ToNumber rather than ToNumeric. This means that `+` will throw on BigInts. The semantics here are designed to allow expressions of the form `+x` to always return Numbers, which is necessary to <a href="https://github.com/tc39/proposal-bigint/blob/master/README.md#dont-break-asmjs">preserve assumptions made by asm.js</a>.</emu-motivation>
</emu-clause>
</emu-clause>
<!-- es6num="12.5.10" -->
<emu-clause id="sec-unary-minus-operator">
<h1>Unary `-` Operator</h1>
<emu-note>
<p>The unary `-` operator converts its operand to Number type and then negates it. Negating *+0* produces *-0*, and negating *-0* produces *+0*.</p>
</emu-note>
<!-- es6num="12.5.10.1" -->
<emu-clause id="sec-unary-minus-operator-runtime-semantics-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>UnaryExpression : `-` UnaryExpression</emu-grammar>
<emu-alg>
1. Let _expr_ be the result of evaluating |UnaryExpression|.
1. Let _oldValue_ be ? <del>ToNumber</del><ins>ToNumeric</ins>(? GetValue(_expr_)).
1. <del>If _oldValue_ is *NaN*, return *NaN*.</del>
1. <del>Return the result of negating _oldValue_; that is, compute a Number with the same magnitude but opposite sign.</del>
1. <ins>Let _T_ be Type(_oldValue_).</ins>
1. <ins>Return ? _T_::unaryMinus(_oldValue_).</ins>
</emu-alg>
</emu-clause>
</emu-clause>
<!-- es6num="12.5.11" -->
<emu-clause id="sec-bitwise-not-operator">
<h1>Bitwise NOT Operator ( `~` )</h1>
<!-- es6num="12.5.11.1" -->
<emu-clause id="sec-bitwise-not-operator-runtime-semantics-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>UnaryExpression : `~` UnaryExpression</emu-grammar>
<emu-alg>
1. Let _expr_ be the result of evaluating |UnaryExpression|.
1. Let _oldValue_ be ? <del>ToInt32</del><ins>ToNumeric</ins>(? GetValue(_expr_)).
1. <del>Return the result of applying bitwise complement to _oldValue_. The result is a signed 32-bit integer.</del>
1. <ins>Let _T_ be Type(_oldValue_).</ins>
1. <ins>Return ? _T_::bitwiseNOT(_oldValue_).</ins>
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-exp-operator">
<h1>Exponentiation Operator</h1>
<emu-clause id="sec-exp-operator-runtime-semantics-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>
ExponentiationExpression : UpdateExpression `**` ExponentiationExpression
</emu-grammar>
<emu-alg>
1. Let _left_ be the result of evaluating _UpdateExpression_.
1. Let _leftValue_ be ? GetValue(_left_).