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,091 of 243,242   
   David Brown to Keith Thompson   
   Re: _BitInt(N)   
   24 Nov 25 14:51:09   
   
   From: david.brown@hesbynett.no   
      
   On 24/11/2025 14:06, Keith Thompson wrote:   
   > 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.)   
   >   
      
   It /looks/ like NM means "N + M" (or N * M, as both Bart and I wrote   
   without thinking), but that was not my intention.  I simply meant a   
   constant that may be chosen differently from N and M, and did not want   
   to go on to the letter O.  In hindsight, NM was a poor choice.   
      
   --- 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