220 31542 <58C2D210.6080900@gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Matthew Woehlke <mwoehlke.floss@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Math constants
Date: Fri, 10 Mar 2017 11:19:28 -0500
Lines: 58
Approved: news@gmane.org
Message-ID: <58C2D210.6080900@gmail.com>
References: <ad05f2f2-609d-4fd3-90f7-d66c74e168b7@isocpp.org>
 <6bccd7e5-82ad-4c59-9f72-f7fb6639c0ca@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: blaine.gmane.org 1489162807 1890 195.159.176.226 (10 Mar 2017 16:20:07 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 10 Mar 2017 16:20:07 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
 Thunderbird/38.1.0
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBC37LBFWUIFBBE5ERPDAKGQEZI5W6ZY@isocpp.org Fri Mar 10 17:19:59 2017
Return-path: <std-proposals+bncBC37LBFWUIFBBE5ERPDAKGQEZI5W6ZY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ua0-f200.google.com ([209.85.217.200])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBC37LBFWUIFBBE5ERPDAKGQEZI5W6ZY@isocpp.org>)
	id 1cmNGl-0007nH-Iz
	for gclcip-std-proposals@m.gmane.org; Fri, 10 Mar 2017 17:19:55 +0100
Original-Received: by mail-ua0-f200.google.com with SMTP id f54sf101625388uaa.5
        for <gclcip-std-proposals@m.gmane.org>; Fri, 10 Mar 2017 08:20:01 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=subject:to:references:from:message-id:date:user-agent:mime-version
         :in-reply-to:content-transfer-encoding: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=k3SVxDPkCtu27CTUvhCEnBSb3e5Lt00FDKaQ5d7NSQc=;
        b=h1cbJU3TXWql8FsDNHh9MCNhtztnifUmcR2yI1aVurv5qduIu9sHJ/PZKnqZ1EK65m
         Nk1J+FVFgnFSQ+ekXXAm6cvxHmzTkyz0qi9BKH4BFD64+e2IR400e0a4hKeCaGOuCBgk
         KiRFTvFvbwWVmMDnPCiE+bMgw0NIfmKx6zO2maqYUwOnUegQlEwgEdeAf26ToSTN7QFR
         +tEdZYD+feKMYMTvgWyAEhcA90cnsXv5c7u76yOcsOx/h9rrDG67TsoJ3geozY7++h2M
         +IriuvvLiX3AByFZdNzW6poTtXlMWypiw2vcLNO/w5vXUsicgG7nULXmZ1CmfDELSJJv
      
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:subject:to:references:from:message-id:date
         :user-agent:mime-version:in-reply-to:content-transfer-encoding
         :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=k3SVxDPkCtu27CTUvhCEnBSb3e5Lt00FDKaQ5d7NSQc=;
        b=i7LLmsUvyKtiwh0dtnXeRxdVy4q9y0ziyz+6OKzIn28X+KPfhCn2pmJU8rdzPcuOhq
         eHxQOon80oc5AMIQ7VQOIxi+eTS5vphKOeQXdh7867kW2V6B+iIqd2ocMvZSlD0trbUQ
         Wx4tGAV/B/unchxqyzD4IRSNXolhwguCz576n9Mh8g5G1SwRFSUzccGsP0ATHCS3VapS
         wEG97h6mHksH0YBm1juy2FdtD80cab5soVAM75ZbbX/P1Zinh9PUdszFHtpdr9cOxLfq
         wmJ0SAwhz+agxZHBnM2TrR8OR+rKOhSYZujnPKXIGlP8vux6SfvoyjSs5SGcMis65swM
  
X-Gm-Message-State: AMke39nPvlNeLbZJAC9e5+zbGX0V/uT5W83kSEsHuaku4H5eZ/nZcNEyD1gpe+Q+pp1mZA==
X-Received: by 10.200.36.104 with SMTP id d37mr3554503qtd.56.1489162773464;
        Fri, 10 Mar 2017 08:19:33 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.129.81 with SMTP id c78ls2717910iod.28.gmail; Fri, 10 Mar
 2017 08:19:30 -0800 (PST)
X-Received: by 10.36.185.16 with SMTP id w16mr3036627ite.118.1489162770867;
        Fri, 10 Mar 2017 08:19:30 -0800 (PST)
Original-Received: from mail-it0-x241.google.com (mail-it0-x241.google.com. [2607:f8b0:4001:c0b::241])
        by mx.google.com with ESMTPS id k201si2543021itk.102.2017.03.10.08.19.30
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 10 Mar 2017 08:19:30 -0800 (PST)
Received-SPF: pass (google.com: domain of mwoehlke.floss@gmail.com designates 2607:f8b0:4001:c0b::241 as permitted sender) client-ip=2607:f8b0:4001:c0b::241;
Original-Received: by mail-it0-x241.google.com with SMTP id w185so1762624ita.3
        for <std-proposals@isocpp.org>; Fri, 10 Mar 2017 08:19:30 -0800 (PST)
X-Received: by 10.36.107.202 with SMTP id v193mr2770348itc.21.1489162770479;
        Fri, 10 Mar 2017 08:19:30 -0800 (PST)
Original-Received: from [192.168.1.176] (tripoint.kitware.com. [66.194.253.20])
        by smtp.googlemail.com with ESMTPSA id l33sm4546307iod.8.2017.03.10.08.19.29
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 10 Mar 2017 08:19:29 -0800 (PST)
In-Reply-To: <6bccd7e5-82ad-4c59-9f72-f7fb6639c0ca@isocpp.org>
X-Original-Sender: mwoehlke.floss@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com;       spf=pass (google.com: domain of
 mwoehlke.floss@gmail.com designates 2607:f8b0:4001:c0b::241 as permitted
 sender) smtp.mailfrom=mwoehlke.floss@gmail.com;       dmarc=pass (p=NONE
 sp=NONE dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <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:31542
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/31542>

On 2017-03-09 17:44, 3dw4rd@verizon.net wrote:
> I think that this could devolve into endless bikeshed discussions and wha=
t=20
> constants to include.=20

  template <typename T>
  class pi_helper
  {
    static constexpr value =3D 3.14159...;

    constexpr operator T() { return value; }

    template <int numerator, int denominator>
    constexpr T times() { return numerator * value / denominator; }
  }

  template <typename T>
  inline constexpr pi_helper pi<T>;

....and as QOI, implementations can provide explicit specializations of
any of `times<N,D>()` that make sense. This way the namespace isn't
polluted by bunches of `pi_1_3` and so forth, and it's clearer what
value you are asking for.

For roots, I think something like:

  template <typename T, unsigned value>
  extern T sqrt;

....makes sense. We should specify that at least a particular set of
these must be available, but this would provide a hook where compilers
can provide an intrinsic such that any square root is available as a
constexpr. (This would also permit compilers to choose to provide them
via an intrinsic that can always compute them, but e.g. using a
variable-precision algorithm that ensures the result is always accurate
within the limits of the requested type.) We can do something similar
for logarithm constants.

I don't think we should have constants for 180/pi and pi/180; having
constexpr functions for these operations will I think lead to better code.

Otherwise, we should definitely have Euler's constant, on principle if
nothing else, but I don't think I've ever used the golden ratio or
anything involving square roots and pi. (When are those useful? When is
pi=C2=B2/6 useful?)

--=20
Matthew

--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/58C2D210.6080900%40gmail.com.

.
