220 26346 <201606201758.41906.marc.mutz@kdab.com> article
Path: news.gmane.org!not-for-mail
From: Marc Mutz <marc.mutz@kdab.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: On P0037 - Fixed-Point Real Numbers
Date: Mon, 20 Jun 2016 17:58:39 +0200
Organization: KDAB
Lines: 62
Approved: news@gmane.org
Message-ID: <201606201758.41906.marc.mutz@kdab.com>
References: <navth1$67p$1@ger.gmane.org> <201606200924.36959.marc.mutz@kdab.com> <0e429c80-84d9-4c6e-93ff-6c5dcb26c9d4@rrsd.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: Text/Plain;
  charset="utf-8"
Content-Transfer-Encoding: 7bit
X-Trace: ger.gmane.org 1466438287 14043 80.91.229.3 (20 Jun 2016 15:58:07 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 20 Jun 2016 15:58:07 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCRPXDOU7ECRBAFFUC5QKGQERBKV6DA@isocpp.org Mon Jun 20 17:57:54 2016
Return-path: <std-proposals+bncBCRPXDOU7ECRBAFFUC5QKGQERBKV6DA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wm0-f72.google.com ([74.125.82.72])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCRPXDOU7ECRBAFFUC5QKGQERBKV6DA@isocpp.org>)
	id 1bF1aE-0001va-C2
	for gclcip-std-proposals@m.gmane.org; Mon, 20 Jun 2016 17:57:54 +0200
Original-Received: by mail-wm0-f72.google.com with SMTP id a66sf30738331wme.1
        for <gclcip-std-proposals@m.gmane.org>; Mon, 20 Jun 2016 08:57:54 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:sender:from:organization:to:subject:date
         :references:in-reply-to:mime-version:content-transfer-encoding
         :message-id:x-original-sender:x-original-authentication-results
         :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=0rvLYP6XfsNGEKzKkvRSihIMTaVZKT+acwEB9qFV6nE=;
        b=D1hviIzG+E0n4slomRldyty9hhc/0z6e8DgjDcTj7eLx8Nphtln0bkGq4AYRQpF2s1
         kdirTXtclcjxMdfqTlf3VmVPfMAJFNO6tnnGe3b6JnkwMzCwg/bybmp59A7EQMIYxxWa
         +zcIF6EG0dBrRO6zoeumWE6WdY12reBfFXET3QC+plxwzVV10+sRonmZ4DEGZTXJwPKr
         c3cdTHNyW/cCnjudlHsLxQyoNXbsjLwLVQQKAJWroB7U20+gULnkyPXEJf+7WyAroWnZ
         tt0r4wSdcrBQvcDJJvZbddYuEELee4hZEvfsIoMug83eu+b/6ZPIJYxB+D7uc 
X-Gm-Message-State: ALyK8tJO+7LFmnpRpQsI3q2Ql4WOgdYAyqlUtLUywx0n5vqb9CEwCQHZn6n4RNxwL7++ew==
X-Received: by 10.25.169.76 with SMTP id s73mr2011013lfe.5.1466438273747;
        Mon, 20 Jun 2016 08:57:53 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.158.19 with SMTP id h19ls413784wme.49.gmail; Mon, 20 Jun
 2016 08:57:52 -0700 (PDT)
X-Received: by 10.28.152.202 with SMTP id a193mr12105704wme.98.1466438272429;
        Mon, 20 Jun 2016 08:57:52 -0700 (PDT)
Original-Received: from mail.kdab.com (mail.kdab.com. [176.9.126.58])
        by mx.google.com with ESMTPS id fi5si30117290wjb.85.2016.06.20.08.57.52
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Mon, 20 Jun 2016 08:57:52 -0700 (PDT)
Received-SPF: pass (google.com: domain of marc.mutz@kdab.com designates 176.9.126.58 as permitted sender) client-ip=176.9.126.58;
X-Virus-Scanned: amavisd-new at kdab.com
Original-Sender: marc@kdab.com
In-Reply-To: <0e429c80-84d9-4c6e-93ff-6c5dcb26c9d4@rrsd.com>
X-Original-Sender: marc.mutz@kdab.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of marc.mutz@kdab.com designates 176.9.126.58 as permitted sender) smtp.mailfrom=marc.mutz@kdab.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:26346
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/26346>

On Monday 20 June 2016 16:45:11 Robert Ramey wrote:
> Obviously you're absolutely correct on this.  It seems that the whole
> job is aready done - and in the most general way.
> 
> But one thing bothers me - with std::ratio I can't specify the
> underlying value type.  One of the fixed_binary use cases is to use it
> for a pixel
> 
> fixed_binary<unsigned char, 3>  // or something like that
> 
> how could std::ration be used to address this?

The same way as std::chrono::duration does. Ratio is just that: a ratio. The 
underlying type is another template argument:

    template <Arithmetic Representation, class Period = std::ratio<1>>
    class duration;

    template <Arithmetic Representation,
               Ratio R = std::ratio<1, width<Representation>/2>>
    class fixed_point;

http://en.cppreference.com/w/cpp/chrono/duration

Thanks,
Marc

> Robert Ramey
> 
> On 6/20/16 12:24 AM, Marc Mutz wrote:
> > On Sunday 28 February 2016 23:49:04 Robert Ramey wrote:
> >> integer part + fractional part where fraction part is any integer.
> > 
> > ... or a std::ratio<>. I don't quite like that we'll have two independent
> > fixed-point implementations in the standard: duration and fixed_point.
> > 
> > I'm sure this has been discussed, but P0037R2 doesn't contain anything
> > about <ratio>.
> > 
> > So I'd like to ask why a fixed_point is represented by an exponent, and
> > not a
> > 
> > std::ratio object:
> >    using dollars = fixed_point<int, ratio<1,100>>; // in units of cents
> > 
> > Though maybe then the fixed_point name is no longer so good, and
> > something containing "discrete" might be better.
> > 
> > If the answer is "we want to restrict to an integer number of bits for
> > performance", then the counter-argument would be that that can be done
> > using specialisation of the operations based on whether the std::ratio
> > is of the form 2^-N for some N.
> > 
> > Thanks,
> > Marc

-- 
Marc Mutz <marc.mutz@kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - Qt, C++ and OpenGL Experts

.
