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 1nKd2s-0005Ji-Ks for pgsql-general@arkaria.postgresql.org; Thu, 17 Feb 2022 09:25:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nKd2r-0004z8-5L for pgsql-general@arkaria.postgresql.org; Thu, 17 Feb 2022 09:25:49 +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 1nKd2q-0004yz-RR for pgsql-general@lists.postgresql.org; Thu, 17 Feb 2022 09:25:48 +0000 Received: from smtprelay07.ispgateway.de ([134.119.228.97]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nKd2k-000878-2h for pgsql-general@lists.postgresql.org; Thu, 17 Feb 2022 09:25:47 +0000 Received: from [109.90.124.214] (helo=mail.office.datagis.com) by smtprelay07.ispgateway.de with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nKd2f-000739-6j for pgsql-general@lists.postgresql.org; Thu, 17 Feb 2022 10:25:37 +0100 Received: from localhost (intranator.datagis.local [127.0.0.1]) by localhost (Postfix) with ESMTP id 3528439E for ; Thu, 17 Feb 2022 10:25:38 +0100 (CET) X-Virus-Scanned: by Intra2net Mail Security (AVE=8.3.64.92,VDF=8.19.7.102) X-Spam-Status: X-Spam-Level: 0 Received: from [192.168.12.10] (dslb-002-205-128-037.002.205.pools.vodafone-ip.de [2.205.128.37]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: smtp-auth-user) by mail.office.datagis.com (Postfix) with ESMTPSA id 2CC53123 for ; Thu, 17 Feb 2022 10:25:37 +0100 (CET) Message-ID: <3b3ac2ef-c06b-1455-3bfd-70fbaa2571c8@datagis.com> Date: Thu, 17 Feb 2022 10:25:37 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.0 Subject: Re: Strange results when casting string to double Content-Language: en-US To: pgsql-general@lists.postgresql.org References: <0d711ac6-6975-ae07-8963-aa91c6500776@datagis.com> <59632509-6ead-bdaa-8ee4-035db22e530d@gmx.net> From: Carsten Klein Organization: DataGis In-Reply-To: <59632509-6ead-bdaa-8ee4-035db22e530d@gmx.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Df-Sender: NTkwMDE1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Feb 17, 2022 at 09:41 AM Thomas Kellerer wrote: > Carsten Klein schrieb am 16.02.2022 um 14:27: Ah, man versteht sich :) >> I'm using several (now unsupported) PostgreSQL 9.3.24 servers on >> different (ancient) Ubuntu 14.04 LTS machines. On only one of those >> servers, I get strange/wrong results when converting a string into a >> double value: >> >> SELECT 1.56::double precision; >> >> --> 1.55999999999999   (wrong!) >> >> Although I do not find any differences in configuration, on all other servers the result looks like this (correct?): >> >> SELECT 1.56::double precision; >> >> --> 1.56               (correct!) >> > > I wonder if extra_float_digits is different between those systems > Maybe initialized by differently configured SQL clients. As I've seen in the sources in file /src/backend/utils/adt/float.c, extra_float_digits is used when converting double precision values back to text only. The binary (BIT) representation if the double value's fraction (mantissa) tells me, that the actual double precision value is already wrong. Also, extra_float_digits is constantly zero in my tests. I've only been using pgAdmin III for that and always ensured with SELECT current_setting('extra_float_digits'); that it's zero. Carsten