1// Copyright 2008 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6//     * Redistributions of source code must retain the above copyright
7//       notice, this list of conditions and the following disclaimer.
8//     * Redistributions in binary form must reproduce the above
9//       copyright notice, this list of conditions and the following
10//       disclaimer in the documentation and/or other materials provided
11//       with the distribution.
12//     * Neither the name of Google Inc. nor the names of its
13//       contributors may be used to endorse or promote products derived
14//       from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28// Test the exponential notation output.
29assertEquals("1e+27", (1.2345e+27).toPrecision(1));
30assertEquals("1.2e+27", (1.2345e+27).toPrecision(2));
31assertEquals("1.23e+27", (1.2345e+27).toPrecision(3));
32assertEquals("1.234e+27", (1.2345e+27).toPrecision(4));
33assertEquals("1.2345e+27", (1.2345e+27).toPrecision(5));
34assertEquals("1.23450e+27", (1.2345e+27).toPrecision(6));
35assertEquals("1.234500e+27", (1.2345e+27).toPrecision(7));
36
37assertEquals("-1e+27", (-1.2345e+27).toPrecision(1));
38assertEquals("-1.2e+27", (-1.2345e+27).toPrecision(2));
39assertEquals("-1.23e+27", (-1.2345e+27).toPrecision(3));
40assertEquals("-1.234e+27", (-1.2345e+27).toPrecision(4));
41assertEquals("-1.2345e+27", (-1.2345e+27).toPrecision(5));
42assertEquals("-1.23450e+27", (-1.2345e+27).toPrecision(6));
43assertEquals("-1.234500e+27", (-1.2345e+27).toPrecision(7));
44
45
46// Test the fixed notation output.
47assertEquals("7", (7).toPrecision(1));
48assertEquals("7.0", (7).toPrecision(2));
49assertEquals("7.00", (7).toPrecision(3));
50
51assertEquals("-7", (-7).toPrecision(1));
52assertEquals("-7.0", (-7).toPrecision(2));
53assertEquals("-7.00", (-7).toPrecision(3));
54
55assertEquals("9e+1", (91).toPrecision(1));
56assertEquals("91", (91).toPrecision(2));
57assertEquals("91.0", (91).toPrecision(3));
58assertEquals("91.00", (91).toPrecision(4));
59
60assertEquals("-9e+1", (-91).toPrecision(1));
61assertEquals("-91", (-91).toPrecision(2));
62assertEquals("-91.0", (-91).toPrecision(3));
63assertEquals("-91.00", (-91).toPrecision(4));
64
65assertEquals("9e+1", (91.1234).toPrecision(1));
66assertEquals("91", (91.1234).toPrecision(2));
67assertEquals("91.1", (91.1234).toPrecision(3));
68assertEquals("91.12", (91.1234).toPrecision(4));
69assertEquals("91.123", (91.1234).toPrecision(5));
70assertEquals("91.1234", (91.1234).toPrecision(6));
71assertEquals("91.12340", (91.1234).toPrecision(7));
72assertEquals("91.123400", (91.1234).toPrecision(8));
73
74assertEquals("-9e+1", (-91.1234).toPrecision(1));
75assertEquals("-91", (-91.1234).toPrecision(2));
76assertEquals("-91.1", (-91.1234).toPrecision(3));
77assertEquals("-91.12", (-91.1234).toPrecision(4));
78assertEquals("-91.123", (-91.1234).toPrecision(5));
79assertEquals("-91.1234", (-91.1234).toPrecision(6));
80assertEquals("-91.12340", (-91.1234).toPrecision(7));
81assertEquals("-91.123400", (-91.1234).toPrecision(8));
82
83