<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>5258</bug_id>
          
          <creation_ts>2005-10-04 10:52:18 -0700</creation_ts>
          <short_desc>toFixed() doesn&apos;t handle enough cases</short_desc>
          <delta_ts>2007-12-28 15:16:27 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>420+</version>
          <rep_platform>Other</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>16640</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>HasReduction, InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="George Staikos">staikos</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ian</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>21337</commentid>
    <comment_count>0</comment_count>
    <who name="George Staikos">staikos</who>
    <bug_when>2005-10-04 10:52:18 -0700</bug_when>
    <thetext>Number.toFixed() doesn&apos;t handle any case besides 0..20 which is not what 
FireFox does.  See the testcases below.  I don&apos;t have a patch to fix all of 
this at this time. 
 
Here are some testcases: 
 
print(eval(&quot;Number(1234.567).toFixed(undefined)&quot;));  
print(&quot;expected 1235&quot;);  
print(eval(&quot;Number(1234.567).toFixed(0)&quot;));  
print(&quot;expected 1235&quot;);  
print(eval(&quot;Number(1234.567).toFixed(1)&quot;));  
print(&quot;expected 1235.6&quot;);  
print(eval(&quot;Number(1234.567).toFixed(2)&quot;));  
print(&quot;expected 1235.57&quot;);  
print(eval(&quot;Number(1234.567).toFixed(-1)&quot;));  
print(&quot;expected 1230&quot;);  
print(eval(&quot;Number(1234.567).toFixed(-4)&quot;));  
print(&quot;expected 0&quot;);  
print(eval(&quot;Number(1234.567).toFixed(-5)&quot;));  
print(&quot;expected 0&quot;);  
print(eval(&quot;Number(1234.567).toFixed(1/0)&quot;));  
print(&quot;expected exception&quot;);</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>27695</commentid>
    <comment_count>1</comment_count>
    <who name="Ricci Adams">ricciadams</who>
    <bug_when>2006-01-03 20:02:36 -0800</bug_when>
    <thetext>Section 15.7.4.5 of ECMA-262 documents the correct behavior of toFixed().  Step 2 specifically states that 
a RangeError exception should be thrown for cases other than 0..20.  Thus, I believe that JavaScriptCore&apos;s 
behavior for the last 7 test cases presented in the above comment is correct.

However, step 1 states that toFixed(undefined) should be the same as toFixed(0).  This does not appear to 
be the case in our implementation.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>27696</commentid>
    <comment_count>2</comment_count>
    <who name="Ricci Adams">ricciadams</who>
    <bug_when>2006-01-03 20:20:37 -0800</bug_when>
    <thetext>Oops.  toFixed(undefined) was fixed in http://bugzilla.opendarwin.org/show_bug.cgi?id=6267 .  I 
accidentally tested in latest-released Safari instead of ToT.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>27733</commentid>
    <comment_count>3</comment_count>
    <who name="Maks Orlovich">maksim</who>
    <bug_when>2006-01-04 11:49:39 -0800</bug_when>
    <thetext>Both behavior are valid, actually. At the second of the section, you&apos;ll  
noticed:  
&quot;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. &quot; 
 </thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>28690</commentid>
    <comment_count>4</comment_count>
    <who name="Gavin Kistner">gavin</who>
    <bug_when>2006-01-17 07:14:35 -0800</bug_when>
    <thetext>...which means that this is less of a bug report, and more of a feature request. (To the extent that not 
matching some non-standard behavior of browser X is a feature mis-match and not a bug.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>32392</commentid>
    <comment_count>5</comment_count>
    <who name="Joost de Valk (AlthA)">joost</who>
    <bug_when>2006-02-13 16:04:26 -0800</bug_when>
    <thetext>Reassigning to webkit-unassigned, to make sure more people see this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>32786</commentid>
    <comment_count>6</comment_count>
    <who name="Joost de Valk (AlthA)">joost</who>
    <bug_when>2006-02-15 14:53:27 -0800</bug_when>
    <thetext>This is an enhancement request, as i agree with #c4, attaching testcase in a sec.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>32787</commentid>
    <comment_count>7</comment_count>
      <attachid>6512</attachid>
    <who name="Joost de Valk (AlthA)">joost</who>
    <bug_when>2006-02-15 14:53:45 -0800</bug_when>
    <thetext>Created attachment 6512
Testcase</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6171</commentid>
    <comment_count>8</comment_count>
    <who name="ivo">rossacher</who>
    <bug_when>2007-06-26 13:08:41 -0700</bug_when>
    <thetext>toFixed as well as toPrecision do have failures which seem related to this issue. The following testcase demonstrates one of the very clear ones.
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Test&lt;/title&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var zahl1=1.0;
var zahl2=1.000000001;
var zahl3=-0.0;
var zahl4=-0.00001;
alert(&quot;1.0==&quot;+zahl1.toPrecision(6)+&quot;==&quot;+zahl2.toPrecision(6));
alert(&quot;0.0==&quot;+zahl3.toFixed(3)+&quot;==&quot;+zahl4.toFixed(3));
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;
This issue was Bug 136734 in kde and is fixed meanwhile in kde(don&apos;t ask me how. I did not have a look at the code till now)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6166</commentid>
    <comment_count>9</comment_count>
      <attachid>15258</attachid>
    <who name="ivo">rossacher</who>
    <bug_when>2007-06-26 13:11:15 -0700</bug_when>
    <thetext>Created attachment 15258
Test case</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5488</commentid>
    <comment_count>10</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2007-07-05 20:44:29 -0700</bug_when>
    <thetext>(In reply to comment #9)
&gt; Created an attachment (id=15258) [edit]
&gt; Test case

This test case assert()&apos;s running a local debug build of WebKit r24013 with Safari 3.0 (522.12) on Mac OS X 10.4.10 (8R218):

/path/to/WebKit/JavaScriptCore/kjs/number_object.cpp:371: failed assertion `n &lt; intPow10(p)&apos;
Abort trap

</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5468</commentid>
    <comment_count>11</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2007-07-05 20:46:34 -0700</bug_when>
    <thetext>&lt;rdar://problem/5316243&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>65498</commentid>
    <comment_count>12</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2007-12-28 15:16:27 -0800</bug_when>
    <thetext>The patches attached to bug 16640 make us pass these tests.  I&apos;m going to dup this to bug 16640 unless there are objections.

*** This bug has been marked as a duplicate of 16640 ***</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>6512</attachid>
            <date>2006-02-15 14:53:45 -0800</date>
            <delta_ts>2006-02-15 14:53:45 -0800</delta_ts>
            <desc>Testcase</desc>
            <filename>test.html</filename>
            <type>text/html</type>
            <size>870</size>
            <attacher name="Joost de Valk (AlthA)">joost</attacher>
            
              <data encoding="base64">PHNjcmlwdCB0eXBlPSJ0ZXh0L2phdmFzY3JpcHQiPgpkb2N1bWVudC53cml0ZShldmFsKCJOdW1i
ZXIoMTIzNC41NjcpLnRvR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</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>15258</attachid>
            <date>2007-06-26 13:11:15 -0700</date>
            <delta_ts>2007-06-26 13:11:15 -0700</delta_ts>
            <desc>Test case</desc>
            <filename>test1.html</filename>
            <type>text/html</type>
            <size>298</size>
            <attacher name="ivo">rossacher</attacher>
            
              <data encoding="base64">PGh0bWw+CjxoZWFkPgo8dGl0bGU+VGVzdDwvdGl0bGU+CjxzY3JpcHQgdHlwZT0idGV4dC9qYXZh
c2NyaXB0Ij4KdmFyIHphaGwxPTEuMDsKdmFyIHphaGwyPTEuMDAwMDAwMDAxOwp2YXIgemFobDM9
LTAuMDsKdmFyIHphaGw0PS0wLjAwMDAxOwphbGVydCgiMS4wPT0iK3phaGwxLnRvUHJlY2lzaW9u
KDYpKyI9PSIremFobDIudG9QcmVjaXNpb24oNikpOwphbGVydCgiMC4wPT0iK3phaGwzLnRvRml4
ZWQoMykrIj09Iit6YWhsNC50b0ZpeGVkKDMpKTsKPC9zY3JpcHQ+CjwvaGVhZD4KPGJvZHk+Cjwv
Ym9keT4KPC9odG1sPg==
</data>

          </attachment>
      

    </bug>

</bugzilla>