220 33031 <8c168cd3-6dc2-97ab-848d-7eab8321e114@rrsd.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Robert Ramey <ramey@rrsd.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: safe integrals comparison
Date: Thu, 29 Jun 2017 12:10:53 -0700
Lines: 42
Approved: news@gmane.org
Message-ID: <8c168cd3-6dc2-97ab-848d-7eab8321e114@rrsd.com>
References: <66f9bab2-7220-4bf1-afb7-77c5efa1bac3@isocpp.org>
 <4473c388-1bc0-24b3-b1f2-fc8bfc834df3@rrsd.com>
 <23282d1f-aaaa-45a1-a1fe-2056addfe835@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"; format=flowed
X-Trace: blaine.gmane.org 1498763458 21535 195.159.176.226 (29 Jun 2017 19:10:58 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Thu, 29 Jun 2017 19:10:58 +0000 (UTC)
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0)
 Gecko/20100101 Thunderbird/52.2.1
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDG73K7L6AIRBQNB2XFAKGQEJLR6H6I@isocpp.org Thu Jun 29 21:10:54 2017
Return-path: <std-proposals+bncBDG73K7L6AIRBQNB2XFAKGQEJLR6H6I@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yb0-f197.google.com ([209.85.213.197])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDG73K7L6AIRBQNB2XFAKGQEJLR6H6I@isocpp.org>)
	id 1dQeq6-0005Ot-5z
	for gclcip-std-proposals@m.gmane.org; Thu, 29 Jun 2017 21:10:54 +0200
Original-Received: by mail-yb0-f197.google.com with SMTP id b189sf1576838yba.1
        for <gclcip-std-proposals@m.gmane.org>; Thu, 29 Jun 2017 12:10:59 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1498763459; cv=pass;
        d=google.com; s=arc-20160816;
        b=cZpOu/jAqVdhqr8B2g+QkcUAhvo3p0iH6GQHYVR9Z63FpOSKMXMoIUW4X/jbFEQnvP
         KAMVaDibRvppb3vDu5FePCU8aLdLVbpADm2qmthulhQ8zbh8UHdw//oletMEPb+gqVOp
         u7xnAxsrudp+IAs4OBnhB6MfaRRlSo9Gn4lr4rMtm7+97eeAgmzuYVtKh9hJDo4FoVML
         79LH0LaAN1tPmS7BO9d99rH2U7J4QyfeZi2WxCCyssYXNcoDILmUDfytdh3nyeYRr/La
         h4xTizsssPExXsZ/ttLodoLnwEuGBRuJ97hkJWjCR+rM6Qf2jwissIlAh16bs9YyJgMt
         UCIg==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:content-language
         :in-reply-to:mime-version:user-agent:date:message-id:from:references
         :newsgroups:to:subject:arc-authentication-results
         :arc-message-signature:dkim-signature:arc-authentication-results;
        bh=c9wVyR0Rnl3oerDPoZIXX0JUA6qe5RGOh68QzR7OiKE=;
        b=t5LGqGRN7NeyMn/YBnaOCc2pz7cANAHJuN/6hZ2oSdxTdFV2WTFdxjC9/qmBNkMMlQ
         niw/oUNMO9ZFWLKG7p9Ele4aRDkci2qIIpY/WhhAMFwcL4rQqHdS9qUmGR5Q+qSyAtHk
         cTNqF+D7L6Shsx1bv1Hxk+133RN5aWULmtBJi7b3QU9Unpf71iMBKyeeWY/IeNt0u9Bh
         83Oipf3D9Bpa6qVMQ6RQjGxL8GNrcH7RmNgt1AawSZcdgAr5ECmjmrhWKCkA+nd9P1G7
         ocqGK85hfRYui8ReWh7SnJT7jDgDnC1yHb0HSaDqxkkHkbvUMgG4gvjtUP9mTjTxz45G
         
ARC-Authentication-Results: i=2; mx.google.com;
       spf=pass (google.com: domain of ramey@rrsd.com designates 23.83.214.27 as permitted sender) smtp.mailfrom=ramey@rrsd.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=subject:to:newsgroups:references:from:message-id:date:user-agent
         :mime-version:in-reply-to:content-language:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=c9wVyR0Rnl3oerDPoZIXX0JUA6qe5RGOh68QzR7OiKE=;
        b=gVoMDRAdniCDmQ5y3DWA1Zessb41lfsG8zzyOXOjQrxjsdJGtgW1hcxz6MMD6RJ3Wk
         qdro6NPMgqEMsdEO1otFvMDoidvzBLtvdrIJf5o97BPX5BvPf/ZTpsn3GMWIkTpjLBNX
         smE2qnysMNSUEfLsMjkHbMprdVdpEaFzhRIXSZaJS4bOERAJ2CsLX7pRxfN2hrN9ryi9
         C/OWwe1xkGYcD9kQxbexMffV6ICu+epJUaPcm6azfZlrMzfgwfgO1jEzNDAIcPdZJfDC
         VEhJhSLFnEtkROFhFHT5y6UoTJ2k5JKPcWqffO8s6jFD7GJRdsifCgqwGZTJ53cZeBdB
         SNGQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:subject:to:newsgroups:references:from:message-id
         :date:user-agent:mime-version:in-reply-to:content-language
         :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=c9wVyR0Rnl3oerDPoZIXX0JUA6qe5RGOh68QzR7OiKE=;
        b=AQ8+yJBVpPF/tBCvz5B6cYdGJeq+vNghYDT2t9MmeTVk3Wu4FoOnC7WwMeoipCgrlc
         9mniu6li88IGIkwwjGexzKYd6hGYPPGdNHcw8M1Y0F+fJ3ZrE2/iQuyuwey7rMjCr1kz
         jwWKKZPaersa3ZCEcRvFbww1vgyERfmvHdOMwi9y8hSAhoFCfoSpkvxfNQ7OnV4tzIZm
         U/lx4KtrejsMSRg1Y25jHsoOVdOK1ABfibi+neU7vqJzH3rHK1zEZ0bq1Wr/EvxPRBs3
         iaJnDWHKlQ+p9wZyaSOmuSaAEQynspHreT3LhvRCtt4fQwtUzSuChYDklZPO3Kx7WPRL 
X-Gm-Message-State: AKS2vOxZSVjGmCMfP/uD4obpXRnvAclP0Bo7jHsuSLi8P1qY7DP8LcC5
	wamCvC2VlU0senLg
X-Received: by 10.129.73.23 with SMTP id w23mr11416534ywa.30.1498763459177;
        Thu, 29 Jun 2017 12:10:59 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.36.7.12 with SMTP id f12ls4769616itf.14.canary-gmail; Thu, 29
 Jun 2017 12:10:57 -0700 (PDT)
X-Received: by 10.98.217.23 with SMTP id s23mr18335533pfg.204.1498763457581;
        Thu, 29 Jun 2017 12:10:57 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1498763457; cv=none;
        d=google.com; s=arc-20160816;
        b=eID3ty4DcxWMrqqsJnPrSrirj14sXO4XyU3o6RugU0FoNBaFqd+qjWWSn+Sezo8k1R
         ZL43mEtNAOtkvlQv+9MFELPPqLuXoxv6IY5rFBBxHtNCjEQq4qURXgy5QmWQTogoL8iP
         tqTe+lgM93juG6mijYFmsptcv0JO0VW0ffH9ioX0xfaKnX8FGDS/bkjt9K5ySJEZmlKy
         qxuZDIzckezlKkOLZ+PA5Vll9AQlP1ei81XX14/tsMXU0v5WsvP5IuKvn4w6tBpkukKV
         cOtubTB77YUTVt7Ez6nJ+HgTxusXdzFXe2svn3pnPo0bH9ufAwHLIPmEYbK0bjWrrGRJ
         oVFQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=content-transfer-encoding:content-language:in-reply-to:mime-version
         :user-agent:date:message-id:from:references:newsgroups:to:subject
         :arc-authentication-results;
        bh=5kd6R2N3xgFF5AxKy/L/xSkWqInFhKlUX+1+Qv3PA9k=;
        b=EbXWkU6fFoUfaiKdBqF/3ZKhWBOiE1o2YpeJ6sxA9P6ly94JgItCrQjNmoGGSE0VFf
         gWL+Ux00Y4T+deIlRcBp5ezLpUfpVm5N3kbw6ODSbpKO6u6JlEq7owAL6OLQwpAIpb1v
         +5SIO0a9+zsimEUWCrGZB+UptW2/WlzxCVcWDBGCFDwQBtqV6G0DJBPZ/2qYJ7fMAJaP
         yuQFk3T2FqZAKzT7bhr1D46cdkWH66+ZtRN5QwhLznu3TNC/cWEJC+t4jq72t39rwBbN
         j63EIIkE8MK9MbbA9TTA98Mhshdg6WshpWqZuND4Wtzy0Gd++5+aIz/rvycMwzfR0j+o
         Seqg==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=pass (google.com: domain of ramey@rrsd.com designates 23.83.214.27 as permitted sender) smtp.mailfrom=ramey@rrsd.com
Original-Received: from butterfly.maple.relay.mailchannels.net (butterfly.maple.relay.mailchannels.net. [23.83.214.27])
        by mx.google.com with ESMTPS id k16si4585293pli.350.2017.06.29.12.10.57
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Thu, 29 Jun 2017 12:10:57 -0700 (PDT)
Received-SPF: pass (google.com: domain of ramey@rrsd.com designates 23.83.214.27 as permitted sender) client-ip=23.83.214.27;
X-Sender-Id: wwwh2|x-authuser|ramey@rrsd.com
Original-Received: from relay.mailchannels.net (localhost [127.0.0.1])
	by relay.mailchannels.net (Postfix) with ESMTP id 759D43689BC
	for <std-proposals@isocpp.org>; Thu, 29 Jun 2017 19:10:56 +0000 (UTC)
Original-Received: from clippers.accountservergroup.com (unknown [100.96.129.109])
	(Authenticated sender: wwwh2)
	by relay.mailchannels.net (Postfix) with ESMTPA id DEFB6368AA2
	for <std-proposals@isocpp.org>; Thu, 29 Jun 2017 19:10:55 +0000 (UTC)
X-Sender-Id: wwwh2|x-authuser|ramey@rrsd.com
Original-Received: from clippers.accountservergroup.com ([UNAVAILABLE].
 [172.20.55.158])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA)
	by 0.0.0.0:2500 (trex/5.9.7);
	Thu, 29 Jun 2017 19:10:56 +0000
X-MC-Relay: Neutral
X-MailChannels-SenderId: wwwh2|x-authuser|ramey@rrsd.com
X-MailChannels-Auth-Id: wwwh2
X-Abaft-Left: 391b28d67b4d69c3_1498763456091_3388971698
X-MC-Loop-Signature: 1498763456091:1434664144
X-MC-Ingress-Time: 1498763456090
Original-Received: from ip68-6-126-194.sb.sd.cox.net ([68.6.126.194]:53424 helo=Roberts-Mac-mini.local)
	by clippers.accountservergroup.com with esmtpsa (TLSv1:DHE-RSA-AES128-SHA:128)
	(Exim 4.87)
	(envelope-from <ramey@rrsd.com>)
	id 1dQeq7-0003Ed-41
	for std-proposals@isocpp.org; Thu, 29 Jun 2017 12:10:55 -0700
Original-Newsgroups: gmane.comp.lang.c++.isocpp.proposals
In-Reply-To: <23282d1f-aaaa-45a1-a1fe-2056addfe835@isocpp.org>
Content-Language: en-US
X-AuthUser: ramey@rrsd.com
X-Original-Sender: ramey@rrsd.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of ramey@rrsd.com designates 23.83.214.27 as permitted sender) smtp.mailfrom=ramey@rrsd.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:33031
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/33031>

On 6/29/17 10:00 AM, federico.kircheis@gmail.com wrote:
> Hi,
> 
> I was just reading your implementation a couple of days ago, it's pretty 
> complicated with all those templated types ;-)
> 
> (To be honest I found out of your library in March, when I listened to 
> the podcast episode, but then forgot to give a look to your implementation)
> 
> I noticed you were not comparing the precision of the types like I did, 
> I guess I missed that I could use "make_unsigned".
> I think the only difference is that I'm converting both types to the one 
> with the biggest range, and accounting that it may be the signed one. I 
> guess it may use less stack space, but I also think that it will never 
> make some difference.
> 
> I guess your implementation for comparing integral types and mine are 
> completely interchangeable.
> 

This is unnecessary.  C/C++ type promotion rules do exactly this so it's 
redundant to do this in your code.  The only problem is that C++ 
promotion rules sometime change signed to
unsigned and change the value.
The attached code keeps this from happening which is why it works.

Note that my code guarantees zero runtime overhead in space or time. In 
fact it could even make one's program faster as in the case:

unsigned int x;
signed int y = -1

y < x // can be eliminated as it will always be true.

Robert Ramey

-- 
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 email 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/8c168cd3-6dc2-97ab-848d-7eab8321e114%40rrsd.com.

.
