- From: Mark Nottingham <mnot@mnot.net>
- Date: Thu, 30 Jan 2020 16:56:06 +1100
- To: Kari Hurtta <hurtta-ietf@elmme-mailer.org>
- Cc: HTTP Working Group <ietf-http-wg@w3.org>, Poul-Henning Kamp <phk@varnish-cache.org>
On 30 Jan 2020, at 4:52 pm, Kari Hurtta <hurtta-ietf@elmme-mailer.org> wrote: > >> Hi Kari, >> >> Very good catch; I noticed this a while back but forgot to file an issue. Now: >> https://github.com/httpwg/http-extensions/issues/1043 > > | ... still isn't right, as Kari noticed. E.g., a value of 1.9944 won't get rounded to 2.0. > > You mean: E.g., a value of 1.9998 won't get rounded to 2.0. > > Algorithm produces three digits for fractional component. > > And 1.994 is correct rounding for 1.9944, I think. Corrected. > > >> Cheers, >> > > Another thing what can be issue when rounding is applied. > >>> On 30 Jan 2020, at 5:17 am, Kari Hurtta <hurtta-ietf@elmme-mailer.org> wrote: >>> >>> 4.1.5. Serializing a Decimal >>> https://tools.ietf.org/html/draft-ietf-httpbis-header-structure-15#section-4.1.5 >>> >>> >>> | Given a decimal_number as input_decimal, return an ASCII string >>> | suitable for use in a HTTP header value. >>> | >>> | 1. Let output be an empty string. >>> | >>> | 2. If input_decimal is less than (but not equal to) 0, append "-" to >>> | output. >>> | >>> | 3. Append input_decimal's integer component represented in base 10 >>> | (using only decimal digits) to output; if it is zero, append "0". >>> | >>> | 4. If the number of characters appended in the previous step is >>> | greater than 12, fail serialisation. > > A decimal_number number can be -999 999 999 999.9997 or 999 999 999 999.9997 > > In step 3 there is digits 999999999999 so no failure on step 4 > > >>> | 5. Append "." to output. >>> | >>> | 6. If input_decimal's fractional component is zero, append "0" to >>> | output. >>> | >>> | 7. Else if input_decimal's fractional component has up to three >>> | digits, append them represented in base 10 (using only decimal >>> | digits) to output. >>> | >>> | 8. Otherwise, append the first three digits of input_decimal's >>> | fractional component (represented in base 10, using only decimal >>> | digits) to output, rounding the final digit to the nearest value, >>> | or to the even value if it is equidistant. >>> | >>> | 9. Return output. > > First theree digits for fractional component are 999 > > "Correct" rounding for -999 999 999 999.9997 is -1 000 000 000 000.0 and > for 999 999 999 999.9997 is 1 000 000 000 000.0, but there are 13 digits > on integer component. > > That is "solved" if > when decimal_number < -999 999 999 999.999 or > decimal_number > 999 999 999 999.999, fractional component > is truncated to 3 digits and rounding is not tried. > > / Kari Hurtta -- Mark Nottingham https://www.mnot.net/
Received on Thursday, 30 January 2020 05:56:19 UTC