home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c      Meh, in C you gotta define EVERYTHING      243,242 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 242,085 of 243,242   
   Keith Thompson to David Brown   
   Re: _BitInt(N)   
   24 Nov 25 05:06:33   
   
   From: Keith.S.Thompson+u@gmail.com   
      
   David Brown  writes:   
   [...]   
   > Yes, exactly.  At the call site, the size of the _BitInt type is   
   > always a known compile-time constant, so it can easily be passed on.   
   > Thus :   
   >   
   > 	_BitInt(N) x;   
   > 	_BitInt(M) y;   
   > 	_BitInt(NM) z = x * y;   
   >   
   > can be implemented as something like :   
   >   
   > 	__bit_int_signed_mult(NM, (unsigned char *) &z,   
   > 			N, (const unsigned char *) &x,   
   > 			M, (const unsigned char *) &y);   
      
   That looks like it's supposed to avoid overflow (I'm assuming NM is N + M), but   
   it wouldn't work.  The type of a C expression is almost always determined   
   by the expression itself, regardless of the context in which it appears.   
   The type of x * y is _BitInt(max(N, M)), not _BitInt(N+M), so it can   
   overflow even if the full result would fit into z.   
      
   You can do this instead (not tested):   
      
       _BitInt(N) x;   
       _BitInt(M) y;   
       _Bit_Int(N+M) z = (_BitInt(N+M))x * y;   
      
   (I'm assuming N+M is sufficient, but I might have missed an off-by-one   
   error somewhere.)   
      
   --   
   Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com   
   void Void(void) { Void(); } /* The recursive call of the void */   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca