Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.misc > #13395

Re: how much computers can do in one second

From Marko Rauhamaa <marko@pacujo.net>
Newsgroups comp.misc
Subject Re: how much computers can do in one second
Date 2017-03-31 09:56 +0300
Organization A noiseless patient Spider
Message-ID <8737du7x3u.fsf@elektro.pacujo.net> (permalink)
References (3 earlier) <8737dwwmdc.fsf@LkoBDZeT.terraraq.uk> <87r31gmn9w.fsf@elektro.pacujo.net> <cj7qdcdjcafrd88ena4k3no13d2bkuqutk@4ax.com> <87d1cywxtg.fsf@elektro.pacujo.net> <ek5c3mFmi9rU26@mid.individual.net>

Show all headers | View raw


Bob Eager <news0006@eager.cx>:

> On Thu, 30 Mar 2017 19:09:47 +0300, Marko Rauhamaa wrote:
>
>> A C programmer also needs to regularly depend on the benign wrapping
>> behavior of (unsigned) integers. For example, you can safely
>> implement a ring buffer by incrementing the read index and the write
>> index as long as the size of the ring buffer is a power of 2.
>
> Bad programming style though. Use the modulus operator or just test
> the value.

Disagree.

The situation is remotely analogous to solving the roots of the cubic
function (<URL: https://en.wikipedia.org/wiki/Cubic_function#Derivat
ion_of_the_roots>). In the 16th century, people were uneasy about the
fact that Cardano's formula yielded the correct (real) results but
involved taking square roots of negative numbers.

Later, this blemish was found to be a great feature. You couldn't have
modern mathematics without complex numbers.

Similarly, you couldn't have C programming without 2's complement modulo
arithmetics.

I once reported a bug in LXPanel (<URL:
https://wiki.lxde.org/en/LXPanel>). Its CPU monitor would stop working
after a few months of use on a 32-bit machine. The root cause was the
behavior of sscanf("%u"). LXPanel would read two numbers from a /proc
file and take the difference. After some time, the ever-increasing
numbers would overflow the 32-bit range. Unfortunately, the sscanf()
function chooses to return UINT_MAX in that situation, which results in
a zero difference between the values.

If sscanf() had just calculated the number naïvely:

    while (...) {
        number = number * 10 + c - '0';
        c = next(...);
    }

the overflow would have behaved gracefully under the difference.


Marko

Back to comp.misc | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

how much computers can do in one second RS Wood <rsw@therandymon.com> - 2017-03-27 14:43 +0300
  Re: how much computers can do in one second Marko Rauhamaa <marko@pacujo.net> - 2017-03-27 15:06 +0300
    Re: how much computers can do in one second Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-03-29 01:55 +0100
      Re: how much computers can do in one second Marko Rauhamaa <marko@pacujo.net> - 2017-03-29 10:25 +0300
      Re: how much computers can do in one second Richard Kettlewell <invalid@invalid.invalid> - 2017-03-29 08:52 +0100
        Re: how much computers can do in one second Marko Rauhamaa <marko@pacujo.net> - 2017-03-29 12:43 +0300
          Re: how much computers can do in one second Caecilius <nospam@spamless.invalid> - 2017-03-30 16:07 +0100
            Re: how much computers can do in one second Marko Rauhamaa <marko@pacujo.net> - 2017-03-30 19:09 +0300
              Re: how much computers can do in one second Bob Eager <news0006@eager.cx> - 2017-03-30 21:36 +0000
                Re: how much computers can do in one second Marko Rauhamaa <marko@pacujo.net> - 2017-03-31 09:56 +0300
  Re: how much computers can do in one second Huge <Huge@nowhere.much.invalid> - 2017-03-27 13:51 +0000
  Re: how much computers can do in one second Sylvia Else <sylvia@not.at.this.address> - 2017-03-28 11:57 +1100
    Re: how much computers can do in one second Huge <Huge@nowhere.much.invalid> - 2017-03-28 09:51 +0000
      Re: how much computers can do in one second Bob Eager <news0006@eager.cx> - 2017-03-28 11:12 +0000

csiph-web