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 1p6kE2-0002g7-7O for pgsql-general@arkaria.postgresql.org; Sun, 18 Dec 2022 03:20:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p6kE0-0000q1-Rb for pgsql-general@arkaria.postgresql.org; Sun, 18 Dec 2022 03:20:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p6kE0-0000ps-FS for pgsql-general@lists.postgresql.org; Sun, 18 Dec 2022 03:20:28 +0000 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p6kDy-0005L7-El for pgsql-general@lists.postgresql.org; Sun, 18 Dec 2022 03:20:28 +0000 Received: by mail-pg1-x530.google.com with SMTP id w37so4157711pga.5 for ; Sat, 17 Dec 2022 19:20:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=o0RyWjkFG1oMMtf9ei2gGh59LNb0frj/nG4UqhyUkXc=; b=lFJnAgOA3wTQix/Y0knGgBA40Sr23La9w7pOz4c/EwzJG52VH7/NwbxlMvbw4OgshV kOa8noCa05IQ7H+EVdkKrE6vtPIJstYnttUYbEsXcX0HvDaK+UcSjRbJcuiPJfdPWmol MimBy40UITI9FsnblNq5UGXsS3Tkp7QY9SrbyzAOb7IinULAsSYSUOx1aCUqEDD+STfT YG3AlCAe4m+7tsP1wsAK5mqZXe18KZlnfuhzHZp/3flc8Sa9YNoo7TirUxhMfSbN91U+ WqJq7E9xxnK1TfEH3DpdvlFQ+acdG29eZo4LmnXLSNqFDN4PHFK6TtrDVBQUW8gTNfPp Ro+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=o0RyWjkFG1oMMtf9ei2gGh59LNb0frj/nG4UqhyUkXc=; b=sy0ZDcqcglCY/mmmQ87OxKggg7+cPI7UZ35lRqZgv/5jGPAeItLHr1MluLEvxhLphj fr7V9RmD+RqaxfKUxSPi/Y1zXrWjS7VJOIRXiYO8GLHYaLDCtZqP5aCahby/Ppd0vLgZ 2dUM0IwUhtPce84Y1WZ0JgHS8bl1r3DpgHbcbKmryzAmXEocu7mVXLszm4nUJZVDLHHM MENA+/RHTU2Oe4TZotx2xyLRJAPku8zVN4rjiRs/UxbQXScP+1r78iCVRlGiomUynhT9 3hWML3HayT1VfE3OQaWRhJd7MxrPuO6Hzf9eJ56P3KgKrYRC6joGfCDOKj+UVgJ00Bsp f93w== X-Gm-Message-State: AFqh2kpTOkWsgvKL7e2YVwBp8Rv0wn7vC1idciilsklmegP55HxlFZ4G i4Xq9c9EONvxgBMX8oZhnpYOja/+Rss= X-Google-Smtp-Source: AMrXdXv0b/12BJwXUpqTpNpFKinPwFfxWNN2ALutfgYGrWYFj7xJZTMOKBEy4fvvnxAdNwfoeFg9Sw== X-Received: by 2002:a62:e303:0:b0:57e:827a:52af with SMTP id g3-20020a62e303000000b0057e827a52afmr10517674pfh.16.1671333623783; Sat, 17 Dec 2022 19:20:23 -0800 (PST) Received: from ?IPV6:2601:681:5a00:f790:6b0:2592:a028:5aa4? ([2601:681:5a00:f790:6b0:2592:a028:5aa4]) by smtp.gmail.com with ESMTPSA id q3-20020aa78423000000b00576d76c9927sm3830334pfn.106.2022.12.17.19.20.22 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 17 Dec 2022 19:20:23 -0800 (PST) Content-Type: multipart/alternative; boundary="------------RD7XZaLR5xfCIZ4437oq5CvX" Message-ID: Date: Sat, 17 Dec 2022 20:20:21 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: integer square root function proposed Content-Language: en-CA To: pgsql-general@lists.postgresql.org References: From: Rob Sargent In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------RD7XZaLR5xfCIZ4437oq5CvX Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 12/17/22 19:39, Martin L. Buchanan wrote: > Dear PostgreSQL colleagues: > > I have just joined this, my first PG mailing list. > > Reading the documentation I found no built-in function for integer > square root, requiring a sequence of: > > floor(sqrt(foo))::integer > > to go from an integer to the integer square root as an integer. > > If PG leaders smile on this suggestion, could we have *isqrt*(foo) > where foo has a numeric type and the result type is the same numeric > type, with the result type being the integer square root for foo >= 0 > and producing an error if negative? (And with infinities and NaNs > processed as described in 8.1 Numeric Types). > > I did not see an explicit enhancement request list in the PG mailing > lists. Recommendations for a more specific list to post this to are > welcome. > > I suspect the majority are comfortable getting a non-integer result for the square root of a number.  What environment have you which needs (sqrt(a) * sqrt(a)) < a-epsilon? --------------RD7XZaLR5xfCIZ4437oq5CvX Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 12/17/22 19:39, Martin L. Buchanan wrote:
Dear PostgreSQL colleagues:

I have just joined this, my first PG mailing list.

Reading the documentation I found no built-in function for integer square root, requiring a sequence of:

floor(sqrt(foo))::integer

to go from an integer to the integer square root as an integer.

If PG leaders smile on this suggestion, could we have isqrt(foo) where foo has a numeric type and the result type is the same numeric type, with the result type being the integer square root for foo >= 0 and producing an error if negative? (And with infinities and NaNs processed as described in 8.1 Numeric Types).

I did not see an explicit enhancement request list in the PG mailing lists. Recommendations for a more specific list to post this to are welcome.



I suspect the majority are comfortable getting a non-integer result for the square root of a number.  What environment have you which needs (sqrt(a) * sqrt(a)) < a-epsilon?

--------------RD7XZaLR5xfCIZ4437oq5CvX--