- From: Tab Atkins Jr. via GitHub <sysbot+gh@w3.org>
- Date: Tue, 25 Apr 2023 17:34:59 +0000
- To: public-css-archive@w3.org
For the Agenda+, here's a first draft of the text to replace the `<number>` part of [the serialization rules](https://drafts.csswg.org/cssom/#serialize-a-css-component-value): ``` The return value of the following algorithm: <div algorithm="serialize a number"> 1. Let |s| initially be the empty [=string=]. 2. If the absolute value of the component is less than 10<sup>21</sup> and greater than or equal to 10<sup>-6</sup>, or equal to zero: * Serialize the integer part of the component as a base-10 number (omitting leading zeros) and append the result to |s|. * If the decimal part of the component, when truncated to 6 digits, is non-zero, append "." (U+002E FULL STOP) to |s|, then serialize the decimal part of the component as a base-10 decimal, truncating to 6 digits and omitting trailing zeros, and append the result to |s|. * Return |s|. 3. Otherwise, serialize the result in scientific notation: * Let |power| be the integer power of 10 that, when multiplied with the component, produces a number with a single non-zero integer digit. Let |shifted component| be the result of multiplying the component by |power|. * Serialize |shifted component| as a <number>, and append the result to |s|. * Append "e" (U+0065 LATIN SMALL LETTER E) to |s|, then serialize |power| as a base-10 integer, omitting leading zeros, and append the result to |s|. * Return |s|. </div> Note: This algorithm matches the behavior of JavaScript in serializing numbers, except that we additionally truncate the decimal portion to a maximum of 6 digits. This somewhat avoids exposing the exact representation precision of numeric values, as that can change between properties and between implementations. It also avoids exposing minor differences in ordering of internal arithmetic operations, which might produce very slightly different floating point values which would serialize differently despite acting identically in practice. ``` -- GitHub Notification of comment by tabatkins Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/8538#issuecomment-1522166138 using your GitHub account -- Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Tuesday, 25 April 2023 17:35:01 UTC