🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3018

Re: Is INT_MAX<<1 defined?

#3018
From: Norman Diamond
Date: Mon, 14 Dec 1992 07:15
51 lines
3150 bytes
In article <8322@charon.cwi.nl> dik@cwi.nl (Dik T. Winter) writes:
>What it comes down to is that << is not a mathematical operation, there
>is nothing in mathematics that tells us that 16384 << 1 equals 32768.

Additional non-mathematical operations:
  ++ (prefix and postfix)
  -- (prefix and postfix)
  [] (subscript, C definition using pointers)
  () (function call, C definition using pointers)
  () (cast)
  unary  &  *  !
  unary  ~  on a value that is not a single bit
  binary /  on integral values where the mathematical quotient is not integral
  binary .  ->  sizeof  %  &  ^  |  &&  ||  =  *=(etc.)  ,

>So what is the meaning of:
>1.  Operation on value in this case?

Operations have meanings defined in the C standard.  For "value", it looks
like we have to refer to another standard.  The ANSI C standard, section 1.6,
page 4 lines 3 to 5, says:  "Terms not defined in this Standard are to be
interpreted according to the American National Dictionary for Information
Processing Systems, Information Processing Systems Technical Report ANSI
X3/TR-1-82 (1982)."  I don't know the ISO equivalent.

>    Where in the standard does it tell
>    us that for signed (16 bit) int 16384, 16384 << 1 is 32768?

I think the standard is unclear enough to recommend an interpretation ruling.
However, for comparison, for unsigned types, the standard says explicitly
that the value of the result is a mathematical multiplication followed by
a mathematical modulo reduction -- if it were a representation multiplication,
the modulo reduction would have been a no-op and would not have been stated.

>    Is an implementation not allowed to define it as -32768?  Or whatever?

Implementations are allowed to define what happens when signed results don't
fit in the corresponding types.  They aren't REQUIRED to, that's all.

>    But in all there is no definition in *mathematics* for this operation.
[...]
>The bottom-line is that shifting is not a mathematical concept, [...]

That didn't prevent a ton of other C operations from being defined on
mathematical values.  Actually maybe the standards committees can start
to get an idea of just how unpopular this stunt is.  However, that is what
they did, following the path of other language committees.
--
Norman Diamond       diamond@jit081.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.
"It's been a lovely recession."
Technical Details
Message-ID: <Bz8MtG.479@jrd.dec.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!decwrl!deccrl!news.crl.dec.com!rdg.dec.com!uvo.dec.com!e2big.mko.dec.com!jrdzzz.jrd.dec.com!jit533.jit.dec.com!diamond
References: <1992Dec1.050540 <1992Dec8.1 <Bz35no.J6M@jrd.dec.com> <8322@charon.cwi.nl>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!decwrl!deccrl!news.crl.dec.com!rdg.dec.com!uvo.dec.com!e2big.mko.dec.com!jrdzzz.jrd.dec.com!jit533.jit.dec.com!diamond
From: diamond@jit533.jit.dec.com (Norman Diamond)
Subject: Re: Is INT_MAX<<1 defined?
Message-ID: <Bz8MtG.479@jrd.dec.com>
Sender: usenet@jrd.dec.com (USENET News System)
Nntp-Posting-Host: jit533.jit.dec.com
Reply-To: diamond@jit.dec.com (Norman Diamond)
Organization: Digital Equipment Corporation Japan , Tokyo
References: <1992Dec1.050540 <1992Dec8.1 <Bz35no.J6M@jrd.dec.com> <8322@charon.cwi.nl>
Date: Mon, 14 Dec 1992 07:15:16 GMT
Lines: 51