Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sTmR2-002MIb-0t for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Jul 2024 17:57:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sTmR0-00311X-Hu for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Jul 2024 17:57:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sTmR0-00311P-8L for pgsql-hackers@lists.postgresql.org; Tue, 16 Jul 2024 17:57:54 +0000 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sTmQx-002S26-Ep for pgsql-hackers@lists.postgresql.org; Tue, 16 Jul 2024 17:57:53 +0000 Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-807687b6652so3449739f.0 for ; Tue, 16 Jul 2024 10:57:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721152669; x=1721757469; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=jM0uveyDSsmCmZtDDuujCcGKPiLsjrHK5wL8N1hYqHY=; b=OHu06akjHQRrGFt/588XGSxp7H9gR5/Z4tAPg9p+W+8KzRhcDSWGl92zJAxieWhb5F bKl4l2S3y7rWNvVvEy7enaMkG31fqZLS43V5Oweu4XWMrhHauoT3u8mcLkd7q8L3myIU ile05fhpG5grdl47dZtT7q0u9Li4MidIsk6PyX5wPAguT1tpJcqORV0KFMoM6VrMNd/n IHiIzeqCF5twRSckh9SYXCVYbod0Djti9ZkixCFG/wy2ixA5ZGI/VxGP2hhDS+SITVOy EwUsQW1yplr/QuVftBaXcET6L4UL7P6NpfiCD5h+wZPWXTntVyw5ld0BBnLnC8s5tknT cK3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721152669; x=1721757469; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jM0uveyDSsmCmZtDDuujCcGKPiLsjrHK5wL8N1hYqHY=; b=FZFYDBEP+8Uzi6JYTfhXyHxHRUE6sXk/28kbrEIPE9zfSmoDDckGErRJ8y1SbMjV4p icOUKdIXNKEmcpw15NedpeJDLvqBpU/CTGwE1YMGiDAA5RksAr3chOgwje2hVYf73VqO NTrJEHzAZwTgYHOFJZJ67xezDr7PGIHpCT8Auo7TNbjtOUrg0f/ib1m/DzYaoa8UfdoS TrhncFVYg08WHFfLMLzlIqxiTvGp1n7fqC4GaILrXqfaLoO8BY6fCuqAcSXBxfUu+n0X pA6JFERexKM2RJfD2ZMKEYZcyqZe4K6zr2ID6sOWzEeJPWjvs8ro1QmY/oHJ1wFDh0uk OK5w== X-Forwarded-Encrypted: i=1; AJvYcCVJ/7hHwUiPnBJx+C0QpRuQI5ozGrj4RQgcY5ebnuwjNvMsSiVDYPm+V7lYM7whtNGKUgEsqln8vxRw64KGZlbDSde9J4m/LfUkQjWTCaDXOBx/ X-Gm-Message-State: AOJu0YxNsOamu/YxTeHIEZ8ugYtBmw3uFhS8OkG+OrriF0VD4PwT0xTM Qpb6qdRryHVSByaSZoKNlrlHQ1wVP1jShoHWfUkItTd9ZdYhM6Yv X-Google-Smtp-Source: AGHT+IFlQyxhnjYXbHi6l70op+jOLx2kwU5nGXkmWY5sPb/Bvc+l8NAGd3IrMkyWhPl9h73xL5hgLA== X-Received: by 2002:a05:6602:6418:b0:807:eeef:4fb5 with SMTP id ca18e2360f4ac-816c4541756mr19787339f.1.1721152669611; Tue, 16 Jul 2024 10:57:49 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c210cbc436sm41393173.73.2024.07.16.10.57.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jul 2024 10:57:49 -0700 (PDT) Date: Tue, 16 Jul 2024 12:57:47 -0500 From: Nathan Bossart To: Joseph Koshakow Cc: Alexander Lakhin , Tom Lane , PostgreSQL Hackers , Andres Freund Subject: Re: Remove dependence on integer wrapping Message-ID: References: <31ad2cd1-db94-bdb3-f91a-65ffdb4bef95@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Jul 15, 2024 at 07:55:22PM -0400, Joseph Koshakow wrote: > On Mon, Jul 15, 2024 at 11:31 AM Nathan Bossart > wrote: >> I'm curious why you aren't using float8_mul/float8_div here, i.e., >> >> fresult = rint(float8_mul((float8) c, f)); >> fresult = rint(float8_div((float8) c, f)); > > I wrongly assumed that it was only meant to be used to implement > multiplication and division for the built-in float types. I've updated > the patch to use these functions. The reason I suggested this is so that we could omit all the prerequisite isinf(), isnan(), etc. checks in the cash_mul_float8() and friends. The checks are slighly different, but from a quick glance it just looks like we might end up relying on the FLOAT8_FITS_IN_INT64 check in more cases. >> and "cash_sub_int64" > > Did you mean "cash_div_int64"? There's only a single function that > subtracts cash and an integer, but there's multiple functions that > divide cash by an integer. I've added a "cash_div_int64" in the updated > patch. My personal preference would be to add helper functions for each of these so that all the overflow, etc. checks are centralized in one place and don't clutter the calling code. Plus, it might help ensure error handling/messages remain consistent. +static Cash +cash_mul_float8(Cash c, float8 f) nitpick: Can you mark these "inline"? I imagine most compilers inline them without any prompting, but we might as well make our intent clear. -- nathan