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

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>8047</bug_id>
          
          <creation_ts>2009-10-25 00:15:18 +0000</creation_ts>
          <short_desc>Reflecting floats: The rules for parsing floating point number values return an unlimited-precision (finite in base 10) number. How is it converted to limited-precision IDL attribute types? In particular, what rounding mode is used? and do very large valu</short_desc>
          <delta_ts>2010-10-04 14:46:59 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>HTML WG</product>
          <component>pre-LC1 HTML5 spec (editor: Ian Hickson)</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>other</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.whatwg.org/specs/web-apps/current-work/#reflecting-content-attributes-in-idl-attributes</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>NE</keywords>
          <priority>P3</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>LC</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>contributor</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>excors</cc>
    
    <cc>ian</cc>
    
    <cc>mike</cc>
    
    <cc>public-html-admin</cc>
    
    <cc>public-html-wg-issue-tracking</cc>
          
          <qa_contact name="HTML WG Bugzilla archive list">public-html-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>28943</commentid>
    <comment_count>0</comment_count>
    <who name="">contributor</who>
    <bug_when>2009-10-25 00:15:18 +0000</bug_when>
    <thetext>Section: http://www.whatwg.org/specs/web-apps/current-work/#reflecting-content-attributes-in-idl-attributes

Comment:
Reflecting floats: The rules for parsing floating point number values return an unlimited-precision (finite in base 10) number. How is it converted to limited-precision IDL attribute types? In particular, what rounding mode is used? and do very large values get converted to Infinity?

Posted from: 212.183.134.209</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>28982</commentid>
    <comment_count>1</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2009-10-25 09:04:18 +0000</bug_when>
    <thetext>Values that are out of range (can&apos;t be expressed by the IDL attribute) return 0.0. (See bug 8046.)

EDITOR&apos;S RESPONSE: This is an Editor&apos;s Response to your comment. If you are satisfied with this response, please change the state of this bug to CLOSED. If you have additional information and would like the editor to reconsider, please reopen this bug. If you would like to escalate the issue to the full HTML Working Group, please add the TrackerRequest keyword to this bug, and suggest title and text for the tracker issue; or you may create a tracker issue yourself, if you are able to do so. For more details, see this document:
   http://dev.w3.org/html5/decision-policy/decision-policy.html

Status: Accepted
Change Description: see diff given below
Rationale: Concurred with reporter&apos;s comments.

If the new text isn&apos;t clear enough, please suggest better text.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>28983</commentid>
    <comment_count>2</comment_count>
    <who name="">contributor</who>
    <bug_when>2009-10-25 09:04:45 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r4331.
Check-in comment: Try to be more explicit about what happens with parsing strings into floats for out-of-range or over-precise values.
http://html5.org/tools/web-apps-tracker?from=4330&amp;to=4331
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>28996</commentid>
    <comment_count>3</comment_count>
    <who name="Philip Taylor">excors</who>
    <bug_when>2009-10-25 10:10:14 +0000</bug_when>
    <thetext>It seems clearer now, but weird, because it doesn&apos;t match how floats are parsed in ECMAScript (or any other environments I&apos;m aware of, though that&apos;s not many).

E.g. the string
  &quot;1.00000000000000012&quot;
in common ECMAScript implementations gets converted to the number
   1.0000000000000002
(and if you subtract 1 then you get 2.220446049250313e-16)
whereas HTML5 now just talks about &quot;truncating&quot;, so it would end up with the number 1.0 (being the next lowest representable number).

I don&apos;t see any reason to differ from ES, and doing so seems like it could make implementations more complex (since they couldn&apos;t be based on existing float-parsing code).

ES defines ToNumber as truncating after the 20th significant digit and then (optionally) incrementing the 20th significant digit, and then doing round-to-nearest with ties-to-even. But these are (32-bit) floats, not Numbers, so HTML5 can&apos;t do exactly the same.

It might be better to copy the definition from http://dev.w3.org/2006/webapi/WebIDL/#es-float , saying something like:

    &quot;A number n is &lt;dfn&gt;converted to an IDL float value&lt;/dfn&gt; by running the following algorithm:
    1. Let S be the set of finite IEEE 754 single-precision floating point values except &amp;#8722;0, but with two special values added: 2^128 and &amp;#8722;2^128.
    2. Let V be the number in S that is closest to n, selecting the number with an even significand if there are two equally close values. (The two special values 2^128 and &amp;#8722;2^128 are considered to have even significands for this purpose.)
    3. If V is 2^128, return +&amp;#8734;.
    4. If V is &amp;#8722;2^128, return &amp;#8722;&amp;#8734;.
    5. Return V.

    ...

    If a reflecting IDL attribute is a floating point number type (float), then, on getting, the content attribute must be parsed according to the rules for parsing floating point number values, and if that is successful, the number must be &lt;a href&gt;converted to an IDL float value&lt;/a&gt;; and if the resulting value is finite, then that value must be returned. If, on the other hand, the parsing fails or the conversion returns an infinite value, ...&quot;

(n can&apos;t be NaN or &amp;#8722;0, so those cases aren&apos;t handled here.)

I doubt that is perfectly correct (perhaps n needs to be truncated before rounding?), and it would be good if someone who understands floating point parsing properly could suggest something better, but I think this is better than what the spec says now.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>29058</commentid>
    <comment_count>4</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2009-10-27 10:29:32 +0000</bug_when>
    <thetext>EDITOR&apos;S RESPONSE: This is an Editor&apos;s Response to your comment. If you are satisfied with this response, please change the state of this bug to CLOSED. If you have additional information and would like the editor to reconsider, please reopen this bug. If you would like to escalate the issue to the full HTML Working Group, please add the TrackerRequest keyword to this bug, and suggest title and text for the tracker issue; or you may create a tracker issue yourself, if you are able to do so. For more details, see this document:
   http://dev.w3.org/html5/decision-policy/decision-policy.html

Status: Accepted
Change Description: see diff given below
Rationale: Concurred with reporter&apos;s comments.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>29059</commentid>
    <comment_count>5</comment_count>
    <who name="">contributor</who>
    <bug_when>2009-10-27 10:30:05 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r4348.
Check-in comment: Redefine how to parse floats so that they are always narrowed to 32bit floats.
http://html5.org/tools/web-apps-tracker?from=4347&amp;to=4348
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>29064</commentid>
    <comment_count>6</comment_count>
    <who name="Philip Taylor">excors</who>
    <bug_when>2009-10-27 14:36:54 +0000</bug_when>
    <thetext>My original doubt was about numbers like 1 + 2^-53:

1.00000000000000011102230246251565404236316680908203125

where a perturbation in the final digit can change whether the closest (double-precision) number is 1.0 or 1.0+epsilon. ECMAScript explicitly truncates strings to 20 significant digits before rounding, so implementations don&apos;t have to (but may) examine an unlimited number of characters.

However, it looks like most browser JS implementations do examine every digit when parsing numbers. (Only IE and Opera-on-Linux appear to truncate.)

So it seems the truncation behaviour is not necessary, and what HTML5 currently defines is reasonable and implementable, as far as I can tell. Implementors can complain if they don&apos;t like it. (And in practice it only matters in crazy edge cases anyway.)</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>