Home | History | Annotate | Download | only in mjsunit
      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.
     29 assertEquals("1e+27", (1.2345e+27).toPrecision(1));
     30 assertEquals("1.2e+27", (1.2345e+27).toPrecision(2));
     31 assertEquals("1.23e+27", (1.2345e+27).toPrecision(3));
     32 assertEquals("1.234e+27", (1.2345e+27).toPrecision(4));
     33 assertEquals("1.2345e+27", (1.2345e+27).toPrecision(5));
     34 assertEquals("1.23450e+27", (1.2345e+27).toPrecision(6));
     35 assertEquals("1.234500e+27", (1.2345e+27).toPrecision(7));
     36 
     37 assertEquals("-1e+27", (-1.2345e+27).toPrecision(1));
     38 assertEquals("-1.2e+27", (-1.2345e+27).toPrecision(2));
     39 assertEquals("-1.23e+27", (-1.2345e+27).toPrecision(3));
     40 assertEquals("-1.234e+27", (-1.2345e+27).toPrecision(4));
     41 assertEquals("-1.2345e+27", (-1.2345e+27).toPrecision(5));
     42 assertEquals("-1.23450e+27", (-1.2345e+27).toPrecision(6));
     43 assertEquals("-1.234500e+27", (-1.2345e+27).toPrecision(7));
     44 
     45 
     46 // Test the fixed notation output.
     47 assertEquals("7", (7).toPrecision(1));
     48 assertEquals("7.0", (7).toPrecision(2));
     49 assertEquals("7.00", (7).toPrecision(3));
     50 
     51 assertEquals("-7", (-7).toPrecision(1));
     52 assertEquals("-7.0", (-7).toPrecision(2));
     53 assertEquals("-7.00", (-7).toPrecision(3));
     54 
     55 assertEquals("9e+1", (91).toPrecision(1));
     56 assertEquals("91", (91).toPrecision(2));
     57 assertEquals("91.0", (91).toPrecision(3));
     58 assertEquals("91.00", (91).toPrecision(4));
     59 
     60 assertEquals("-9e+1", (-91).toPrecision(1));
     61 assertEquals("-91", (-91).toPrecision(2));
     62 assertEquals("-91.0", (-91).toPrecision(3));
     63 assertEquals("-91.00", (-91).toPrecision(4));
     64 
     65 assertEquals("9e+1", (91.1234).toPrecision(1));
     66 assertEquals("91", (91.1234).toPrecision(2));
     67 assertEquals("91.1", (91.1234).toPrecision(3));
     68 assertEquals("91.12", (91.1234).toPrecision(4));
     69 assertEquals("91.123", (91.1234).toPrecision(5));
     70 assertEquals("91.1234", (91.1234).toPrecision(6));
     71 assertEquals("91.12340", (91.1234).toPrecision(7));
     72 assertEquals("91.123400", (91.1234).toPrecision(8));
     73 
     74 assertEquals("-9e+1", (-91.1234).toPrecision(1));
     75 assertEquals("-91", (-91.1234).toPrecision(2));
     76 assertEquals("-91.1", (-91.1234).toPrecision(3));
     77 assertEquals("-91.12", (-91.1234).toPrecision(4));
     78 assertEquals("-91.123", (-91.1234).toPrecision(5));
     79 assertEquals("-91.1234", (-91.1234).toPrecision(6));
     80 assertEquals("-91.12340", (-91.1234).toPrecision(7));
     81 assertEquals("-91.123400", (-91.1234).toPrecision(8));
     82 
     83