W3C home > Mailing lists > Public > ietf-http-wg@w3.org > January to March 2020

Re: draft-ietf-httpbis-header-structure-15, Serializing a Decimal

From: Mark Nottingham <mnot@mnot.net>
Date: Thu, 30 Jan 2020 09:21:56 +1100
Cc: HTTP Working Group <ietf-http-wg@w3.org>, Poul-Henning Kamp <phk@varnish-cache.org>
Message-Id: <9E4F45C3-1B74-458D-AE93-E6EA6BE58A9C@mnot.net>
To: Kari Hurtta <hurtta-ietf@elmme-mailer.org>
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

Cheers,


> 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.
> |
> |   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.
> 
> I'm not sure how this works.
> 
> 
> Let's input_decimal  to be 123.9998
> 
> After step 3 output is "123"
> 
> After step 5 output is "123."
> 
> On step 8 the first three digits of input_decimal's fractional component
> are "999".
> 
> The final digit is "9".  There is no possiblity to round up that digit.
> 
> So final output is "123.999".
> 
> Is that orrect ? That is effectively truncation.
> 
> If 123.9998 is rounded to 3 fractional decimals, value is 124.000,
> but that serialization can not produce it.
> 
> / Kari Hurtta
> 
> 

--
Mark Nottingham   https://www.mnot.net/
Received on Wednesday, 29 January 2020 22:22:06 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 29 January 2020 22:22:07 UTC