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


Groups > comp.lang.c++ > #6822

Re: Slow -- VERY slow brain

From "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com>
Newsgroups comp.lang.c++
Subject Re: Slow -- VERY slow brain
Date 2011-06-16 22:46 +0200
Organization A noiseless patient Spider
Message-ID <itdpg3$nfl$1@dont-email.me> (permalink)
References <itbdgg$aer$1@dont-email.me> <60b67c1e-da5f-48d5-8e5b-f99a34154b4c@r33g2000prh.googlegroups.com> <61cb1940-6462-4539-965f-0d08de716c0b@r35g2000prj.googlegroups.com> <itdboa$kv4$1@dont-email.me> <86259de8-25e5-4d86-bfda-69f722b1055b@gv8g2000vbb.googlegroups.com>

Show all headers | View raw


* madamemandm@yahoo.com, on 16.06.2011 22:10:
> On Jun 16, 11:51 am, "Alf P. Steinbach /Usenet"<alf.p.steinbach
> +use...@gmail.com>  wrote:
>> * madamema...@yahoo.com, on 16.06.2011 16:31:
>>
>>
>>
>>
>>
>>> On Jun 16, 9:22 am, "madamema...@yahoo.com"<madamema...@yahoo.com>
>>> wrote:
>>>> On Jun 15, 6:08 pm, "Alf P. Steinbach /Usenet"<alf.p.steinbach
>>
>>>> +use...@gmail.com>    wrote:
>>>>> Well, I think, it's not just me.
>>
>>>>> Since it's in the FAQ, and since we have discussed this for years, it must be
>>>>> nearly all of us: we're idiots.
>>
>>>>> I'm thinking of the argument for `unsigned` type, that you can do
>>
>>>>>      void foo( unsigned n )
>>>>>      {
>>>>>          assert( n<    maxN );
>>>>>          // blah
>>>>>      }
>>
>>>>> which is reportedly both more concise and more efficient than
>>
>>>>>      void foo( int n )
>>>>>      {
>>>>>          assert( 0<= n&&    n<    maxN );
>>>>>          // blah
>>>>>      }
>>
>>>>> But, the second one can always be written as
>>
>>>>>      void foo( int n )
>>>>>      {
>>>>>          assert( unsigned( n )<    maxN );
>>>>>          // blah
>>>>>      }
>>
>>>> [snip]
>>>> Really?  On a system where UINT_MAX = INT_MAX = -INT_MIN wouldn't the
>>>> second fire the assert while the third would not?  (Assuming maxN>
>>>> 0).
>>
>>>> (Not that the effeciency argument isn't bogus anyway, but I don't
>>>> think this demonstrates it.)
>>
>>> Oops!  Should double check before I send.  Let n = INT_MIN and assume
>>> maxN>    1.
>>
>> The standard guarantees that when x is of integral type then unsigned(x) is
>> congruent to x modulo 2^n where n is the number of value representation bits in
>> `unsigned`. No, this isn't it a quote. I just haven't had my coffee yet so not
>> quite able to express things more simply, sorry.
>
> That is correct, and if you do the math under the conditions I
> described, you find that unsigned(INT_MIN) == 1.

$3.9.1/3 requires the same value representation for a signed type as for its 
corresponding unsigned type.

$3.9/4 defines value representation as the set of bits that holds the value.

With the same number of bits for the value representation the standard does not 
allow your condition UINT_MAX = INT_MAX; you are guaranteed that for every 
signed T value, there is a unique unsigned T value.


>> Anyway, you don't need the math to see that the two codes do the same.
>
> Not without some additional restrictions on the values of n.

That's meaningless, sorry.


>> In the first case the conversion happens at the call site as an implicit
>> promotion, in the second case the same conversion happens locally via a cast.
>
> You need some gaurentees not provided by the language to get any pair
> of the three versions to behave the same.  The second and third differ
> as described above.  The first differs from the second and third in
> that values of n (before conversion at the call-site) such that
> INT_MAX<  n<= UINT_MAX is well-defined for the first case, and
> implementation defined for the other two.

That's again meaningless, sorry.


Cheers & hth.


-- 
blog at <url: http://alfps.wordpress.com>

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Slow -- VERY slow brain "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-16 01:08 +0200
  Re: Slow -- VERY slow brain "Balog Pal" <pasa@lib.hu> - 2011-06-16 01:44 +0200
  Re: Slow -- VERY slow brain Puppet_Sock <puppet_sock@hotmail.com> - 2011-06-16 06:25 -0700
    Re: Slow -- VERY slow brain Noah Roberts <dont@email.me> - 2011-06-29 10:05 -0700
  Re: Slow -- VERY slow brain Keith H Duggar <duggar@alum.mit.edu> - 2011-06-16 07:00 -0700
  Re: Slow -- VERY slow brain "madamemandm@yahoo.com" <madamemandm@yahoo.com> - 2011-06-16 07:22 -0700
    Re: Slow -- VERY slow brain "madamemandm@yahoo.com" <madamemandm@yahoo.com> - 2011-06-16 07:31 -0700
      Re: Slow -- VERY slow brain "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-16 18:51 +0200
        Re: Slow -- VERY slow brain "madamemandm@yahoo.com" <madamemandm@yahoo.com> - 2011-06-16 13:10 -0700
          Re: Slow -- VERY slow brain "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-16 22:46 +0200
            Re: Slow -- VERY slow brain "madamemandm@yahoo.com" <madamemandm@yahoo.com> - 2011-06-17 07:38 -0700
              Re: Slow -- VERY slow brain Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-06-17 18:06 +0200
                Re: Slow -- VERY slow brain "madamemandm@yahoo.com" <madamemandm@yahoo.com> - 2011-06-17 10:49 -0700
        Re: Slow -- VERY slow brain "Paul" <pchristor@yahoo.co.uk> - 2011-06-17 18:27 +0100
  Re: Slow -- VERY slow brain Werner <werasm@gmail.com> - 2011-06-17 01:33 -0700
    Re: Slow -- VERY slow brain Öö Tiib <ootiib@hot.ee> - 2011-06-17 07:48 -0700
      Re: Slow -- VERY slow brain Werner <werasm@gmail.com> - 2011-06-17 09:39 -0700
    Re: Slow -- VERY slow brain "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-17 19:59 +0200

csiph-web