-
Notifications
You must be signed in to change notification settings - Fork 2
/
javascript_ecma_262_5th_ed.info-3
6671 lines (4711 loc) · 270 KB
/
javascript_ecma_262_5th_ed.info-3
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
ã“れ㯠javascript_ecma_262_5th_ed.infoã€es5.texi より makeinfo
ãƒãƒ¼ã‚¸ãƒ§ãƒ³ 4.8 ã«ã‚ˆã£ã¦ä½œæˆã•ã‚Œã¾ã—ãŸã€‚
File: javascript_ecma_262_5th_ed.info, Node: 1562 The Boolean Constructor, Next: 15621 new Boolean value, Prev: 15611 Boolean value, Up: Top
406 15.6.2 (#sec-15.6.2) The Boolean Constructor
************************************************
When Boolean is called as part of a `new' expression it is a
constructor: it initialises the newly created object.
File: javascript_ecma_262_5th_ed.info, Node: 15621 new Boolean value, Next: 1563 Properties of the Boolean Constructor, Prev: 1562 The Boolean Constructor, Up: Top
407 15.6.2.1 (#sec-15.6.2.1) new Boolean (value)
************************************************
The [[Prototype]] internal property of the newly constructed object is
set to the original Boolean prototype object, the one that is the
initial value of Boolean.prototype (15.6.3.1 (#sec-15.6.3.1)).
The [[Class]] internal property of the newly constructed Boolean
object is set to "Boolean".
The [[PrimitiveValue]] internal property of the newly constructed
Boolean object is set to ToBoolean (#sec-9.2)(value).
The [[Extensible]] internal property of the newly constructed object
is set to true.
File: javascript_ecma_262_5th_ed.info, Node: 1563 Properties of the Boolean Constructor, Next: 15631 Booleanprototype, Prev: 15621 new Boolean value, Up: Top
408 15.6.3 (#sec-15.6.3) Properties of the Boolean Constructor
**************************************************************
The value of the [[Prototype]] internal property of the Boolean
constructor is the Function prototype object (15.3.4) (#sec-15.3.4).
Besides the internal properties and the `length' property (whose
value is 1), the Boolean constructor has the following property:
File: javascript_ecma_262_5th_ed.info, Node: 15631 Booleanprototype, Next: 1564 Properties of the Boolean Prototype Object, Prev: 1563 Properties of the Boolean Constructor, Up: Top
409 15.6.3.1 (#sec-15.6.3.1) Boolean.prototype
**********************************************
The initial value of Boolean.prototype is the Boolean prototype object
(15.6.4 (#sec-15.6.4)).
This property has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: false }.
File: javascript_ecma_262_5th_ed.info, Node: 1564 Properties of the Boolean Prototype Object, Next: 15641 Booleanprototypeconstructor, Prev: 15631 Booleanprototype, Up: Top
410 15.6.4 (#sec-15.6.4) Properties of the Boolean Prototype Object
*******************************************************************
The Boolean prototype object is itself a Boolean object (its [[Class]]
is "Boolean") whose value is false.
The value of the [[Prototype]] internal property of the Boolean
prototype object is the standard built-in Object prototype object
(15.2.4 (#sec-15.2.4)).
File: javascript_ecma_262_5th_ed.info, Node: 15641 Booleanprototypeconstructor, Next: 15642 BooleanprototypetoString, Prev: 1564 Properties of the Boolean Prototype Object, Up: Top
411 15.6.4.1 (#sec-15.6.4.1) Boolean.prototype.constructor
**********************************************************
The initial value of Boolean.prototype.constructor is the built-in
Boolean constructor.
File: javascript_ecma_262_5th_ed.info, Node: 15642 BooleanprototypetoString, Next: 15643 BooleanprototypevalueOf, Prev: 15641 Booleanprototypeconstructor, Up: Top
412 15.6.4.2 (#sec-15.6.4.2) Boolean.prototype.toString ( )
***********************************************************
The following steps are taken:
1. Let B be the this value.
2. If Type (#def-type)(B) is Boolean, then let b be B.
3. Else if Type (#def-type)(B) is Object and the value of the
[[Class]] internal property of B is "Boolean", then let b be the
value of the [[PrimitiveValue]] internal property of B.
4. Else throw a TypeError exception.
5. If b is true, then return "true"; else return "false".
File: javascript_ecma_262_5th_ed.info, Node: 15643 BooleanprototypevalueOf, Next: 1565 Properties of Boolean Instances, Prev: 15642 BooleanprototypetoString, Up: Top
413 15.6.4.3 (#sec-15.6.4.3) Boolean.prototype.valueOf ( )
**********************************************************
The following steps are taken:
1. Let B be the this value.
2. If Type (#def-type)(B) is Boolean, then let b be B.
3. Else if Type (#def-type)(B) is Object and the value of the
[[Class]] internal property of B is "Boolean", then let b be the
value of the [[PrimitiveValue]] internal property of B.
4. Else throw a TypeError exception.
5. Return b.
File: javascript_ecma_262_5th_ed.info, Node: 1565 Properties of Boolean Instances, Next: 157 Number Objects, Prev: 15643 BooleanprototypevalueOf, Up: Top
414 15.6.5 (#sec-15.6.5) Properties of Boolean Instances
********************************************************
Boolean instances inherit properties from the Boolean prototype object
and their [[Class]] internal property value is "Boolean". Boolean
instances also have a [[PrimitiveValue]] internal property.
The [[PrimitiveValue]] internal property is the Boolean value
represented by this Boolean object.
File: javascript_ecma_262_5th_ed.info, Node: 157 Number Objects, Next: 1571 The Number Constructor Called as a Function, Prev: 1565 Properties of Boolean Instances, Up: Top
415 15.7 (#sec-15.7) Number Objects
***********************************
File: javascript_ecma_262_5th_ed.info, Node: 1571 The Number Constructor Called as a Function, Next: 15711 Number [ value ], Prev: 157 Number Objects, Up: Top
416 15.7.1 (#sec-15.7.1) The Number Constructor Called as a Function
********************************************************************
When Number is called as a function rather than as a constructor, it
performs a type conversion.
File: javascript_ecma_262_5th_ed.info, Node: 15711 Number [ value ], Next: 1572 The Number Constructor, Prev: 1571 The Number Constructor Called as a Function, Up: Top
417 15.7.1.1 (#sec-15.7.1.1) Number ( [ value ] )
*************************************************
Returns a Number value (not a Number object) computed by ToNumber
(#sec-9.3)(value) if value was supplied, else returns +0.
File: javascript_ecma_262_5th_ed.info, Node: 1572 The Number Constructor, Next: 15721 new Number [ value ], Prev: 15711 Number [ value ], Up: Top
418 15.7.2 (#sec-15.7.2) The Number Constructor
***********************************************
When Number is called as part of a `new' expression it is a
constructor: it initialises the newly created object.
File: javascript_ecma_262_5th_ed.info, Node: 15721 new Number [ value ], Next: 1573 Properties of the Number Constructor, Prev: 1572 The Number Constructor, Up: Top
419 15.7.2.1 (#sec-15.7.2.1) new Number ( [ value ] )
*****************************************************
The [[Prototype]] internal property of the newly constructed object is
set to the original Number prototype object, the one that is the
initial value of Number.prototype (15.7.3.1 (#sec-15.7.3.1)).
The [[Class]] internal property of the newly constructed object is
set to "Number".
The [[PrimitiveValue]] internal property of the newly constructed
object is set to ToNumber (#sec-9.3)(value) if value was supplied, else
to +0.
The [[Extensible]] internal property of the newly constructed object
is set to true.
File: javascript_ecma_262_5th_ed.info, Node: 1573 Properties of the Number Constructor, Next: 15731 Numberprototype, Prev: 15721 new Number [ value ], Up: Top
420 15.7.3 (#sec-15.7.3) Properties of the Number Constructor
*************************************************************
The value of the [[Prototype]] internal property of the Number
constructor is the Function prototype object (15.3.4) (#sec-15.3.4).
Besides the internal properties and the `length' property (whose
value is 1), the Number constructor has the following properties:
File: javascript_ecma_262_5th_ed.info, Node: 15731 Numberprototype, Next: 15732 NumberMAX_VALUE, Prev: 1573 Properties of the Number Constructor, Up: Top
421 15.7.3.1 (#sec-15.7.3.1) Number.prototype
*********************************************
The initial value of Number.prototype is the Number prototype object
(15.7.4 (#sec-15.7.4)).
This property has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: false }.
File: javascript_ecma_262_5th_ed.info, Node: 15732 NumberMAX_VALUE, Next: 15733 NumberMIN_VALUE, Prev: 15731 Numberprototype, Up: Top
422 15.7.3.2 (#sec-15.7.3.2) Number.MAX_VALUE
*********************************************
The value of Number.MAX_VALUE is the largest positive finite value of
the Number type, which is approximately 1.7976931348623157 × 10^308.
This property has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: false }.
File: javascript_ecma_262_5th_ed.info, Node: 15733 NumberMIN_VALUE, Next: 15734 NumberNaN, Prev: 15732 NumberMAX_VALUE, Up: Top
423 15.7.3.3 (#sec-15.7.3.3) Number.MIN_VALUE
*********************************************
The value of Number.MIN_VALUE is the smallest positive value of the
Number type, which is approximately 5 × 10^−324.
This property has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: false }.
File: javascript_ecma_262_5th_ed.info, Node: 15734 NumberNaN, Next: 15735 NumberNEGATIVE_INFINITY, Prev: 15733 NumberMIN_VALUE, Up: Top
424 15.7.3.4 (#sec-15.7.3.4) Number.NaN
***************************************
The value of Number.NaN is NaN.
This property has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: false }.
File: javascript_ecma_262_5th_ed.info, Node: 15735 NumberNEGATIVE_INFINITY, Next: 15736 NumberPOSITIVE_INFINITY, Prev: 15734 NumberNaN, Up: Top
425 15.7.3.5 (#sec-15.7.3.5) Number.NEGATIVE_INFINITY
*****************************************************
The value of Number.NEGATIVE_INFINITY is −∞.
This property has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: false }.
File: javascript_ecma_262_5th_ed.info, Node: 15736 NumberPOSITIVE_INFINITY, Next: 1574 Properties of the Number Prototype Object, Prev: 15735 NumberNEGATIVE_INFINITY, Up: Top
426 15.7.3.6 (#sec-15.7.3.6) Number.POSITIVE_INFINITY
*****************************************************
The value of Number.POSITIVE_INFINITY is +∞.
This property has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: false }.
File: javascript_ecma_262_5th_ed.info, Node: 1574 Properties of the Number Prototype Object, Next: 15741 Numberprototypeconstructor, Prev: 15736 NumberPOSITIVE_INFINITY, Up: Top
427 15.7.4 (#sec-15.7.4) Properties of the Number Prototype Object
******************************************************************
The Number prototype object is itself a Number object (its [[Class]] is
"Number") whose value is +0.
The value of the [[Prototype]] internal property of the Number
prototype object is the standard built-in Object prototype object
(15.2.4 (#sec-15.2.4)).
Unless explicitly stated otherwise, the methods of the Number
prototype object defined below are not generic and the this value
passed to them must be either a Number value or an Object for which the
value of the [[Class]] internal property is "Number".
In the following descriptions of functions that are properties of
the Number prototype object, the phrase “this Number object†refers
to either the object that is the this value for the invocation of the
function or, if Type (#def-type)(this value) is Number, an object that
is created as if by the expression `new Number(<var><span
class="this">this</span> value</var>)' where `Number' is the standard
built-in constructor with that name. Also, the phrase “this Number
value†refers to either the Number value represented by this Number
object, that is, the value of the [[PrimitiveValue]] internal property
of this Number object or the this value if its type is Number. A
TypeError exception is thrown if the this value is neither an object
for which the value of the [[Class]] internal property is "Number" or a
value whose type is Number.
File: javascript_ecma_262_5th_ed.info, Node: 15741 Numberprototypeconstructor, Next: 15742 NumberprototypetoString [ radix ], Prev: 1574 Properties of the Number Prototype Object, Up: Top
428 15.7.4.1 (#sec-15.7.4.1) Number.prototype.constructor
*********************************************************
The initial value of Number.prototype.constructor is the built-in
Number constructor.
File: javascript_ecma_262_5th_ed.info, Node: 15742 NumberprototypetoString [ radix ], Next: 15743 NumberprototypetoLocaleString, Prev: 15741 Numberprototypeconstructor, Up: Top
429 15.7.4.2 (#sec-15.7.4.2) Number.prototype.toString ( [ radix ] )
********************************************************************
The optional radix should be an integer value in the inclusive range 2
to 36. If radix not present or is undefined the Number 10 is used as
the value of radix. If ToInteger (#sec-9.4)(radix) is the Number 10
then this Number value (#def-this-Number-value) is given as an argument
to the ToString (#sec-9.8) abstract operation; the resulting String
value is returned.
If ToInteger (#sec-9.4)(radix) is not an integer between 2 and 36
inclusive throw a RangeError exception. If ToInteger (#sec-9.4)(radix)
is an integer from 2 to 36, but not 10, the result is a String
representation of this Number value (#def-this-Number-value) using the
specified radix. Letters `a'-`z' are used for digits with values 10
through 35. The precise algorithm is implementation-dependent if the
radix is not 10, however the algorithm should be a generalization of
that specified in 9.8.1 (#sec-9.8.1).
The toString function is not generic; it throws a TypeError
exception if its this value is not a Number or a Number object.
Therefore, it cannot be transferred to other kinds of objects for use
as a method.
File: javascript_ecma_262_5th_ed.info, Node: 15743 NumberprototypetoLocaleString, Next: 15744 NumberprototypevalueOf, Prev: 15742 NumberprototypetoString [ radix ], Up: Top
430 15.7.4.3 (#sec-15.7.4.3) Number.prototype.toLocaleString()
**************************************************************
Produces a String value that represents this Number value
(#def-this-Number-value) formatted according to the conventions of the
host environment’s current locale. This function is
implementation-dependent, and it is permissible, but not encouraged,
for it to return the same thing as toString.
NOTE The first parameter to this function is likely to be used in a
future version of this standard; it is recommended that implementations
do not use this parameter position for anything else.
File: javascript_ecma_262_5th_ed.info, Node: 15744 NumberprototypevalueOf, Next: 15745 NumberprototypetoFixed fractionDigits, Prev: 15743 NumberprototypetoLocaleString, Up: Top
431 15.7.4.4 (#sec-15.7.4.4) Number.prototype.valueOf ( )
*********************************************************
Returns this Number value (#def-this-Number-value).
The valueOf function is not generic; it throws a TypeError exception
if its this value is not a Number or a Number object. Therefore, it
cannot be transferred to other kinds of objects for use as a method.
File: javascript_ecma_262_5th_ed.info, Node: 15745 NumberprototypetoFixed fractionDigits, Next: 15746 NumberprototypetoExponential fractionDigits, Prev: 15744 NumberprototypevalueOf, Up: Top
432 15.7.4.5 (#sec-15.7.4.5) Number.prototype.toFixed (fractionDigits)
**********************************************************************
Return a String containing this Number value (#def-this-Number-value)
represented in decimal fixed-point notation with fractionDigits digits
after the decimal point. If fractionDigits is undefined, 0 is assumed.
Specifically, perform the following steps:
1. Let f be ToInteger (#sec-9.4)(fractionDigits). (If fractionDigits
is undefined, this step produces the value 0).
2. If f < 0 or f > 20, throw a RangeError exception.
3. Let x be this Number value (#def-this-Number-value).
4. If x is NaN, return the String "NaN".
5. Let s be the empty String.
6. If x < 0, then
1. Let s be "-".
2. Let x = −x.
7. If x ≥ 10^21, then
1. Let m = ToString (#sec-9.8)(x).
8. Else, x < 10^21
1. Let n be an integer for which the exact mathematical value of
n ÷ 10^f − x is as close to zero as possible. If there are
two such n, pick the larger n.
2. If n = 0, let m be the String "0". Otherwise, let m be the
String consisting of the digits of the decimal representation
of n (in order, with no leading zeroes).
3. If f ≠0, then
1. Let k be the number of characters in m.
2. If k ≤ f, then
1. Let z be the String consisting of f+1−k
occurrences of the character ‘`0'’.
2. Let m be the concatenation of Strings z and m.
3. Let k = f + 1.
3. Let a be the first k-f characters of m, and let b be the
remaining f characters of m.
4. Let m be the concatenation of the three Strings a, ".",
and b.
9. Return the concatenation of the Strings s and m.
The `length' property of the toFixed method is 1.
If the toFixed method is called with more than one argument, then
the behaviour is undefined (see clause 15 (#sec-15)).
An implementation is permitted to extend the behaviour of toFixed
for values of fractionDigits less than 0 or greater than 20. In this
case toFixed would not necessarily throw RangeError for such values.
NOTE The output of toFixed may be more precise than toString for
some values because toString only prints enough significant digits to
distinguish the number from adjacent number values. For example,
File: javascript_ecma_262_5th_ed.info, Node: 15746 NumberprototypetoExponential fractionDigits, Next: 15747 NumberprototypetoPrecision precision, Prev: 15745 NumberprototypetoFixed fractionDigits, Up: Top
433 15.7.4.6 (#sec-15.7.4.6) Number.prototype.toExponential (fractionDigits)
****************************************************************************
Return a String containing this Number value (#def-this-Number-value)
represented in decmal exponential notation with one digit before the
significand’s decimal point and fractionDigits digits after the
significand’s decimal point. If fractionDigits is undefined, include
as many significand digits as necessary to uniquely specify the Number
(just like in ToString (#sec-9.8) except that in this case the Number
is always output in exponential notation). Specifically, perform the
following steps:
1. Let x be this Number value (#def-this-Number-value).
2. Let f be ToInteger (#sec-9.4)(fractionDigits).
3. If x is NaN, return the String "NaN".
4. Let s be the empty String.
5. If x < 0, then
1. Let s be "-".
2. Let x = −x.
6. If x = +∞, then
1. Return the concatenation of the Strings s and "Infinity".
7. If fractionDigits is not undefined and (f < 0 or f > 20), throw a
RangeError exception.
8. If x = 0, then
1. Let f = 0.
2. Let m be the String consisting of f+1 occurrences of the
character ‘`0'’.
3. Let e = 0.
9. Else, x ≠0
1. If fractionDigits is not undefined, then
1. Let e and n be integers such that 10^f ≤ n < 10^f+1
and for which the exact mathematical value of n ×
10^e−f − x is as close to zero as possible. If there
are two such sets of e and n, pick the e and n for which
n × 10^e−f is larger.
2. Else, fractionDigits is undefined
1. Let e, n, and f be integers such that f ≥ 0, 10^f ≤
n < 10^f+1, the number value for n × 10^e−f is x, and
f is as small as possible. Note that the decimal
representation of n has f+1 digits, n is not divisible
by 10, and the least significant digit of n is not
necessarily uniquely determined by these criteria.
3. Let m be the String consisting of the digits of the decimal
representation of n (in order, with no leading zeroes).
10. If f ≠0, then
1. Let a be the first character of m, and let b be the remaining
f characters of m.
2. Let m be the concatenation of the three Strings a, ".", and b.
11. If e = 0, then
1. Let c = "+".
2. Let d = "0".
12. Else
1. If e > 0, then let c = "+".
2. Else, e ≤ 0
1. Let c = "-".
2. Let e = −e.
3. Let d be the String consisting of the digits of the decimal
representation of e (in order, with no leading zeroes).
13. Let m be the concatenation of the four Strings m, "e", c, and d.
14. Return the concatenation of the Strings s and m.
The `length' property of the toExponential method is 1.
If the toExponential method is called with more than one argument,
then the behaviour is undefined (see clause 15 (#sec-15)).
NOTE For implementations that provide more accurate conversions than
required by the rules above, it is recommended that the following
alternative version of step 9.b.i be used as a guideline:
i. Let e, n, and f be integers such that f ≥ 0, 10^f ≤ n <
10^f+1, the number value for n × 10^e−f is x, and f is as small
as possible. If there are multiple possibilities for n, choose the
value of n for which n × 10^e−f is closest in value to x. If
there are two such possible values of n, choose the one that is
even.
File: javascript_ecma_262_5th_ed.info, Node: 15747 NumberprototypetoPrecision precision, Next: 1575 Properties of Number Instances, Prev: 15746 NumberprototypetoExponential fractionDigits, Up: Top
434 15.7.4.7 (#sec-15.7.4.7) Number.prototype.toPrecision (precision)
*********************************************************************
Return a String containing this Number value (#def-this-Number-value)
represented either in decimal exponential notation with one digit
before the significand’s decimal point and precision−1 digits after
the significand’s decimal point or in decimal fixed notation with
precision significant digits. If precision is undefined, call ToString
(#sec-9.8) (9.8.1 (#sec-9.8.1)) instead. Specifically, perform the
following steps:
1. Let x be this Number value (#def-this-Number-value).
2. If precision is undefined, return ToString (#sec-9.8)(x).
3. Let p be ToInteger (#sec-9.4)(precision).
4. If x is NaN, return the String "NaN".
5. Let s be the empty String.
6. If x < 0, then
1. Let s be "-".
2. Let x = −x.
7. If x = +∞, then
1. Return the concatenation of the Strings s and "Infinity".
8. If p < 1 or p > 21, throw a RangeError exception.
9. If x = 0, then
1. Let m be the String consisting of p occurrences of the
character ‘`0'’.
2. Let e = 0.
10. Else x ≠0,
1. Let e and n be integers such that 10^p−1 ≤ n < 10^p and
for which the exact mathematical value of n × 10^e−p+1 −
x is as close to zero as possible. If there are two such sets
of e and n, pick the e and n for which n × 10^e−p+1 is
larger.
2. Let m be the String consisting of the digits of the decimal
representation of n (in order, with no leading zeroes).
3. If e < −6 or e ≥ p, then
1. Let a be the first character of m, and let b be the
remaining p−1 characters of m.
2. Let m be the concatenation of the three Strings a, ".",
and b.
3. If e = 0, then
1. Let c = "+" and d = "0".
4. Else e ≠0,
1. If e > 0, then
1. Let c = "+".
2. Else e < 0,
1. Let c = "-".
2. Let e = −e.
3. Let d be the String consisting of the digits of the
decimal representation of e (in order, with no
leading zeroes).
5. Let m be the concatenation of the five Strings s, m,
"e", c, and d.
11. If e = p−1, then return the concatenation of the Strings s and m.
12. If e ≥ 0, then
1. Let m be the concatenation of the first e+1 characters of m,
the character ‘`.'’, and the remaining p−(e+1)
characters of m.
13. Else e < 0,
1. Let m be the concatenation of the String "0.", −(e+1)
occurrences of the character ‘`0'’, and the String m.
14. Return the concatenation of the Strings s and m.
The `length' property of the toPrecision method is 1.
If the toPrecision method is called with more than one argument,
then the behaviour is undefined (see clause 15 (#sec-15)).
An implementation is permitted to extend the behaviour of
toPrecision for values of precision less than 1 or greater than 21. In
this case toPrecision would not necessarily throw RangeError for such
values.
File: javascript_ecma_262_5th_ed.info, Node: 1575 Properties of Number Instances, Next: 158 The Math Object, Prev: 15747 NumberprototypetoPrecision precision, Up: Top
435 15.7.5 (#sec-15.7.5) Properties of Number Instances
*******************************************************
Number instances inherit properties from the Number prototype object
and their [[Class]] internal property value is "Number". Number
instances also have a [[PrimitiveValue]] internal property.
The [[PrimitiveValue]] internal property is the Number value
represented by this Number object.
File: javascript_ecma_262_5th_ed.info, Node: 158 The Math Object, Next: 1581 Value Properties of the Math Object, Prev: 1575 Properties of Number Instances, Up: Top
436 15.8 (#sec-15.8) The Math Object
************************************
The Math object is a single object that has some named properties, some
of which are functions.
The value of the [[Prototype]] internal property of the Math object
is the standard built-in Object prototype object (15.2.4
(#sec-15.2.4)). The value of the [[Class]] internal property of the
Math object is "Math".
The Math object does not have a [[Construct]] internal property; it
is not possible to use the Math object as a constructor with the `new'
operator.
The Math object does not have a [[Call]] internal property; it is
not possible to invoke the Math object as a function.
NOTE In this specification, the phrase “the Number value for xâ€
has a technical meaning defined in 8.5 (#sec-8.5).
File: javascript_ecma_262_5th_ed.info, Node: 1581 Value Properties of the Math Object, Next: 15811 E, Prev: 158 The Math Object, Up: Top
437 15.8.1 (#sec-15.8.1) Value Properties of the Math Object
************************************************************
File: javascript_ecma_262_5th_ed.info, Node: 15811 E, Next: 15812 LN10, Prev: 1581 Value Properties of the Math Object, Up: Top
438 15.8.1.1 (#sec-15.8.1.1) E
******************************
The Number value for _e_, the base of the natural logarithms, which is
approximately 2.7182818284590452354.
This property has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: false }.
File: javascript_ecma_262_5th_ed.info, Node: 15812 LN10, Next: 15813 LN2, Prev: 15811 E, Up: Top
439 15.8.1.2 (#sec-15.8.1.2) LN10
*********************************
The Number value for the natural logarithm of 10, which is
approximately 2.302585092994046.
This property has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: false }.
File: javascript_ecma_262_5th_ed.info, Node: 15813 LN2, Next: 15814 LOG2E, Prev: 15812 LN10, Up: Top
440 15.8.1.3 (#sec-15.8.1.3) LN2
********************************
The Number value for the natural logarithm of 2, which is approximately
0.6931471805599453.
This property has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: false }.
File: javascript_ecma_262_5th_ed.info, Node: 15814 LOG2E, Next: 15815 LOG10E, Prev: 15813 LN2, Up: Top
441 15.8.1.4 (#sec-15.8.1.4) LOG2E
**********************************
The Number value for the base-2 logarithm of _e_, the base of the
natural logarithms; this value is approximately 1.4426950408889634.
NOTE The value of Math.LOG2E is approximately the reciprocal of the
value of Math.LN2.
File: javascript_ecma_262_5th_ed.info, Node: 15815 LOG10E, Next: 15816 PI, Prev: 15814 LOG2E, Up: Top
442 15.8.1.5 (#sec-15.8.1.5) LOG10E
***********************************
The Number value for the base-10 logarithm of _e_, the base of the
natural logarithms; this value is approximately 0.4342944819032518.
This property has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: false }.
NOTE The value of Math.LOG10E is approximately the reciprocal of the
value of Math.LN10.
File: javascript_ecma_262_5th_ed.info, Node: 15816 PI, Next: 15817 SQRT1_2, Prev: 15815 LOG10E, Up: Top
443 15.8.1.6 (#sec-15.8.1.6) PI
*******************************
The Number value for π, the ratio of the circumference of a circle to
its diameter, which is approximately 3.1415926535897932.
This property has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: false }.
File: javascript_ecma_262_5th_ed.info, Node: 15817 SQRT1_2, Next: 15818 SQRT2, Prev: 15816 PI, Up: Top
444 15.8.1.7 (#sec-15.8.1.7) SQRT1_2
************************************
The Number value for the square root of ½, which is approximately
0.7071067811865476.
This property has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: false }.
NOTE The value of Math.SQRT1_2 is approximately the reciprocal of
the value of Math.SQRT2.
File: javascript_ecma_262_5th_ed.info, Node: 15818 SQRT2, Next: 1582 Function Properties of the Math Object, Prev: 15817 SQRT1_2, Up: Top
445 15.8.1.8 (#sec-15.8.1.8) SQRT2
**********************************
The Number value for the square root of 2, which is approximately
1.4142135623730951.
This property has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: false }.
File: javascript_ecma_262_5th_ed.info, Node: 1582 Function Properties of the Math Object, Next: 15821 abs x, Prev: 15818 SQRT2, Up: Top
446 15.8.2 (#sec-15.8.2) Function Properties of the Math Object
***************************************************************
Each of the following Math object functions applies the ToNumber
(#sec-9.3) abstract operator to each of its arguments (in left-to-right
order if there is more than one) and then performs a computation on the
resulting Number value(s).
In the function descriptions below, the symbols NaN, −0, +0,
−∞ and +∞ refer to the Number values described in 8.5 (#sec-8.5).
NOTE The behaviour of the functions acos, asin, atan, atan2, cos,
exp, log, pow, sin, sqrt, and tan is not precisely specified here
except to require specific results for certain argument values that
represent boundary cases of interest. For other argument values, these
functions are intended to compute approximations to the results of
familiar mathematical functions, but some latitude is allowed in the
choice of approximation algorithms. The general intent is that an
implementer should be able to use the same mathematical library for
ECMAScript on a given hardware platform that is available to C
programmers on that platform. Although the choice of algorithms is left
to the implementation, it is recommended (but not specified by this
standard) that implementations use the approximation algorithms for
IEEE 754 arithmetic contained in *fdlibm*, the freely distributable
mathematical library from Sun Microsystems
(http://www.netlib.org/fdlibm (http://www.netlib.org/fdlibm)).
File: javascript_ecma_262_5th_ed.info, Node: 15821 abs x, Next: 15822 acos x, Prev: 1582 Function Properties of the Math Object, Up: Top
447 15.8.2.1 (#sec-15.8.2.1) abs (x)
************************************
Returns the absolute value of x; the result has the same magnitude as x
but has positive sign.
* * If x is −0, the result is +0.
* If x is −∞, the result is +∞.
File: javascript_ecma_262_5th_ed.info, Node: 15822 acos x, Next: 15823 asin x, Prev: 15821 abs x, Up: Top
448 15.8.2.2 (#sec-15.8.2.2) acos (x)
*************************************
Returns an implementation-dependent approximation to the arc cosine of
x. The result is expressed in radians and ranges from +0 to +Ï€.
* If x is NaN, the result is NaN.
* If x is greater than 1, the result is NaN.
* If x is less than −1, the result is NaN.
* If x is exactly 1, the result is +0.
File: javascript_ecma_262_5th_ed.info, Node: 15823 asin x, Next: 15824 atan x, Prev: 15822 acos x, Up: Top
449 15.8.2.3 (#sec-15.8.2.3) asin (x)
*************************************
Returns an implementation-dependent approximation to the arc sine of x.
The result is expressed in radians and ranges from −π/2 to +π/2.
* If x is NaN, the result is NaN.
* If x is greater than 1, the result is NaN.
* If x is less than −1, the result is NaN.
* If x is +0, the result is +0.
* If x is −0, the result is −0.
File: javascript_ecma_262_5th_ed.info, Node: 15824 atan x, Next: 15825 atan2 y x, Prev: 15823 asin x, Up: Top
450 15.8.2.4 (#sec-15.8.2.4) atan (x)
*************************************
Returns an implementation-dependent approximation to the arc tangent of
x. The result is expressed in radians and ranges from −π/2 to +π/2.
* If x is NaN, the result is NaN.
* If x is +0, the result is +0.
* If x is −0, the result is −0.
* If x is +∞, the result is an implementation-dependent
approximation to +Ï€/2.
* If x is −∞, the result is an implementation-dependent
approximation to −π/2.
File: javascript_ecma_262_5th_ed.info, Node: 15825 atan2 y x, Next: 15826 ceil x, Prev: 15824 atan x, Up: Top
451 15.8.2.5 (#sec-15.8.2.5) atan2 (y, x)
*****************************************
Returns an implementation-dependent approximation to the arc tangent of
the quotient y/x of the arguments y and x, where the signs of y and x
are used to determine the quadrant of the result. Note that it is
intentional and traditional for the two-argument arc tangent function
that the argument named y be first and the argument named x be second.
The result is expressed in radians and ranges from −π to +π.
* If either x or y is NaN, the result is NaN.
* If y>0 and x is +0, the result is an implementation-dependent
approximation to +Ï€/2.
* If y>0 and x is −0, the result is an implementation-dependent
approximation to +Ï€/2.
* If y is +0 and x>0, the result is +0.
* If y is +0 and x is +0, the result is +0.
* If y is +0 and x is −0, the result is an
implementation-dependent approximation to +Ï€.
* If y is +0 and x<0, the result is an implementation-dependent
approximation to +Ï€.
* If y is −0 and x>0, the result is −0.
* If y is −0 and x is +0, the result is −0.
* If y is −0 and x is −0, the result is an
implementation-dependent approximation to −π.
* If y is −0 and x<0, the result is an implementation-dependent
approximation to −π.
* If y<0 and x is +0, the result is an implementation-dependent
approximation to −π/2.
* If y<0 and x is −0, the result is an implementation-dependent
approximation to −π/2.
* * If y>0 and y is finite and x is −∞, the result if an
implementation-dependent approximation to +Ï€.
* If y<0 and y is finite and x is +∞, the result is −0.
* If y<0 and y is finite and x is −∞, the result is an
implementation-dependent approximation to −π.
* If y is +∞ and x is finite, the result is an
implementation-dependent approximation to +Ï€/2.
* If y is −∞ and x is finite, the result is an
implementation-dependent approximation to −π/2.
* If y is +∞ and x is +∞, the result is an
implementation-dependent approximation to +Ï€/4.
* If y is +∞ and x is −∞, the result is an
implementation-dependent approximation to +3Ï€/4.
* If y is −∞ and x is +∞, the result is an
implementation-dependent approximation to −π/4.
* If y is −∞ and x is −∞, the result is an
implementation-dependent approximation to −3π/4.
File: javascript_ecma_262_5th_ed.info, Node: 15826 ceil x, Next: 15827 cosx, Prev: 15825 atan2 y x, Up: Top
452 15.8.2.6 (#sec-15.8.2.6) ceil (x)
*************************************
Returns the smallest (closest to −∞) Number value that is not less
than x and is equal to a mathematical integer. If x is already an
integer, the result is x.
* If x is NaN, the result is NaN.
* If x is +0, the result is +0.
* If x is −0, the result is −0.
* If x is +∞, the result is +∞.
* If x is −∞, the result is −∞.
* If x is less than 0 but greater than −1, the result is −0.
The value of `Math.ceil(x)' is the same as the value of
`-Math.floor(-x)'.
File: javascript_ecma_262_5th_ed.info, Node: 15827 cosx, Next: 15828 expx, Prev: 15826 ceil x, Up: Top
453 15.8.2.7 (#sec-15.8.2.7) cos(x)
***********************************
Returns an implementation-dependent approximation to the cosine of x.
The argument is expressed in radians.
* If x is NaN, the result is NaN.
* If x is +0, the result is 1.
* If x is −0, the result is 1.
* If x is +∞, the result is NaN.
* If x is −∞, the result is NaN.
File: javascript_ecma_262_5th_ed.info, Node: 15828 expx, Next: 15829 floor x, Prev: 15827 cosx, Up: Top