Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oj3YE-0003yJ-SQ for pgsql-general@arkaria.postgresql.org; Thu, 13 Oct 2022 19:07:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oj3YD-0003Vi-OV for pgsql-general@arkaria.postgresql.org; Thu, 13 Oct 2022 19:07:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oj3YD-0003VF-Bc for pgsql-general@lists.postgresql.org; Thu, 13 Oct 2022 19:07:25 +0000 Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oj3YB-0000Lh-2m for pgsql-general@postgresql.org; Thu, 13 Oct 2022 19:07:24 +0000 Received: by mail-lj1-x234.google.com with SMTP id b18so3454293ljr.13 for ; Thu, 13 Oct 2022 12:07:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=IvoHDK8dunedch7Q+/bFEe792TBKChi7fhrv2uh3d8Q=; b=PbHVmjEtQzMRJiIPnpLna9FdJwk8YP8cGIYyiFPntsDuHL2LeADilAcx680urnwLi3 cOaZSlwCoeRSNbj+rOVTtmeOr9z/KQ1Nlt5fbKJ9UTKW6lRQYhVMUekw9izG6SDrhgeq 1CIdFYvIDS/lHvGdBZlptvD/js08wE2w3RpBZEFE4eZsGzxv9K7qCKvBHOAVx1OiMDIq Jrp5/26BOGRcINWpqjBq49R7K/MVXGfedLlhWqb0dYwHmKUmVKIhrj27z1MVdCIweGns wGbpvHg9XouzcPu2D87OURwfm69ExsEFd1x8SSrr62KyW97apPneVA89YNaScxGcGhrw QMDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IvoHDK8dunedch7Q+/bFEe792TBKChi7fhrv2uh3d8Q=; b=M0kytj+BfZHBoQC+n1cSITA3GZkzXCbgu+P5JOJbLNlxwNeDQnlgnN/rGi426k4Etr NXNSeCJChoc1QMwuWo+7+yEVFgE806lzqv6EXrHlFLYWDzryKtUoYkAmJBZqWzaNaO09 r7U/IgqyYkgnkg7dUR7AysmpkNwD8Xqfpdyim++qMeh1yKZsPXVgOyb3N1UaD4Y2k36c b2KQQcsn6b4yrjtcOJnDwK4bfWl278/dwMOP2Dpgj//wGC1CM4ycFna1O/bZkWG8J2eP JeEjE9eTQ9wm3m4SBAb4inqW3HvkIel5klvA9UJn/rKJ+4GY4jK33GlvfW80ATIbf+S/ qwog== X-Gm-Message-State: ACrzQf2A+yvG5iaiU5wxUe/Fa5K2Ldg/tvAQEWM8oYV8cvaSVCDJ3apG 3EIuWPXOdpIgWGaGWqa2DugEA2c6t4ehGmhUaBw= X-Google-Smtp-Source: AMsMyM6amzwLm+i8ezuPA6LStNRWp8PuF+PE6FM+sI60sX5Gvwk0yXBE4szVoML6RsBV0tpELir94pdcrAMq7731yJs= X-Received: by 2002:a05:651c:4ca:b0:26c:50be:5df6 with SMTP id e10-20020a05651c04ca00b0026c50be5df6mr467179lji.177.1665688040315; Thu, 13 Oct 2022 12:07:20 -0700 (PDT) MIME-Version: 1.0 References: <12a40226-70ac-3a3b-3d3a-fdaf9e32d312@aklaver.com> <603008316.190107.1665680007674@office.mailbox.org> <979360.1665681418@sss.pgh.pa.us> In-Reply-To: <979360.1665681418@sss.pgh.pa.us> From: Dean Rasheed Date: Thu, 13 Oct 2022 20:07:08 +0100 Message-ID: Subject: Re: Exponentiation confusion To: Tom Lane Cc: Erik Wienhold , Adrian Klaver , pgsql-general Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 13 Oct 2022 at 18:17, Tom Lane wrote: > > I'm inclined to think that we should push the responsibility for choosing > its rscale into power_var_int(), because internally that already does > estimate the result weight, so with a little code re-ordering we won't > need duplicative estimates. Don't have time to work on that right now > though ... Dean, are you interested in fixing this? > OK, I'll take a look. The most obvious thing to do is to try to make power_var_int() choose the same result rscale as power_var() so that the results are consistent regardless of whether the exponent is an integer. It's worth noting, however, that that will cause in a *reduction* in the output rscale rather than an increase in some cases, since the power_var_int() code path currently always chooses an rscale of at least 16, whereas the other code path in power_var() uses the rscales of the 2 inputs, and produces a minimum of 16 significant digits, rather than 16 digits after the decimal point. For example: select power(5.678, 18.00000001::numeric); power ------------------------- 37628507689498.14987457 (1 row) select power(5.678, 18::numeric); power --------------------------------- 37628507036041.8454541428979479 (1 row) Regards, Dean