From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from zimbra.cs.ucla.edu (zimbra.cs.ucla.edu [131.179.128.68]) by sourceware.org (Postfix) with ESMTPS id 8294D3858D28 for ; Tue, 17 Jan 2023 20:11:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8294D3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=cs.ucla.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cs.ucla.edu Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id C445216004F; Tue, 17 Jan 2023 12:11:31 -0800 (PST) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id j3b51QagLhkg; Tue, 17 Jan 2023 12:11:31 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 1C1F816005E; Tue, 17 Jan 2023 12:11:31 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.9.2 zimbra.cs.ucla.edu 1C1F816005E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.ucla.edu; s=78364E5A-2AF3-11ED-87FA-8298ECA2D365; t=1673986291; bh=X9AZfQMvYwL22MtA+DYQgsMvi0qCb/kOCwMhMKw8uMY=; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type: Content-Transfer-Encoding; b=I09ToXCrD4TINXxy6CfG8n3cc/d1ScLpDXHptwR3OPfSA6jG3x8LDP+8sq8PqSV84 VhTQYMJ8Ic7DW0tpVgJ/wXT1GK1xWwAMEayt0qk3WiNrujU96s3kzGWmltJKlDkvrT qVF6s9ftRowBPz8Y0sGAnEuRVGy/oTGF5rjMkBYE= X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id GNmB-SgSDyZ9; Tue, 17 Jan 2023 12:11:31 -0800 (PST) Received: from [131.179.64.200] (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id F2FDB16004F; Tue, 17 Jan 2023 12:11:30 -0800 (PST) Message-ID: <59e67ba9-a379-16e9-3300-8f7d6114bf5c@cs.ucla.edu> Date: Tue, 17 Jan 2023 12:11:27 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: bug in roundup(3) from Content-Language: en-US To: Wilco Dijkstra , Adhemerval Zanella , "Alejandro Colomar (man-pages)" Cc: 'GNU C Library' References: From: Paul Eggert Organization: UCLA Computer Science Department In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,JMQ_SPF_NEUTRAL,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 1/17/23 11:16, Wilco Dijkstra via Libc-alpha wrote: > So it seems best to state it only works on unsigned values (with y > 0 since division > by zero is undefined behaviour of course) and it's implementation defined whether > overflow wraps or saturates. roundup works just fine on signed integers. Although x should be nonnegative and y should be positive, there's no requirement that either x or y must be unsigned. This sort of thing matters in the C style I prefer nowadays, which is to use types like ptrdiff_t and idx_t instead of size_t, so that I can optionally enable runtime overflow checking that works.