Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j5Yw3-0006LU-Ch for pgsql-hackers@arkaria.postgresql.org; Sat, 22 Feb 2020 17:51:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j5Yw1-00037E-8R for pgsql-hackers@arkaria.postgresql.org; Sat, 22 Feb 2020 17:51:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j5Yw0-000377-Oh for pgsql-hackers@lists.postgresql.org; Sat, 22 Feb 2020 17:51:24 +0000 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j5Yvx-000588-KL for pgsql-hackers@postgresql.org; Sat, 22 Feb 2020 17:51:23 +0000 Received: by mail-pg1-x52f.google.com with SMTP id 6so2723209pgk.0 for ; Sat, 22 Feb 2020 09:51:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:cc:date:in-reply-to:references :mime-version:content-transfer-encoding; bh=xrb2RDLS1Wd4+lpAI1lyNvJs4V2B9uJwxGjtLgWhYdo=; b=HCNoax9AHMFBvN9NUo+0YD6RdFgNAUp+ZySijV2vFOS5/0tDr68maLOIu4wYgxSj93 X0w/BS105qKyiu1/35O+U+Zt8/b1PxOtDJA0Ng1Ah3RaazPB8sjp1hAaQzmUfMUzspbb O21HP+5tOUgGYaqiIZ+lOF8ZsinOixltYchY4PBtOIDG7W+LIN9HlT25MS60Ju2eETgT Uux5WSWrkJvzaroceSvDGMuJm7uEDgc2Y1pJjJtYsHOvLqaZhRK+JqrkL/1n7Wi6bYfH eOhORBl0QzjQT/JGfUBeUjimQAGLKQr5m36FybTz+lJkXi61BQwKoSW8r57Y6F68Fjw/ godA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=xrb2RDLS1Wd4+lpAI1lyNvJs4V2B9uJwxGjtLgWhYdo=; b=JSp/mmgH+eFNMXduSQsy9ZvV/2rGilcZKLYxSUs3voyEyi9mhyla17wNbqEQQ2J7Eu +H6I9BxAUtSUVE5f9eKIN6Zykcm7nCHySrAqTTqISNhUoCZyUD3kLPK4DO9XWv449nKA V3VNf6BdB7Om3bHCDruYPI0SymjnA9ytK5MQ+/utu9K17fNrF+gJxFGxZbfI/fgtNZn5 SRO2QjHY+hMkVlBx0fgJ9sw/8KNzIHm3KCbKNi0qJOSM7+pRJZoYrUbgwZtqClJqM2K/ c8Lc+LISshiYUJNZ5M1fj7weUAYJDt3e8mBxhRYPxKMDa7/upDWBkcZfYtLuRW84Zto/ my7g== X-Gm-Message-State: APjAAAX0vSo5yZE6hWpjBWduQERxuoRc8gaMA/bIO1PbWiDP6YFm4LX3 TtTNFSLBa/zUQOdfmqfOqWjfTQ== X-Google-Smtp-Source: APXvYqyyQH4RHTlMf1v8eFuNJ1DM706OsZYzu1tlsOZWtAh1bni+XSCeEWlquO7U+ngYcDrZZ6K53w== X-Received: by 2002:a63:1503:: with SMTP id v3mr44449492pgl.295.1582393879865; Sat, 22 Feb 2020 09:51:19 -0800 (PST) Received: from jdavis.lan (c-73-231-146-4.hsd1.ca.comcast.net. [73.231.146.4]) by smtp.gmail.com with ESMTPSA id b27sm6659510pgl.77.2020.02.22.09.51.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 22 Feb 2020 09:51:18 -0800 (PST) Message-ID: <0404d85ef736eb9a33138e94d0c745cd22e50fba.camel@j-davis.com> Subject: Re: POC: rational number type (fractions) From: Jeff Davis To: Joe Nelson Cc: pgsql-hackers@postgresql.org Date: Sat, 22 Feb 2020 09:51:16 -0800 In-Reply-To: <20200222012447.GG42864@begriffs.com> References: <20200208042554.GE42864@begriffs.com> <80df7e765063cf044a483a751d7171017f697a31.camel@j-davis.com> <20200222012447.GG42864@begriffs.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, 2020-02-21 at 19:24 -0600, Joe Nelson wrote: > I could imagine having two types, a rational8 for the current > implementation, and an arbitrary precision rational. Perhaps... The main thing I'm trying to avoid is a situation where we introduce "rational", but it only meets a subset of the use cases, and then we end up with another extension. I'm not saying that's happening here, but it would be good to compare against other implementations (for instance from normal programming languages) to see if we are missing some use cases. If you are using rational to track positions of items in an online to- do list, and the user keeps swapping or rotating items in the list, is that going to lead to overflow/underflow? > > * what's the philosophy regarding NULL and rational? Why are NULL > > arguments returning non-NULL answers? > > The rational_intermediate(x, y) function picks a fraction between x > and > y, and NULL was meant as a signal that one of the sides is unbounded. > So rational_intermediate(x, NULL) means find a fraction larger than > x, > and rational_intermediate(NULL, y) means find one smaller than y. Would "x+1" or "y-1" also work for that? I am a little worried about introducing a function that is not well- defined. Would a midpoint function serve the purpose? > If there are already todos positioned after 2 then it'll find a spot > between 2 and the min. However if there are no todos after 2 then > min() > will return NULL and we'll simply find a position *somewhere* after > 2. Interesting. That could probably be solved with a COALESCE() around the MIN(), but your version is a little cleaner. > > * Is rational_intermediate() well-defined, or can it just choose > > any > > rational between the two arguments? > > It chooses the mediant [2] Maybe we should define it as the mediant then? > currently included these casts: integer -> rational, float8 <-> > rational. Don't have one for numeric yet. A cast to numeric would make sense. What will you do in cases where the domains don't quite match, are you rounding or truncating? Regards, Jeff Davis