Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

In the long run, every program becomes rococco, and then rubble. -- Alan Perlis


devel / comp.arch / Compact representation for common integer constants

SubjectAuthor
* Compact representation for common integer constantsJohnG
+* Re: Compact representation for common integer constantsIvan Godard
|+- Re: Compact representation for common integer constantsDavid Brown
|`* Re: Compact representation for common integer constantsJohnG
| `* Re: Compact representation for common integer constantsBGB
|  `* Re: Compact representation for common integer constantsMitchAlsup
|   `* Re: Compact representation for common integer constantsBGB
|    `* Re: Compact representation for common integer constantsThomas Koenig
|     +- Re: Compact representation for common integer constantsMitchAlsup
|     `* Re: Compact representation for common integer constantsBGB
|      `* Re: Compact representation for common integer constantsMitchAlsup
|       `* Re: Compact representation for common integer constantsIvan Godard
|        +- Re: Compact representation for common integer constantsMarcus
|        +* Re: Compact representation for common integer constantsBGB
|        |`* Re: Compact representation for common integer constantsMitchAlsup
|        | +* Clamping. was: Compact representation for common integer constantsIvan Godard
|        | |+* Re: Clamping. was: Compact representation for common integer constantsMitchAlsup
|        | ||`* Re: Clamping. was: Compact representation for common integerIvan Godard
|        | || `- Re: Clamping. was: Compact representation for common integer constantsMitchAlsup
|        | |`* Re: Clamping. was: Compact representation for common integerBGB
|        | | `* Re: Clamping. was: Compact representation for common integerIvan Godard
|        | |  `- Re: Clamping. was: Compact representation for common integer constantsMitchAlsup
|        | +* Re: Compact representation for common integer constantsMarcus
|        | |`* Re: Compact representation for common integer constantsMitchAlsup
|        | | `* Re: Compact representation for common integer constantsDavid Brown
|        | |  `* Re: Compact representation for common integer constantsMitchAlsup
|        | |   +- Re: Compact representation for common integer constantsThomas Koenig
|        | |   `* Re: Compact representation for common integer constantsDavid Brown
|        | |    `- Re: Compact representation for common integer constantsMitchAlsup
|        | `* Re: Compact representation for common integer constantsThomas Koenig
|        |  +- Re: Compact representation for common integer constantsAnton Ertl
|        |  `* Re: Compact representation for common integer constantsMitchAlsup
|        |   `* Re: Compact representation for common integer constantsThomas Koenig
|        |    +* Re: Compact representation for common integer constantsAnton Ertl
|        |    |`* Re: Compact representation for common integer constantsBrian G. Lucas
|        |    | +* Re: Compact representation for common integer constantsThomas Koenig
|        |    | |`- Re: Compact representation for common integer constantsBrian G. Lucas
|        |    | +- Re: Compact representation for common integer constantsStefan Monnier
|        |    | `* Re: Compact representation for common integer constantsAnton Ertl
|        |    |  `* Re: Compact representation for common integer constantsThomas Koenig
|        |    |   +* Re: Compact representation for common integer constantsAnton Ertl
|        |    |   |`* Re: Compact representation for common integer constantsThomas Koenig
|        |    |   | `- Re: Compact representation for common integer constantsAnton Ertl
|        |    |   `* Re: Compact representation for common integer constantsTerje Mathisen
|        |    |    `- Re: Compact representation for common integer constantsAnton Ertl
|        |    `* Re: Compact representation for common integer constantsMitchAlsup
|        |     `* Re: Compact representation for common integer constantsThomas Koenig
|        |      `* Re: Compact representation for common integer constantsBrian G. Lucas
|        |       `* Re: Compact representation for common integer constantsThomas Koenig
|        |        +* Re: Compact representation for common integer constantsMitchAlsup
|        |        |`- Re: Compact representation for common integer constantsThomas Koenig
|        |        +* Re: Compact representation for common integer constantsAnton Ertl
|        |        |+* Re: Compact representation for common integer constantsThomas Koenig
|        |        ||+* Re: Compact representation for common integer constantsMitchAlsup
|        |        |||`* Re: Compact representation for common integer constantsThomas Koenig
|        |        ||| `- Re: Compact representation for common integer constantsMitchAlsup
|        |        ||`* Re: Compact representation for common integer constantsAnton Ertl
|        |        || +* Re: Compact representation for common integer constantsMitchAlsup
|        |        || |+* Re: Compact representation for common integer constantsEricP
|        |        || ||+* Re: Compact representation for common integer constantsThomas Koenig
|        |        || |||+- Re: Compact representation for common integer constantsMitchAlsup
|        |        || |||+* Re: Compact representation for common integer constantsEricP
|        |        || ||||`* Re: Compact representation for common integer constantsTerje Mathisen
|        |        || |||| `* Re: Compact representation for common integer constantsDavid Brown
|        |        || ||||  `* Re: Compact representation for common integer constantsTerje Mathisen
|        |        || ||||   `* Re: Compact representation for common integer constantsDavid Brown
|        |        || ||||    `- Re: Compact representation for common integer constantsTerje Mathisen
|        |        || |||`* Re: Compact representation for common integer constantsStephen Fuld
|        |        || ||| `* Re: Compact representation for common integer constantsMitchAlsup
|        |        || |||  +- Re: Compact representation for common integer constantsStephen Fuld
|        |        || |||  `* Re: Compact representation for common integer constantsBill Findlay
|        |        || |||   `* Re: Compact representation for common integer constantsMitchAlsup
|        |        || |||    `- Re: Compact representation for common integer constantsBill Findlay
|        |        || ||+* Re: Compact representation for common integer constantsThomas Koenig
|        |        || |||+* Re: Compact representation for common integer constantsStephen Fuld
|        |        || ||||`- Re: Compact representation for common integer constantsThomas Koenig
|        |        || |||`- Re: Compact representation for common integer constantsEricP
|        |        || ||`* Re: Compact representation for common integer constantsStephen Fuld
|        |        || || +* Re: Compact representation for common integer constantsNiklas Holsti
|        |        || || |`* Re: Compact representation for common integer constantsStephen Fuld
|        |        || || | `* Re: Compact representation for common integer constantsMitchAlsup
|        |        || || |  `* Re: Compact representation for common integer constantsStephen Fuld
|        |        || || |   `* Re: Compact representation for common integer constantsEricP
|        |        || || |    +* Re: Compact representation for common integer constantsMitchAlsup
|        |        || || |    |`* Re: Compact representation for common integer constantsEricP
|        |        || || |    | `* Re: Compact representation for common integer constantsMitchAlsup
|        |        || || |    |  `* Re: Compact representation for common integer constantsThomas Koenig
|        |        || || |    |   +- Re: Compact representation for common integer constantsMitchAlsup
|        |        || || |    |   `* Re: Compact representation for common integer constantsTerje Mathisen
|        |        || || |    |    `* Re: Compact representation for common integer constantsMitchAlsup
|        |        || || |    |     +- Re: Compact representation for common integer constantsTerje Mathisen
|        |        || || |    |     `* Re: Compact representation for common integer constantsMitchAlsup
|        |        || || |    |      `- Re: Compact representation for common integer constantsTerje Mathisen
|        |        || || |    `* Re: Compact representation for common integer constantsStephen Fuld
|        |        || || |     `* Re: Compact representation for common integer constantsMitchAlsup
|        |        || || |      +- Re: Compact representation for common integer constantsBill Findlay
|        |        || || |      +* Re: Compact representation for common integer constantsThomas Koenig
|        |        || || |      |+* Re: Compact representation for common integer constantsAnton Ertl
|        |        || || |      ||`* Re: Compact representation for common integer constantsThomas Koenig
|        |        || || |      || `- Re: Compact representation for common integer constantsAnton Ertl
|        |        || || |      |`* Re: Compact representation for common integer constantsMitchAlsup
|        |        || || |      +* Re: Compact representation for common integer constantsTerje Mathisen
|        |        || || |      `* Re: Compact representation for common integer constantsStephen Fuld
|        |        || || `* Re: Compact representation for common integer constantsEricP
|        |        || |`- Re: Compact representation for common integer constantsAnton Ertl
|        |        || `* Re: Compact representation for common integer constantsThomas Koenig
|        |        |`* Re: Compact representation for common integer constantsMitchAlsup
|        |        `* Re: Compact representation for common integer constantsBrian G. Lucas
|        `* Re: Compact representation for common integer constantsQuadibloc
+* Re: Compact representation for common integer constantsBGB
`* Re: Compact representation for common integer constantsJohn Levine

Pages:123456789101112131415
Re: Compact representation for common integer constants

<sahodq$s36$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17908&group=comp.arch#17908

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Fri, 18 Jun 2021 11:18:50 +0200
Organization: A noiseless patient Spider
Lines: 81
Message-ID: <sahodq$s36$1@dont-email.me>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<s7u338$cek$1@newsreader4.netcologne.de> <s7v6j1$qns$1@dont-email.me>
<s7vn9p$bfu$1@newsreader4.netcologne.de>
<2021May18.183723@mips.complang.tuwien.ac.at>
<s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at>
<s83h0k$jaj$1@newsreader4.netcologne.de>
<2021May19.214832@mips.complang.tuwien.ac.at> <s8414d$okc$1@dont-email.me>
<2021May20.001137@mips.complang.tuwien.ac.at> <s846ou$s25$1@dont-email.me>
<35c1d9c9-d12a-4812-bcac-07979e0fcaccn@googlegroups.com>
<s84b0a$lht$1@dont-email.me>
<5c8aa7d4-ae7d-465e-bcb4-230ee64b2bfbn@googlegroups.com>
<s8522o$tol$1@dont-email.me> <s85i3s$929$1@dont-email.me>
<s85j8h$hce$1@dont-email.me> <s869c0$nvg$1@dont-email.me>
<s86des$g1a$1@newsreader4.netcologne.de> <86zgvobdd4.fsf@linuxsc.com>
<4e106f2b-31a7-42ff-9523-cb396cbb80fdn@googlegroups.com>
<sag7gi$9ur$1@dont-email.me>
<6d654e64-9393-4b58-9954-2b83e88d78e4n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 18 Jun 2021 09:18:50 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="999e9651e969867b2f79d9d5e2984164";
logging-data="28774"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/90YgSu/3AA91ZJwcnkuLPDeJ9SMZTk/Y="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
Thunderbird/68.10.0
Cancel-Lock: sha1:I/Udo/TsLOEtiZILScRqLP3dOnE=
In-Reply-To: <6d654e64-9393-4b58-9954-2b83e88d78e4n@googlegroups.com>
Content-Language: en-GB
 by: David Brown - Fri, 18 Jun 2021 09:18 UTC

On 18/06/2021 01:46, MitchAlsup wrote:
> On Thursday, June 17, 2021 at 2:24:05 PM UTC-5, David Brown wrote:
>> On 17/06/2021 20:22, MitchAlsup wrote:
>>> On Thursday, June 17, 2021 at 12:38:33 PM UTC-5, Tim Rentsch wrote:
>>>> Thomas Koenig <tko...@netcologne.de> writes:
>>>>
>>>>> Marcus <m.de...@this.bitsnbites.eu> schrieb:
>>>>>
>>>>>> A common source of
>>>>>> errors is implicit type conversions in C, for instance.
>>>>>
>>>>> The integral promotions from signed to unsigned of the
>>>>> same size are the worst.
>>>>>
>>>>> int a = -3;
>>>>> unsigned int b = 2;
>>>>> if (a > b)
>>>>> printf ("You expected this to happen, right?\n");
>>>>
>>>> The C standard uses the term "integer promotions" rather than
>>>> "integral promotions", but in any case what is going on here
>>>> falls under the heading of "usual arithmetic conversions",
>>>> not "integer promotions". (Integer promotions are things
>>>> like turning a 'short' into an 'int'.)
>>> <
>>> What causes the supersize is that programmers are not taught
>>> unsigned has a lower surprise factor than integer.
> <
>> unsigned types in C don't have "lower surprise factor" than signed
>> types. They have slightly /different/ surprise factors. If you want to
>> program in C, you should learn how the signed and unsigned integer types
>> work, alone and together, and code accordingly.
> <
> While they do have different surprise factors, the unsigned variety is lower
> because when signed an unsigned are mixed, the unsigned takes precedent.

That is only the case for types of size "int" and bigger. Unsigned
types smaller than "int" promote to /signed/ int. I am not a fan of the
way this works in C and C++, but I think it is a good idea to know the
rules rather than live by generalisations that are not always correct.

> <
> And as I have stated many times: the only time I EVER use a signed type
> is when at some point it has to contain a negative value. Then, again, if
> it always contains a negative value (never positive) I STILL use unsigned
> and subtract rather than add.

And the only time you use a screwdriver is if hammering the screw in fails?

Signed and unsigned types have their differences, advantages and
disadvantages. If you want to program in C or C++ (or other languages
with the distinction), it pays to learn how the types work, use the
appropriate type for the task, and be careful when mixing them. For
some tasks, unsigned types will naturally be more common - but going out
of your way to avoid signed types because /you/ find them "surprising"
will surprise anyone else looking at the code.

> <
> About the only time I use a signed integer type is when interfacing with a
> library routine which has parameters or result defined as signed.
>>
>> There is a lot of value in using good static warning tools - enabling
>> "-Wsign-compare -Wsign-conversion" in gcc will give you warnings on
>> these things if you don't use explicit casts. You choose your own
>> balance between reduced risk of errors at the cost of additional effort
>> (such as casts) when you need to mixed signedness and know it is safe.
>>
>> One problem with a lot of C teaching is that it usually fails to teach
>> about tools that can make programming easier and safer. Another is that
>> if they teach the details of integer types at all, they do so with
>> invalid and unhelpful generalisations like "unsigned types are better
>> because overflow is defined and they are therefore safe".
>>> <
>>> But consider::
>>> <
>>> int64_t a = -3;
>>> uint64_t b = 0xfffffffffffffffd;
>>> if( a == b )
>>> printf ("You expected this to happen, right?\n");
>>>

Re: Compact representation for common integer constants

<d7ab87d1-4b8e-4d9b-b71e-bed88cdaed04n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17922&group=comp.arch#17922

  copy link   Newsgroups: comp.arch
X-Received: by 2002:ac8:7c9c:: with SMTP id y28mr11140433qtv.192.1624032352991;
Fri, 18 Jun 2021 09:05:52 -0700 (PDT)
X-Received: by 2002:a05:6808:919:: with SMTP id w25mr14708101oih.30.1624032352711;
Fri, 18 Jun 2021 09:05:52 -0700 (PDT)
Path: i2pn2.org!i2pn.org!paganini.bofh.team!usenet.pasdenom.info!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Fri, 18 Jun 2021 09:05:52 -0700 (PDT)
In-Reply-To: <saheha$ie$2@newsreader4.netcologne.de>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:a9d3:561c:9b34:f434;
posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:a9d3:561c:9b34:f434
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<s7u338$cek$1@newsreader4.netcologne.de> <s7v6j1$qns$1@dont-email.me>
<s7vn9p$bfu$1@newsreader4.netcologne.de> <2021May18.183723@mips.complang.tuwien.ac.at>
<s80rjn$1ci$2@newsreader4.netcologne.de> <2021May19.124934@mips.complang.tuwien.ac.at>
<s83h0k$jaj$1@newsreader4.netcologne.de> <2021May19.214832@mips.complang.tuwien.ac.at>
<s8414d$okc$1@dont-email.me> <2021May20.001137@mips.complang.tuwien.ac.at>
<s846ou$s25$1@dont-email.me> <35c1d9c9-d12a-4812-bcac-07979e0fcaccn@googlegroups.com>
<s84b0a$lht$1@dont-email.me> <5c8aa7d4-ae7d-465e-bcb4-230ee64b2bfbn@googlegroups.com>
<s8522o$tol$1@dont-email.me> <s85i3s$929$1@dont-email.me> <s85j8h$hce$1@dont-email.me>
<s869c0$nvg$1@dont-email.me> <s86des$g1a$1@newsreader4.netcologne.de>
<86zgvobdd4.fsf@linuxsc.com> <4e106f2b-31a7-42ff-9523-cb396cbb80fdn@googlegroups.com>
<sag7gi$9ur$1@dont-email.me> <sag8p5$il8$1@dont-email.me> <saheha$ie$2@newsreader4.netcologne.de>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d7ab87d1-4b8e-4d9b-b71e-bed88cdaed04n@googlegroups.com>
Subject: Re: Compact representation for common integer constants
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Fri, 18 Jun 2021 16:05:52 +0000
Content-Type: text/plain; charset="UTF-8"
 by: MitchAlsup - Fri, 18 Jun 2021 16:05 UTC

On Friday, June 18, 2021 at 1:30:05 AM UTC-5, Thomas Koenig wrote:
> Ivan Godard <iv...@millcomputing.com> schrieb:
> > The warnings are necessary, but still annoying:
> > for (int i = 0; i < arr.size(); i++)
> Why chose arr.size() as unsigned?
<
Because it never can deliver a negative number !
>
> As long as the types are long enough that overflow is not
> an issue (as should be the case with 64-bit types), signed
> has far nicer properties.

Re: Compact representation for common integer constants

<saii8n$p5t$1@newsreader4.netcologne.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17928&group=comp.arch#17928

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd7-6322-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoe...@netcologne.de (Thomas Koenig)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Fri, 18 Jun 2021 16:39:51 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <saii8n$p5t$1@newsreader4.netcologne.de>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<s7v6j1$qns$1@dont-email.me> <s7vn9p$bfu$1@newsreader4.netcologne.de>
<2021May18.183723@mips.complang.tuwien.ac.at>
<s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at>
<s83h0k$jaj$1@newsreader4.netcologne.de>
<2021May19.214832@mips.complang.tuwien.ac.at> <s8414d$okc$1@dont-email.me>
<2021May20.001137@mips.complang.tuwien.ac.at> <s846ou$s25$1@dont-email.me>
<35c1d9c9-d12a-4812-bcac-07979e0fcaccn@googlegroups.com>
<s84b0a$lht$1@dont-email.me>
<5c8aa7d4-ae7d-465e-bcb4-230ee64b2bfbn@googlegroups.com>
<s8522o$tol$1@dont-email.me> <s85i3s$929$1@dont-email.me>
<s85j8h$hce$1@dont-email.me> <s869c0$nvg$1@dont-email.me>
<s86des$g1a$1@newsreader4.netcologne.de> <86zgvobdd4.fsf@linuxsc.com>
<4e106f2b-31a7-42ff-9523-cb396cbb80fdn@googlegroups.com>
<sag7gi$9ur$1@dont-email.me> <sag8p5$il8$1@dont-email.me>
<saheha$ie$2@newsreader4.netcologne.de> <sahnmn$n6t$1@dont-email.me>
Injection-Date: Fri, 18 Jun 2021 16:39:51 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd7-6322-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd7:6322:0:7285:c2ff:fe6c:992d";
logging-data="25789"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Fri, 18 Jun 2021 16:39 UTC

David Brown <david.brown@hesbynett.no> schrieb:

> I disagree somewhat on saying "signed has far nicer properties", just as
> I disagree with people who say "unsigned" are "safer" or better defined.

The main reason why I try to use unsigned only where possible is loops.

With signed integers, it is easy to write a loop from a to b
which gets executed zero times if a > b, as in

for (i=a ; i<b, i++)

For unsigned... hm.

Re: Compact representation for common integer constants

<saija3$ue5$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17931&group=comp.arch#17931

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Fri, 18 Jun 2021 18:57:38 +0200
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <saija3$ue5$1@dont-email.me>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<s7vn9p$bfu$1@newsreader4.netcologne.de>
<2021May18.183723@mips.complang.tuwien.ac.at>
<s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at>
<s83h0k$jaj$1@newsreader4.netcologne.de>
<2021May19.214832@mips.complang.tuwien.ac.at> <s8414d$okc$1@dont-email.me>
<2021May20.001137@mips.complang.tuwien.ac.at> <s846ou$s25$1@dont-email.me>
<35c1d9c9-d12a-4812-bcac-07979e0fcaccn@googlegroups.com>
<s84b0a$lht$1@dont-email.me>
<5c8aa7d4-ae7d-465e-bcb4-230ee64b2bfbn@googlegroups.com>
<s8522o$tol$1@dont-email.me> <s85i3s$929$1@dont-email.me>
<s85j8h$hce$1@dont-email.me> <s869c0$nvg$1@dont-email.me>
<s86des$g1a$1@newsreader4.netcologne.de> <86zgvobdd4.fsf@linuxsc.com>
<4e106f2b-31a7-42ff-9523-cb396cbb80fdn@googlegroups.com>
<sag7gi$9ur$1@dont-email.me> <sag8p5$il8$1@dont-email.me>
<saheha$ie$2@newsreader4.netcologne.de> <sahnmn$n6t$1@dont-email.me>
<saii8n$p5t$1@newsreader4.netcologne.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 18 Jun 2021 16:57:39 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="8e329dc0dd19c902c331f441ab4bdb58";
logging-data="31173"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18e6Ym90hWdvc+Y+E55lB07WPJzEEQkWSY="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
Thunderbird/68.10.0
Cancel-Lock: sha1:oH3HXdejbZUCrgxQ9wVsKwGyBkY=
In-Reply-To: <saii8n$p5t$1@newsreader4.netcologne.de>
Content-Language: en-GB
 by: David Brown - Fri, 18 Jun 2021 16:57 UTC

On 18/06/2021 18:39, Thomas Koenig wrote:
> David Brown <david.brown@hesbynett.no> schrieb:
>
>> I disagree somewhat on saying "signed has far nicer properties", just as
>> I disagree with people who say "unsigned" are "safer" or better defined.
>
> The main reason why I try to use unsigned only where possible is loops.
>
> With signed integers, it is easy to write a loop from a to b
> which gets executed zero times if a > b, as in
>
> for (i=a ; i<b, i++)
>
> For unsigned... hm.
>

I prefer to know what "a" and "b" are before writing the loop, and
whether (a > b) might hold.

If you write your code assuming (a <= b), but in fact (a > b), then it
doesn't matter if you use signed or unsigned types - your code is
broken. And if the assumption /does/ hold, then it doesn't matter
whether your types are signed or unsigned either.

In general, if it actually matters whether you have signed or unsigned
types (assuming they cover the ranges you need), then your code is
probably wrong. Unsigned overflow is almost almost an error regardless
of how well defined it is in the language.

Re: Compact representation for common integer constants

<saj16o$4ij$1@newsreader4.netcologne.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17935&group=comp.arch#17935

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd7-6322-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoe...@netcologne.de (Thomas Koenig)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Fri, 18 Jun 2021 20:54:48 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <saj16o$4ij$1@newsreader4.netcologne.de>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<2021May18.183723@mips.complang.tuwien.ac.at>
<s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at>
<s83h0k$jaj$1@newsreader4.netcologne.de>
<2021May19.214832@mips.complang.tuwien.ac.at> <s8414d$okc$1@dont-email.me>
<2021May20.001137@mips.complang.tuwien.ac.at> <s846ou$s25$1@dont-email.me>
<35c1d9c9-d12a-4812-bcac-07979e0fcaccn@googlegroups.com>
<s84b0a$lht$1@dont-email.me>
<5c8aa7d4-ae7d-465e-bcb4-230ee64b2bfbn@googlegroups.com>
<s8522o$tol$1@dont-email.me> <s85i3s$929$1@dont-email.me>
<s85j8h$hce$1@dont-email.me> <s869c0$nvg$1@dont-email.me>
<s86des$g1a$1@newsreader4.netcologne.de> <86zgvobdd4.fsf@linuxsc.com>
<4e106f2b-31a7-42ff-9523-cb396cbb80fdn@googlegroups.com>
<sag7gi$9ur$1@dont-email.me> <sag8p5$il8$1@dont-email.me>
<saheha$ie$2@newsreader4.netcologne.de> <sahnmn$n6t$1@dont-email.me>
<saii8n$p5t$1@newsreader4.netcologne.de> <saija3$ue5$1@dont-email.me>
Injection-Date: Fri, 18 Jun 2021 20:54:48 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd7-6322-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd7:6322:0:7285:c2ff:fe6c:992d";
logging-data="4691"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Fri, 18 Jun 2021 20:54 UTC

David Brown <david.brown@hesbynett.no> schrieb:
> On 18/06/2021 18:39, Thomas Koenig wrote:
>> David Brown <david.brown@hesbynett.no> schrieb:
>>
>>> I disagree somewhat on saying "signed has far nicer properties", just as
>>> I disagree with people who say "unsigned" are "safer" or better defined.
>>
>> The main reason why I try to use unsigned only where possible is loops.
>>
>> With signed integers, it is easy to write a loop from a to b
>> which gets executed zero times if a > b, as in
>>
>> for (i=a ; i<b, i++)
>>
>> For unsigned... hm.
>>
>
> I prefer to know what "a" and "b" are before writing the loop, and
> whether (a > b) might hold.
>
> If you write your code assuming (a <= b), but in fact (a > b), then it
> doesn't matter if you use signed or unsigned types - your code is
> broken. And if the assumption /does/ hold, then it doesn't matter
> whether your types are signed or unsigned either.

I have use, from time to time, for arrays with negative offsets
(I guess Fortran spoiled me there). Looping over such an
array with an unsigned index would be... interesting.

The other thing that I like are zero-sized arrays which take
no special handling, they just work.

Again, hard to do with unsigned integers.

That's what I like about potential zero-trip loops with signed
types - they get this right. Fortran had this since F77,
C earlier with its test in the for loop before execution as well.
I'd have to look up the earlier definition of Algol etc to see
how far this goes back.

"Do nothing it there is nothing to do" seems like a pretty good
paradigm to me, and that is just so much harder with unsigned
integers.

How would an unsigned loop looping from 0xff...ff to 1 look like?

They have their place - sometimes you want modulo 2^n arithmetic,
and sometimes 0 - 1 should really be 2^n-1, but not always.

Re: Compact representation for common integer constants

<saj2ug$qon$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17936&group=comp.arch#17936

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: iva...@millcomputing.com (Ivan Godard)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Fri, 18 Jun 2021 14:24:31 -0700
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <saj2ug$qon$1@dont-email.me>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at>
<s83h0k$jaj$1@newsreader4.netcologne.de>
<2021May19.214832@mips.complang.tuwien.ac.at> <s8414d$okc$1@dont-email.me>
<2021May20.001137@mips.complang.tuwien.ac.at> <s846ou$s25$1@dont-email.me>
<35c1d9c9-d12a-4812-bcac-07979e0fcaccn@googlegroups.com>
<s84b0a$lht$1@dont-email.me>
<5c8aa7d4-ae7d-465e-bcb4-230ee64b2bfbn@googlegroups.com>
<s8522o$tol$1@dont-email.me> <s85i3s$929$1@dont-email.me>
<s85j8h$hce$1@dont-email.me> <s869c0$nvg$1@dont-email.me>
<s86des$g1a$1@newsreader4.netcologne.de> <86zgvobdd4.fsf@linuxsc.com>
<4e106f2b-31a7-42ff-9523-cb396cbb80fdn@googlegroups.com>
<sag7gi$9ur$1@dont-email.me> <sag8p5$il8$1@dont-email.me>
<saheha$ie$2@newsreader4.netcologne.de> <sahnmn$n6t$1@dont-email.me>
<saii8n$p5t$1@newsreader4.netcologne.de> <saija3$ue5$1@dont-email.me>
<saj16o$4ij$1@newsreader4.netcologne.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 18 Jun 2021 21:24:32 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="73cdb180e409d82131c04e022f89b7f7";
logging-data="27415"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18jtqL8juo/O2YnvBBHHSxv"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:M9YW1LQjAUpQczDeEv7L54ZkuFI=
In-Reply-To: <saj16o$4ij$1@newsreader4.netcologne.de>
Content-Language: en-US
 by: Ivan Godard - Fri, 18 Jun 2021 21:24 UTC

On 6/18/2021 1:54 PM, Thomas Koenig wrote:
> David Brown <david.brown@hesbynett.no> schrieb:
>> On 18/06/2021 18:39, Thomas Koenig wrote:
>>> David Brown <david.brown@hesbynett.no> schrieb:
>>>
>>>> I disagree somewhat on saying "signed has far nicer properties", just as
>>>> I disagree with people who say "unsigned" are "safer" or better defined.
>>>
>>> The main reason why I try to use unsigned only where possible is loops.
>>>
>>> With signed integers, it is easy to write a loop from a to b
>>> which gets executed zero times if a > b, as in
>>>
>>> for (i=a ; i<b, i++)
>>>
>>> For unsigned... hm.
>>>
>>
>> I prefer to know what "a" and "b" are before writing the loop, and
>> whether (a > b) might hold.
>>
>> If you write your code assuming (a <= b), but in fact (a > b), then it
>> doesn't matter if you use signed or unsigned types - your code is
>> broken. And if the assumption /does/ hold, then it doesn't matter
>> whether your types are signed or unsigned either.
>
> I have use, from time to time, for arrays with negative offsets
> (I guess Fortran spoiled me there). Looping over such an
> array with an unsigned index would be... interesting.
>
> The other thing that I like are zero-sized arrays which take
> no special handling, they just work.
>
> Again, hard to do with unsigned integers.
>
> That's what I like about potential zero-trip loops with signed
> types - they get this right. Fortran had this since F77,
> C earlier with its test in the for loop before execution as well.
> I'd have to look up the earlier definition of Algol etc to see
> how far this goes back.
>
> "Do nothing it there is nothing to do" seems like a pretty good
> paradigm to me, and that is just so much harder with unsigned
> integers.
>
> How would an unsigned loop looping from 0xff...ff to 1 look like?
>
> They have their place - sometimes you want modulo 2^n arithmetic,
> and sometimes 0 - 1 should really be 2^n-1, but not always.
>

An array with negative indices wouldn't use size() as in my example;
you'd need
someType arr[-3..17];
for (int i = arr.lwb(), i <= arr.upb(), ++i)

Re: Compact representation for common integer constants

<sao3gk$vdf$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17984&group=comp.arch#17984

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!udcs8n8gSpKJzYN2P2E9tQ.user.gioia.aioe.org.POSTED!not-for-mail
From: terje.ma...@tmsw.no (Terje Mathisen)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Sun, 20 Jun 2021 21:04:53 +0200
Organization: Aioe.org NNTP Server
Lines: 68
Message-ID: <sao3gk$vdf$1@gioia.aioe.org>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at>
<s83h0k$jaj$1@newsreader4.netcologne.de>
<2021May19.214832@mips.complang.tuwien.ac.at> <s8414d$okc$1@dont-email.me>
<2021May20.001137@mips.complang.tuwien.ac.at> <s846ou$s25$1@dont-email.me>
<35c1d9c9-d12a-4812-bcac-07979e0fcaccn@googlegroups.com>
<s84b0a$lht$1@dont-email.me>
<5c8aa7d4-ae7d-465e-bcb4-230ee64b2bfbn@googlegroups.com>
<s8522o$tol$1@dont-email.me> <s85i3s$929$1@dont-email.me>
<s85j8h$hce$1@dont-email.me> <s869c0$nvg$1@dont-email.me>
<s86des$g1a$1@newsreader4.netcologne.de> <86zgvobdd4.fsf@linuxsc.com>
<4e106f2b-31a7-42ff-9523-cb396cbb80fdn@googlegroups.com>
<sag7gi$9ur$1@dont-email.me> <sag8p5$il8$1@dont-email.me>
<saheha$ie$2@newsreader4.netcologne.de> <sahnmn$n6t$1@dont-email.me>
<saii8n$p5t$1@newsreader4.netcologne.de> <saija3$ue5$1@dont-email.me>
<saj16o$4ij$1@newsreader4.netcologne.de>
NNTP-Posting-Host: udcs8n8gSpKJzYN2P2E9tQ.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101
Firefox/60.0 SeaMonkey/2.53.7.1
X-Notice: Filtered by postfilter v. 0.9.2
 by: Terje Mathisen - Sun, 20 Jun 2021 19:04 UTC

Thomas Koenig wrote:
> David Brown <david.brown@hesbynett.no> schrieb:
>> On 18/06/2021 18:39, Thomas Koenig wrote:
>>> David Brown <david.brown@hesbynett.no> schrieb:
>>>
>>>> I disagree somewhat on saying "signed has far nicer properties", just as
>>>> I disagree with people who say "unsigned" are "safer" or better defined.
>>>
>>> The main reason why I try to use unsigned only where possible is loops.
>>>
>>> With signed integers, it is easy to write a loop from a to b
>>> which gets executed zero times if a > b, as in
>>>
>>> for (i=a ; i<b, i++)
>>>
>>> For unsigned... hm.
>>>
>>
>> I prefer to know what "a" and "b" are before writing the loop, and
>> whether (a > b) might hold.
>>
>> If you write your code assuming (a <= b), but in fact (a > b), then it
>> doesn't matter if you use signed or unsigned types - your code is
>> broken. And if the assumption /does/ hold, then it doesn't matter
>> whether your types are signed or unsigned either.
>
> I have use, from time to time, for arrays with negative offsets
> (I guess Fortran spoiled me there). Looping over such an
> array with an unsigned index would be... interesting.
>
> The other thing that I like are zero-sized arrays which take
> no special handling, they just work.
>
> Again, hard to do with unsigned integers.

for (size_t i = 0; i < arr.size; i++) {}

With arr.size == 0 all compilers will give you zero iterations of the
loop, what is the issue?

The only slightly complicated situation with unsigned is when I need to
count down to zero, i.e. do something to arr[n-1], arr[n-2],...arr[1],
arr[0.

Here it is easy but wrong to write the natural¨

for (size_t i = arr.size-1; i >= 0; i--) { do something with arr[i] }

since a size_t can never become negative so this is an infinite loop.

The alternatives are slighly more complicated:

for (size_t i = arr.size; i > 0; i--) { do something with arr[i-1] }

or

for (size_t i = arr.size; i-- > 0; /* nothing here! */ ) {
do something with arr[i]
}

I.e. remove the traditional i-- from the end of the for loop and instead
integrate it with the loop end test.

Terje

--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

Re: Compact representation for common integer constants

<sao50e$ht0$3@newsreader4.netcologne.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17988&group=comp.arch#17988

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd4-da68-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoe...@netcologne.de (Thomas Koenig)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Sun, 20 Jun 2021 19:30:22 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <sao50e$ht0$3@newsreader4.netcologne.de>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<2021May19.124934@mips.complang.tuwien.ac.at>
<s83h0k$jaj$1@newsreader4.netcologne.de>
<2021May19.214832@mips.complang.tuwien.ac.at> <s8414d$okc$1@dont-email.me>
<2021May20.001137@mips.complang.tuwien.ac.at> <s846ou$s25$1@dont-email.me>
<35c1d9c9-d12a-4812-bcac-07979e0fcaccn@googlegroups.com>
<s84b0a$lht$1@dont-email.me>
<5c8aa7d4-ae7d-465e-bcb4-230ee64b2bfbn@googlegroups.com>
<s8522o$tol$1@dont-email.me> <s85i3s$929$1@dont-email.me>
<s85j8h$hce$1@dont-email.me> <s869c0$nvg$1@dont-email.me>
<s86des$g1a$1@newsreader4.netcologne.de> <86zgvobdd4.fsf@linuxsc.com>
<4e106f2b-31a7-42ff-9523-cb396cbb80fdn@googlegroups.com>
<sag7gi$9ur$1@dont-email.me> <sag8p5$il8$1@dont-email.me>
<saheha$ie$2@newsreader4.netcologne.de> <sahnmn$n6t$1@dont-email.me>
<saii8n$p5t$1@newsreader4.netcologne.de> <saija3$ue5$1@dont-email.me>
<saj16o$4ij$1@newsreader4.netcologne.de> <sao3gk$vdf$1@gioia.aioe.org>
Injection-Date: Sun, 20 Jun 2021 19:30:22 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd4-da68-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd4:da68:0:7285:c2ff:fe6c:992d";
logging-data="18336"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Sun, 20 Jun 2021 19:30 UTC

Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
> Thomas Koenig wrote:
>> David Brown <david.brown@hesbynett.no> schrieb:
>>> On 18/06/2021 18:39, Thomas Koenig wrote:
>>>> David Brown <david.brown@hesbynett.no> schrieb:
>>>>
>>>>> I disagree somewhat on saying "signed has far nicer properties", just as
>>>>> I disagree with people who say "unsigned" are "safer" or better defined.
>>>>
>>>> The main reason why I try to use unsigned only where possible is loops.
>>>>
>>>> With signed integers, it is easy to write a loop from a to b
>>>> which gets executed zero times if a > b, as in
>>>>
>>>> for (i=a ; i<b, i++)
>>>>
>>>> For unsigned... hm.
>>>>
>>>
>>> I prefer to know what "a" and "b" are before writing the loop, and
>>> whether (a > b) might hold.
>>>
>>> If you write your code assuming (a <= b), but in fact (a > b), then it
>>> doesn't matter if you use signed or unsigned types - your code is
>>> broken. And if the assumption /does/ hold, then it doesn't matter
>>> whether your types are signed or unsigned either.
>>
>> I have use, from time to time, for arrays with negative offsets
>> (I guess Fortran spoiled me there). Looping over such an
>> array with an unsigned index would be... interesting.
>>
>> The other thing that I like are zero-sized arrays which take
>> no special handling, they just work.
>>
>> Again, hard to do with unsigned integers.
>
> for (size_t i = 0; i < arr.size; i++) {}
>
> With arr.size == 0 all compilers will give you zero iterations of the
> loop, what is the issue?

There isn't an issue for that particular use case. However,
loops with unsigned variables are problematic if you want
nothing done for b < a when you write

for (i=a; i<b; i++)

and b could have a wraparound.

An issue with optimization is that it is much harder for a compiler
to handle loop with unsigned values, it is often impossible to
prove that they terminate.

And, of course, writing a traditional Fortran DO loop with unsigned
arithmetic would be highly problematic at least :-)

Re: Compact representation for common integer constants

<86c73e59-e8a8-4ed3-af5a-72aa57268019n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17993&group=comp.arch#17993

  copy link   Newsgroups: comp.arch
X-Received: by 2002:ac8:6911:: with SMTP id e17mr20867514qtr.256.1624229763433; Sun, 20 Jun 2021 15:56:03 -0700 (PDT)
X-Received: by 2002:a9d:82b:: with SMTP id 40mr18862334oty.81.1624229763313; Sun, 20 Jun 2021 15:56:03 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!tr2.eu1.usenetexpress.com!feeder.usenetexpress.com!tr3.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Sun, 20 Jun 2021 15:56:03 -0700 (PDT)
In-Reply-To: <sao50e$ht0$3@newsreader4.netcologne.de>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:299e:8c57:5fb2:49d; posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:299e:8c57:5fb2:49d
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com> <2021May19.124934@mips.complang.tuwien.ac.at> <s83h0k$jaj$1@newsreader4.netcologne.de> <2021May19.214832@mips.complang.tuwien.ac.at> <s8414d$okc$1@dont-email.me> <2021May20.001137@mips.complang.tuwien.ac.at> <s846ou$s25$1@dont-email.me> <35c1d9c9-d12a-4812-bcac-07979e0fcaccn@googlegroups.com> <s84b0a$lht$1@dont-email.me> <5c8aa7d4-ae7d-465e-bcb4-230ee64b2bfbn@googlegroups.com> <s8522o$tol$1@dont-email.me> <s85i3s$929$1@dont-email.me> <s85j8h$hce$1@dont-email.me> <s869c0$nvg$1@dont-email.me> <s86des$g1a$1@newsreader4.netcologne.de> <86zgvobdd4.fsf@linuxsc.com> <4e106f2b-31a7-42ff-9523-cb396cbb80fdn@googlegroups.com> <sag7gi$9ur$1@dont-email.me> <sag8p5$il8$1@dont-email.me> <saheha$ie$2@newsreader4.netcologne.de> <sahnmn$n6t$1@dont-email.me> <saii8n$p5t$1@newsreader4.netcologne.de> <saija3$ue5$1@dont-email.me> <saj16o$4ij$1@newsreader4.netcologne.de> <sao3gk$vdf$1@gioia.aioe.org> <sao50e$ht0$3@newsreader4.netcologne.de>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <86c73e59-e8a8-4ed3-af5a-72aa57268019n@googlegroups.com>
Subject: Re: Compact representation for common integer constants
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Sun, 20 Jun 2021 22:56:03 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 57
 by: MitchAlsup - Sun, 20 Jun 2021 22:56 UTC

On Sunday, June 20, 2021 at 2:30:24 PM UTC-5, Thomas Koenig wrote:
> Terje Mathisen <terje.m...@tmsw.no> schrieb:
> > Thomas Koenig wrote:
> >> David Brown <david...@hesbynett.no> schrieb:
> >>> On 18/06/2021 18:39, Thomas Koenig wrote:
> >>>> David Brown <david...@hesbynett.no> schrieb:
> >>>>
> >>>>> I disagree somewhat on saying "signed has far nicer properties", just as
> >>>>> I disagree with people who say "unsigned" are "safer" or better defined.
> >>>>
> >>>> The main reason why I try to use unsigned only where possible is loops.
> >>>>
> >>>> With signed integers, it is easy to write a loop from a to b
> >>>> which gets executed zero times if a > b, as in
> >>>>
> >>>> for (i=a ; i<b, i++)
> >>>>
> >>>> For unsigned... hm.
> >>>>
> >>>
> >>> I prefer to know what "a" and "b" are before writing the loop, and
> >>> whether (a > b) might hold.
> >>>
> >>> If you write your code assuming (a <= b), but in fact (a > b), then it
> >>> doesn't matter if you use signed or unsigned types - your code is
> >>> broken. And if the assumption /does/ hold, then it doesn't matter
> >>> whether your types are signed or unsigned either.
> >>
> >> I have use, from time to time, for arrays with negative offsets
> >> (I guess Fortran spoiled me there). Looping over such an
> >> array with an unsigned index would be... interesting.
> >>
> >> The other thing that I like are zero-sized arrays which take
> >> no special handling, they just work.
> >>
> >> Again, hard to do with unsigned integers.
> >
> > for (size_t i = 0; i < arr.size; i++) {}
> >
> > With arr.size == 0 all compilers will give you zero iterations of the
> > loop, what is the issue?
> There isn't an issue for that particular use case. However,
> loops with unsigned variables are problematic if you want
> nothing done for b < a when you write
>
> for (i=a; i<b; i++)
>
> and b could have a wraparound.
>
> An issue with optimization is that it is much harder for a compiler
> to handle loop with unsigned values, it is often impossible to
> prove that they terminate.
>
> And, of course, writing a traditional Fortran DO loop with unsigned
> arithmetic would be highly problematic at least :-)
<
FORTRAN DO loops can convert the DO loop range in to a counted number
loop passes and avoid the problem.

Re: Compact representation for common integer constants

<sap71k$8o5$1@newsreader4.netcologne.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17998&group=comp.arch#17998

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd4-da68-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoe...@netcologne.de (Thomas Koenig)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Mon, 21 Jun 2021 05:11:16 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <sap71k$8o5$1@newsreader4.netcologne.de>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<2021May19.214832@mips.complang.tuwien.ac.at> <s8414d$okc$1@dont-email.me>
<2021May20.001137@mips.complang.tuwien.ac.at> <s846ou$s25$1@dont-email.me>
<35c1d9c9-d12a-4812-bcac-07979e0fcaccn@googlegroups.com>
<s84b0a$lht$1@dont-email.me>
<5c8aa7d4-ae7d-465e-bcb4-230ee64b2bfbn@googlegroups.com>
<s8522o$tol$1@dont-email.me> <s85i3s$929$1@dont-email.me>
<s85j8h$hce$1@dont-email.me> <s869c0$nvg$1@dont-email.me>
<s86des$g1a$1@newsreader4.netcologne.de> <86zgvobdd4.fsf@linuxsc.com>
<4e106f2b-31a7-42ff-9523-cb396cbb80fdn@googlegroups.com>
<sag7gi$9ur$1@dont-email.me> <sag8p5$il8$1@dont-email.me>
<saheha$ie$2@newsreader4.netcologne.de> <sahnmn$n6t$1@dont-email.me>
<saii8n$p5t$1@newsreader4.netcologne.de> <saija3$ue5$1@dont-email.me>
<saj16o$4ij$1@newsreader4.netcologne.de> <sao3gk$vdf$1@gioia.aioe.org>
<sao50e$ht0$3@newsreader4.netcologne.de>
<86c73e59-e8a8-4ed3-af5a-72aa57268019n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 21 Jun 2021 05:11:16 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd4-da68-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd4:da68:0:7285:c2ff:fe6c:992d";
logging-data="8965"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Mon, 21 Jun 2021 05:11 UTC

MitchAlsup <MitchAlsup@aol.com> schrieb:
> On Sunday, June 20, 2021 at 2:30:24 PM UTC-5, Thomas Koenig wrote:

>> loops with unsigned variables are problematic if you want
>> nothing done for b < a when you write
>>
>> for (i=a; i<b; i++)
>>
>> and b could have a wraparound.
>>
>> An issue with optimization is that it is much harder for a compiler
>> to handle loop with unsigned values, it is often impossible to
>> prove that they terminate.
>>
>> And, of course, writing a traditional Fortran DO loop with unsigned
>> arithmetic would be highly problematic at least :-)
><
> FORTRAN DO loops can convert the DO loop range in to a counted number
> loop passes and avoid the problem.

This is indeed how the loop count is defined.

If you have a loop

DO I=m1,m2,m3

then (clause 11.1.7.4.1, p. 3) "The iteration count is established
and is the value of the expression (m2 − m1 + m3 )/m3 , unless
that value is negative, in which case the iteration count is 0."
Note 1 (non-normative) stating

The iteration count is zero whenever:
m1 > m2 and m3 > 0, or
m1 < m2 and m3 < 0.

If you do this with signed integers, all is fine. If you introduce
unsigned integers, you would have to redfine things because
(m2 - m1 + m3)/m3 can no longer be negative, and defining
what the iteratiion cound should be for

do i=1,2,unsigned(-1)

could become interesting. "Can of worms" only just starts describing
the issues...

Re: Compact representation for common integer constants

<saplp4$r8s$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18002&group=comp.arch#18002

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Mon, 21 Jun 2021 11:22:43 +0200
Organization: A noiseless patient Spider
Lines: 88
Message-ID: <saplp4$r8s$1@dont-email.me>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<2021May19.124934@mips.complang.tuwien.ac.at>
<s83h0k$jaj$1@newsreader4.netcologne.de>
<2021May19.214832@mips.complang.tuwien.ac.at> <s8414d$okc$1@dont-email.me>
<2021May20.001137@mips.complang.tuwien.ac.at> <s846ou$s25$1@dont-email.me>
<35c1d9c9-d12a-4812-bcac-07979e0fcaccn@googlegroups.com>
<s84b0a$lht$1@dont-email.me>
<5c8aa7d4-ae7d-465e-bcb4-230ee64b2bfbn@googlegroups.com>
<s8522o$tol$1@dont-email.me> <s85i3s$929$1@dont-email.me>
<s85j8h$hce$1@dont-email.me> <s869c0$nvg$1@dont-email.me>
<s86des$g1a$1@newsreader4.netcologne.de> <86zgvobdd4.fsf@linuxsc.com>
<4e106f2b-31a7-42ff-9523-cb396cbb80fdn@googlegroups.com>
<sag7gi$9ur$1@dont-email.me> <sag8p5$il8$1@dont-email.me>
<saheha$ie$2@newsreader4.netcologne.de> <sahnmn$n6t$1@dont-email.me>
<saii8n$p5t$1@newsreader4.netcologne.de> <saija3$ue5$1@dont-email.me>
<saj16o$4ij$1@newsreader4.netcologne.de> <sao3gk$vdf$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 21 Jun 2021 09:22:44 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="df33aeeb06c9ad5932ebf6808d84c8f3";
logging-data="27932"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1940V8w/eZ+8wg/eVtpujEbNjqmC99WngI="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
Thunderbird/68.10.0
Cancel-Lock: sha1:iDDKVKuZ2aevTW/SwpDExYbQYbE=
In-Reply-To: <sao3gk$vdf$1@gioia.aioe.org>
Content-Language: en-GB
 by: David Brown - Mon, 21 Jun 2021 09:22 UTC

On 20/06/2021 21:04, Terje Mathisen wrote:
> Thomas Koenig wrote:
>> David Brown <david.brown@hesbynett.no> schrieb:
>>> On 18/06/2021 18:39, Thomas Koenig wrote:
>>>> David Brown <david.brown@hesbynett.no> schrieb:
>>>>
>>>>> I disagree somewhat on saying "signed has far nicer properties",
>>>>> just as
>>>>> I disagree with people who say "unsigned" are "safer" or better
>>>>> defined.
>>>>
>>>> The main reason why I try to use unsigned only where possible is loops.
>>>>
>>>> With signed integers, it is easy to write a loop from a to b
>>>> which gets executed zero times if a > b, as in
>>>>
>>>>    for (i=a ; i<b, i++)
>>>>
>>>> For unsigned... hm.
>>>>
>>>
>>> I prefer to know what "a" and "b" are before writing the loop, and
>>> whether (a > b) might hold.
>>>
>>> If you write your code assuming (a <= b), but in fact (a > b), then it
>>> doesn't matter if you use signed or unsigned types - your code is
>>> broken.  And if the assumption /does/ hold, then it doesn't matter
>>> whether your types are signed or unsigned either.
>>
>> I have use, from time to time, for arrays with negative offsets
>> (I guess Fortran spoiled me there).  Looping over such an
>> array with an unsigned index would be... interesting.
>>
>> The other thing that I like are zero-sized arrays which take
>> no special handling, they just work.
>>
>> Again, hard to do with unsigned integers.
>
> for (size_t i = 0; i < arr.size; i++) {}
>
> With arr.size == 0 all compilers will give you zero iterations of the
> loop, what is the issue?
>
> The only slightly complicated situation with unsigned is when I need to
> count down to zero, i.e. do something to arr[n-1], arr[n-2],...arr[1],
> arr[0.
>
> Here it is easy but wrong to write the natural¨
>
>  for (size_t i = arr.size-1; i >= 0; i--) { do something with arr[i] }
>
> since a size_t can never become negative so this is an infinite loop.
>
> The alternatives are slighly more complicated:
>
>   for (size_t i = arr.size; i > 0; i--) { do something with arr[i-1] }
>
> or
>
>   for (size_t i = arr.size; i-- > 0; /* nothing here! */ ) {
>     do something with arr[i]
>   }
>
> I.e. remove the traditional i-- from the end of the for loop and instead
> integrate it with the loop end test.
>
> Terje
>

Or you can use the ranged for in C++ :

Iterate forward:

void foo2(void) {
for (auto& a : arr) {
a++;
}
}

Iterate backwards (using <ranges> from C++20 or boost libraries) :

void bar1(void) {
for (auto& a : arr | std::views::reverse) {
a++;
}
}

Re: Compact representation for common integer constants

<86y2ax9t8a.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18076&group=comp.arch#18076

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Fri, 25 Jun 2021 20:53:41 -0700
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <86y2ax9t8a.fsf@linuxsc.com>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com> <e29a79f4-80ba-4dcb-8079-cf2f87a86b3en@googlegroups.com> <s7svtl$qlt$1@newsreader4.netcologne.de> <bcd3dd9a-cfcd-4691-9163-842ddf1f483dn@googlegroups.com> <s7u338$cek$1@newsreader4.netcologne.de> <s7v6j1$qns$1@dont-email.me> <s7vn9p$bfu$1@newsreader4.netcologne.de> <2021May18.183723@mips.complang.tuwien.ac.at> <s80rjn$1ci$2@newsreader4.netcologne.de> <2021May19.124934@mips.complang.tuwien.ac.at> <d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com> <nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me> <igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me> <51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com> <s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad> <s89ahe$t4n$1@dont-email.me> <26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com> <s8boip$ka2$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="3832d731885168e7b849b5bd0868fbfc";
logging-data="10255"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19nCrVbBGozUO8dlYgxsQh0T2wVHPuknA0="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:yEbuVJPzzLiBKowhXXl08edoC80=
sha1:rcERTl8mfFSHFGNyI4oj/M4C9o8=
 by: Tim Rentsch - Sat, 26 Jun 2021 03:53 UTC

Terje Mathisen <terje.mathisen@tmsw.no> writes:

> MitchAlsup wrote:
>
>>> [...]
>>
>> This brings to mind that the whole concept of arithmetic exceptions is
>> fundamentally flawed.
>> It is not the arithmetic that should be checked for out-of-range values
>> it is the depositing of values into containers that should be checked.
>
> I agree:
>
> It is my strong and not so humble opinion that a cpu/program/language
> should always be free to deliver the best result it can, i.e. even if
> an intermediate results would overflow/trap on most other CPUs.
>
> If the final result delivered is in range, and mathematically correct,
> then use it, otherwise trap at that point.
>
> It is typically more prevalent on FP where some architectures can
> deliver results that are closer to the mathematical definition than
> others (long double intermediates etc), but the recent uint16_t
> example shows that this can be an issue for integer ops as well.

First let me see if I understand you. If we have code like this

some_type a, b, c;

...

some_type x = a + b - c;

do you mean that the code could work reliably on some systems and
fail reliably on other systems? (The "reliably" here means no
undefined behavior in either case.)

Also, if we have code like this

some_type a, b, c;

...

some_type x = a + b - c;

then the result could be different than if the code were written
instead as follows

some_type a, b, c;

...

some_type a_plus_b = a + b;
some_type x = a_plus_b - c;

In the above 'some_type' is meant to be any integer type
or any real floating point type. (I am curious to know
if you also meant to include complex floating point types,
but that is very much a secondary question.) Also the
question is meant to include other arithmetic operations
such as *, /, and %.

Have I understood you correctly? If so, is there something
important that I missed? If not, could you explain what you
do mean?

Re: Compact representation for common integer constants

<jwvim20pv61.fsf-monnier+comp.arch@gnu.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18097&group=comp.arch#18097

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: monn...@iro.umontreal.ca (Stefan Monnier)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Sat, 26 Jun 2021 10:19:38 -0400
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <jwvim20pv61.fsf-monnier+comp.arch@gnu.org>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<s7svtl$qlt$1@newsreader4.netcologne.de>
<bcd3dd9a-cfcd-4691-9163-842ddf1f483dn@googlegroups.com>
<s7u338$cek$1@newsreader4.netcologne.de> <s7v6j1$qns$1@dont-email.me>
<s7vn9p$bfu$1@newsreader4.netcologne.de>
<2021May18.183723@mips.complang.tuwien.ac.at>
<s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at>
<d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com>
<nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me>
<igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me>
<51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com>
<s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad>
<s89ahe$t4n$1@dont-email.me>
<26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com>
<s8boip$ka2$1@gioia.aioe.org> <86y2ax9t8a.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="47441adc7dc81cce55e7c8e0d7424681";
logging-data="24545"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ls2zcJosGTMrUWIwkAWo7"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
Cancel-Lock: sha1:8sPDi2i5Jl+bA0Q/9XJXMh2FBTI=
sha1:qGOC6bvb0O5UiTs2PaYEP2WhuhA=
 by: Stefan Monnier - Sat, 26 Jun 2021 14:19 UTC

> First let me see if I understand you. If we have code like this
>
> some_type a, b, c;
>
> ...
>
> some_type x = a + b - c;
>
> do you mean that the code could work reliably on some systems and
> fail reliably on other systems? (The "reliably" here means no
> undefined behavior in either case.)

Take `some_type` to be some kind of multiprecision integer. Then yes,
I think it makes sense to reliably return the right result when there's
enough memory to hold those integers and to trap reliably when we run
out of memory during the computation.

Stefan

Re: Compact representation for common integer constants

<f681e1b1-1282-40c8-a985-5ad7d697b612n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18103&group=comp.arch#18103

  copy link   Newsgroups: comp.arch
X-Received: by 2002:ac8:4a18:: with SMTP id x24mr14064326qtq.239.1624721775031;
Sat, 26 Jun 2021 08:36:15 -0700 (PDT)
X-Received: by 2002:a9d:12a9:: with SMTP id g38mr15512872otg.114.1624721774740;
Sat, 26 Jun 2021 08:36:14 -0700 (PDT)
Path: i2pn2.org!i2pn.org!paganini.bofh.team!usenet.pasdenom.info!usenet-fr.net!fdn.fr!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Sat, 26 Jun 2021 08:36:14 -0700 (PDT)
In-Reply-To: <86y2ax9t8a.fsf@linuxsc.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:d167:c4a4:9932:46f3;
posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:d167:c4a4:9932:46f3
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<e29a79f4-80ba-4dcb-8079-cf2f87a86b3en@googlegroups.com> <s7svtl$qlt$1@newsreader4.netcologne.de>
<bcd3dd9a-cfcd-4691-9163-842ddf1f483dn@googlegroups.com> <s7u338$cek$1@newsreader4.netcologne.de>
<s7v6j1$qns$1@dont-email.me> <s7vn9p$bfu$1@newsreader4.netcologne.de>
<2021May18.183723@mips.complang.tuwien.ac.at> <s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at> <d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com>
<nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me>
<igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me>
<51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com> <s864if$mqg$1@dont-email.me>
<q1UpI.60399$DZ5.42895@fx23.iad> <s89ahe$t4n$1@dont-email.me>
<26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com> <s8boip$ka2$1@gioia.aioe.org>
<86y2ax9t8a.fsf@linuxsc.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f681e1b1-1282-40c8-a985-5ad7d697b612n@googlegroups.com>
Subject: Re: Compact representation for common integer constants
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Sat, 26 Jun 2021 15:36:15 +0000
Content-Type: text/plain; charset="UTF-8"
 by: MitchAlsup - Sat, 26 Jun 2021 15:36 UTC

On Friday, June 25, 2021 at 10:53:44 PM UTC-5, Tim Rentsch wrote:
> Terje Mathisen <terje.m...@tmsw.no> writes:
>
> > MitchAlsup wrote:
> >
> >>> [...]
> >>
> >> This brings to mind that the whole concept of arithmetic exceptions is
> >> fundamentally flawed.
> >> It is not the arithmetic that should be checked for out-of-range values
> >> it is the depositing of values into containers that should be checked.
> >
> > I agree:
> >
> > It is my strong and not so humble opinion that a cpu/program/language
> > should always be free to deliver the best result it can, i.e. even if
> > an intermediate results would overflow/trap on most other CPUs.
> >
> > If the final result delivered is in range, and mathematically correct,
> > then use it, otherwise trap at that point.
> >
> > It is typically more prevalent on FP where some architectures can
> > deliver results that are closer to the mathematical definition than
> > others (long double intermediates etc), but the recent uint16_t
> > example shows that this can be an issue for integer ops as well.
>
> First let me see if I understand you. If we have code like this
>
> some_type a, b, c;
>
> ...
>
> some_type x = a + b - c;
>
> do you mean that the code could work reliably on some systems and
> fail reliably on other systems? (The "reliably" here means no
> undefined behavior in either case.)
>
> Also, if we have code like this
>
> some_type a, b, c;
>
> ...
>
> some_type x = a + b - c;
>
> then the result could be different than if the code were written
> instead as follows
>
> some_type a, b, c;
>
> ...
>
> some_type a_plus_b = a + b;
> some_type x = a_plus_b - c;
<
FORTRAN allows for::
<
some_type x = (a+b)-c;
<
Parenthesis have to be obeyed. The # define in C pretty much made
this FORTRAN convention unworkable in C derived languages.
>
> In the above 'some_type' is meant to be any integer type
> or any real floating point type. (I am curious to know
> if you also meant to include complex floating point types,
> but that is very much a secondary question.) Also the
> question is meant to include other arithmetic operations
> such as *, /, and %.
>
> Have I understood you correctly? If so, is there something
> important that I missed? If not, could you explain what you
> do mean?

Re: Compact representation for common integer constants

<86h7hi9qbh.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18149&group=comp.arch#18149

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Mon, 28 Jun 2021 04:33:22 -0700
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <86h7hi9qbh.fsf@linuxsc.com>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com> <bcd3dd9a-cfcd-4691-9163-842ddf1f483dn@googlegroups.com> <s7u338$cek$1@newsreader4.netcologne.de> <s7v6j1$qns$1@dont-email.me> <s7vn9p$bfu$1@newsreader4.netcologne.de> <2021May18.183723@mips.complang.tuwien.ac.at> <s80rjn$1ci$2@newsreader4.netcologne.de> <2021May19.124934@mips.complang.tuwien.ac.at> <d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com> <nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me> <igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me> <51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com> <s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad> <s89ahe$t4n$1@dont-email.me> <26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com> <s8boip$ka2$1@gioia.aioe.org> <86y2ax9t8a.fsf@linuxsc.com> <f681e1b1-1282-40c8-a985-5ad7d697b612n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="07ecc7e6b90142e92a1737c0f645f4c9";
logging-data="26929"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/TlNEYzigAI5K+JuEU9MPVBXe1jEk1Y9M="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:eHUTPedMtd9yvUIjvEaCYZoMR3k=
sha1:fmDQFZJrHQvVIGLsv9UvN+cycLo=
 by: Tim Rentsch - Mon, 28 Jun 2021 11:33 UTC

MitchAlsup <MitchAlsup@aol.com> writes:

> On Friday, June 25, 2021 at 10:53:44 PM UTC-5, Tim Rentsch wrote:
>
>> Terje Mathisen <terje.m...@tmsw.no> writes:
>>
>>> MitchAlsup wrote:
>>>
>>>>> [...]
>>>>
>>>> This brings to mind that the whole concept of arithmetic exceptions is
>>>> fundamentally flawed.
>>>> It is not the arithmetic that should be checked for out-of-range values
>>>> it is the depositing of values into containers that should be checked.
>>>
>>> I agree:
>>>
>>> It is my strong and not so humble opinion that a cpu/program/language
>>> should always be free to deliver the best result it can, i.e. even if
>>> an intermediate results would overflow/trap on most other CPUs.
>>>
>>> If the final result delivered is in range, and mathematically correct,
>>> then use it, otherwise trap at that point.
>>>
>>> It is typically more prevalent on FP where some architectures can
>>> deliver results that are closer to the mathematical definition than
>>> others (long double intermediates etc), but the recent uint16_t
>>> example shows that this can be an issue for integer ops as well.
>>
>> First let me see if I understand you. If we have code like this
>>
>> some_type a, b, c;
>>
>> ...
>>
>> some_type x = a + b - c;
>>
>> do you mean that the code could work reliably on some systems and
>> fail reliably on other systems? (The "reliably" here means no
>> undefined behavior in either case.)
>>
>> Also, if we have code like this
>>
>> some_type a, b, c;
>>
>> ...
>>
>> some_type x = a + b - c;
>>
>> then the result could be different than if the code were written
>> instead as follows
>>
>> some_type a, b, c;
>>
>> ...
>>
>> some_type a_plus_b = a + b;
>> some_type x = a_plus_b - c;
>
> FORTRAN allows for::
> some_type x = (a+b)-c;
> Parenthesis have to be obeyed. [...]

Fine, but that's not what I'm asking about, which is
standard arithmetic types in a C-like language.

Pages:123456789101112131415
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor