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

Kari Hurtta <hurtta-ietf@elmme-mailer.org> Thu, 30 January 2020 05:54 UTC

Return-Path: <ietf-http-wg-request+bounce-httpbisa-archive-bis2juki=lists.ie@listhub.w3.org>
X-Original-To: ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com
Delivered-To: ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 0AB27120059 for <ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com>; Wed, 29 Jan 2020 21:54:59 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.651
X-Spam-Level:
X-Spam-Status: No, score=-2.651 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, MAILING_LIST_MULTI=-1, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id t0zgCo2tbzIp for <ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com>; Wed, 29 Jan 2020 21:54:55 -0800 (PST)
Received: from frink.w3.org (frink.w3.org [IPv6:2603:400a:ffff:804:801e:34:0:38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 6E81F12006B for <httpbisa-archive-bis2Juki@lists.ietf.org>; Wed, 29 Jan 2020 21:54:55 -0800 (PST)
Received: from lists by frink.w3.org with local (Exim 4.89) (envelope-from <ietf-http-wg-request@listhub.w3.org>) id 1ix2kv-0003DB-UL for ietf-http-wg-dist@listhub.w3.org; Thu, 30 Jan 2020 05:52:45 +0000
Resent-Date: Thu, 30 Jan 2020 05:52:45 +0000
Resent-Message-Id: <E1ix2kv-0003DB-UL@frink.w3.org>
Received: from mimas.w3.org ([2603:400a:ffff:804:801e:34:0:4f]) by frink.w3.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from <khurtta@welho.com>) id 1ix2kt-0003CQ-PC for ietf-http-wg@listhub.w3.org; Thu, 30 Jan 2020 05:52:43 +0000
Received: from welho-filter3.welho.com ([83.102.41.25]) by mimas.w3.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from <khurtta@welho.com>) id 1ix2kr-0004rQ-5M for ietf-http-wg@w3.org; Thu, 30 Jan 2020 05:52:43 +0000
Received: from localhost (localhost [127.0.0.1]) by welho-filter3.welho.com (Postfix) with ESMTP id 1CFF91F35; Thu, 30 Jan 2020 07:52:38 +0200 (EET)
X-Virus-Scanned: Debian amavisd-new at pp.htv.fi
Received: from welho-smtp1.welho.com ([IPv6:::ffff:83.102.41.84]) by localhost (welho-filter3.welho.com [::ffff:83.102.41.25]) (amavisd-new, port 10024) with ESMTP id 6RkA85UZZ74B; Thu, 30 Jan 2020 07:52:35 +0200 (EET)
Received: from kasvihuone.keh.iki.fi (89-27-39-95.bb.dnainternet.fi [89.27.39.95]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by welho-smtp1.welho.com (Postfix) with ESMTPS id A7DD17A; Thu, 30 Jan 2020 07:52:29 +0200 (EET)
In-Reply-To: <9E4F45C3-1B74-458D-AE93-E6EA6BE58A9C@mnot.net>
References: <158028031175.4610.9085377324549619919@ietfa.amsl.com> <20200129181750.78AF7350F@welho-filter3.welho.com> <9E4F45C3-1B74-458D-AE93-E6EA6BE58A9C@mnot.net>
To: Mark Nottingham <mnot@mnot.net>
Date: Thu, 30 Jan 2020 07:52:29 +0200
From: Kari Hurtta <hurtta-ietf@elmme-mailer.org>
CC: Kari Hurtta <hurtta-ietf@elmme-mailer.org>, HTTP Working Group <ietf-http-wg@w3.org>, Poul-Henning Kamp <phk@varnish-cache.org>
X-Mailer: ELM [version ME+ 2.5 PLalpha50+]
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="US-ASCII"
Message-Id: <20200130055238.1CFF91F35@welho-filter3.welho.com>
Received-SPF: none client-ip=83.102.41.25; envelope-from=khurtta@welho.com; helo=welho-filter3.welho.com
X-W3C-Hub-Spam-Status: No, score=-5.3
X-W3C-Hub-Spam-Report: BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_NONE=0.001, W3C_AA=-1, W3C_IRA=-1, W3C_WL=-1
X-W3C-Scan-Sig: mimas.w3.org 1ix2kr-0004rQ-5M f842c4ddc96b798e27a5ab6eb51e1f15
X-Original-To: ietf-http-wg@w3.org
Subject: Re: draft-ietf-httpbis-header-structure-15, Serializing a Decimal
Archived-At: <https://www.w3.org/mid/20200130055238.1CFF91F35@welho-filter3.welho.com>
Resent-From: ietf-http-wg@w3.org
X-Mailing-List: <ietf-http-wg@w3.org> archive/latest/37327
X-Loop: ietf-http-wg@w3.org
Resent-Sender: ietf-http-wg-request@w3.org
Precedence: list
List-Id: <ietf-http-wg.w3.org>
List-Help: <https://www.w3.org/Mail/>
List-Post: <mailto:ietf-http-wg@w3.org>
List-Unsubscribe: <mailto:ietf-http-wg-request@w3.org?subject=unsubscribe>

> 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.

 
> 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