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


Groups > comp.lang.c > #395411

Re: _BitInt(N)

Path csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c
Subject Re: _BitInt(N)
Date Mon, 24 Nov 2025 05:06:33 -0800
Organization None to speak of
Lines 34
Message-ID <87a50b4m1y.fsf@example.invalid> (permalink)
References <10dajlh$ko3c$1@dont-email.me> <10fus62$hl69$1@solani.org> <10fv2dm$3can9$1@paganini.bofh.team> <10fv40v$1f7a2$1@dont-email.me> <20251123170654.000056a9@yahoo.com> <10g18hq$28nc2$1@dont-email.me>
MIME-Version 1.0
Content-Type text/plain
Injection-Date Mon, 24 Nov 2025 13:06:34 +0000 (UTC)
Injection-Info dont-email.me; posting-host="497198ffef236bf75350d11e6379045b"; logging-data="2535543"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+N7dinc7ObAsIliE6WW/6w"
User-Agent Gnus/5.13 (Gnus v5.13)
Cancel-Lock sha1:ygxlvL5Zp52EIxpjT7mGAq9aILQ= sha1:gns9rNrF4qohIf5V+tqRzCjEPuI=
Xref csiph.com comp.lang.c:395411

Show key headers only | View raw


David Brown <david.brown@hesbynett.no> 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 */

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


Thread

#394650 
  #394657 
    #394658 
      #394659 
        #394662 
  #395383 
    #395386 
      #395387 
        #395388 
          #395400 
            #395401 
              #395412 
              #395417 
                #395447 
                #395458 
                #395573 
                #395603 
                #395614 
            #395411 
              #395414 
              #395418 
          #395575 
            #395582 
            #395587 
              #395597 
              #395600 
              #395604 
        #395390 
        #395395 
          #395396 
            #395402 
              #395403 
                #395419 
              #395408 
                #395415 
                #395421 
                #395445 
                #395422 
                #395428 
                #395434 
                #395436 
                #395451 
                #395478 
                #395484 
                #395485 
                #395486 
                #395487 
                #395492 
                #395495 
                #395498 
                #395488 
                #395578 
                #395591 
                #395489 
                #395494 
                #395501 
                #395502 
                #395503 
                #395505 
                #395506 
                #395507 
                #395513 
                #395524 
                #395526 
                #395522 
                #395523 
                #395525 
                #395527 
                #395534 
                #395535 
                #395544 
                #395546 
                #395547 
                #395549 
                #395551 
                #395571 
                #395560 
                #395572 
                #395554 
                #395557 
                #395530 
                #395531 
                #395532 
                #395541 
                #395548 
                #395550 
                #395558 
                #395559 
                #395563 
                #395564 
                #395565 
                #395567 
                #395568 
                #395570 
                #395569 
                #395584 
                #395592 
                #395865 
                #395867 
                #395877 
                #395880 
                #395889 
                #396255 
                #395869 
                #396249 
                #395870 
                #396248 
                #395871 
                #395876 
                #395561 
                #395562 
                #395566 
                #395552 
                #395545 
                #395555 
                #395556 
                #395536 
                #395537 
                #395538 
                #395539 
                #395542 
                #395683 
                #395540 
                #395628 
                #395630 
                #395640 
                #395645 
                #395649 
                #395650 
                #395655 
                #395662 
                #395664 
                #395666 
                #395667 
                #395821 
                #395826 
                #395874 
                #395651 
                #395653 
                #395656 
                #395657 
                #395654 
                #395658 
                #395659 
                #395660 
                #395520 
                #395510 
                #395511 
                #395515 
                #395574 
                #395581 
                #395585 
                #395589 
                #395593 
                #395609 
                #395616 
                #395617 
                #395619 
                #395620 
                #395623 
                #395633 
                #395634 
                #395637 
                #395638 
                #395641 
                #395647 
                #395648 
                #395642 
                #395644 
                #395646 
                #395625 
                #395626 
                #395629 
                #395636 
                #395639 
                #395643 
                #395661 
                #395665 
                #395668 
                #395669 
                #395817 
                #395818 
                #395622 
                #395594 
                #395601 
                #395602 
                #395605 
                #395608 
                #395611 
                #395607 
                #395450 
                #395460 
                #395461 
                #395464 
                #395471 
                #395475 
                #395490 
                #395497 
                #395499 
                #395491 
                #395512 
                #395819 
                #395480 
                #395483 
                #395493 
                #395500 
                #395496 
                #395481 
                #395508 
                #395509 
                #395514 
                #395576 
                #395580 
                #395583 
                #395586 
                #395599 
                #395595 
                #395598 
                #395610 
                #395612 
                #395613 
                #395615 
                #395618 
                #395621 
                #395624 
                #395627 
                #395631 
                #395632 
                #395635 
                #395606 
            #395406 
            #395407 
        #395399 
          #395404 
            #395405 
              #395410 
                #395413 
                #395423 
            #395416 
              #395420 
                #395430 
                #395446 
                #395452 
                #395577 
                #395588 
                #395596 
          #395409 
            #395426 

csiph-web