Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UUk6q-00062K-Mg for pgsql-bugs@arkaria.postgresql.org; Tue, 23 Apr 2013 20:46:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UUk6q-0003FI-73 for pgsql-bugs@arkaria.postgresql.org; Tue, 23 Apr 2013 20:46:40 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UUk6o-0003Dr-Aj for pgsql-bugs@postgresql.org; Tue, 23 Apr 2013 20:46:38 +0000 Received: from nm25-vm0.bullet.mail.bf1.yahoo.com ([98.139.213.156]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UUk6k-0002pD-QT for pgsql-bugs@postgresql.org; Tue, 23 Apr 2013 20:46:37 +0000 Received: from [98.139.212.146] by nm25.bullet.mail.bf1.yahoo.com with NNFMP; 23 Apr 2013 20:46:33 -0000 Received: from [98.139.212.200] by tm3.bullet.mail.bf1.yahoo.com with NNFMP; 23 Apr 2013 20:46:33 -0000 Received: from [127.0.0.1] by omp1009.mail.bf1.yahoo.com with NNFMP; 23 Apr 2013 20:46:33 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 742355.39636.bm@omp1009.mail.bf1.yahoo.com Received: (qmail 89863 invoked by uid 60001); 23 Apr 2013 20:46:33 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ymail.com; s=s1024; t=1366749993; bh=8xXmPuGQmoBYs2+60PVaMRDpNbxx9S1Qxdy6q/nK2Hg=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type; b=ZCzxU28ToYUU2KYnmeQua/Ink8N/llF9VSIzZQQycG8XxFqYRyuZzEfiOHKSsVv0D8RNWIBIUOtUOgaL8nW9i4RB1L7wnt31dfMULUHDcOjRQSE7Se6yeokB6X6wYo2Ke2uHNZFgVMlaqn1zUurVFfDPGqciF90PUWO40ticLZk= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=ymail.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type; b=2K8yA0rJVoey7o2yo79rpxYR6wwzoYt16bufsN3UgkyZ0fWdyqKRvunV+werHUzlgBVkR85f02dvjGFJQr+AcM8NvNbjp04qrW7jxYrZtbfTpezwZmuPqbaVvNK4NYfxXCRnoZ4FRSVKhsAGWkVlyDrTND6ZIQzaeYisESz6DCY=; X-YMail-OSG: 50RPtGIVM1lZ3waRLkgri2crLtuSk5NZ4Ngl5sS1bbXQ7V_ mA44QbPa2_YZDkxver.MCGD2RzkHu6QhJMF2Iau6fDmjERYesdbCww4NzpID HhuncIz_pwjk65Kkm_t5cp3epqRAlUtfj8wtyDpt5Db5iIYPmJcFTUyPYHMv osKV9k3lL6G5mwF8gVpQS2EiCj2eV38nOt.4c4q7MrLnhh85f9QHGgG1wb0o Y1.sQoyx.4XP3wiULduMatAtWyScTPecQmrk5_JXFsyIggtNWGh4me6Luvgi eM4cdHlBn.GMqnBZ1aWSOEl0wKZx9V6Ut4zxPg5PdFp1wGGUGR5NGIKkTYam EBRyYSHVSC4U5RJo16492NjHPzsN4q3O13R2B3cn9i51Bjm_tPBwgng1gPSI MatJv3_NmB_lWNHveLqKS4kS9Q_jEcQ_58JTEDI65G2FsEv7JgcpUrPmsEO0 b37o0tb1GHfVRMKmVaPgA2Jzzsev6Ynnlso_D.r8yQM7mlwcw98xSJaA4xHJ yYLPqcGvPWUDHeAbcbZc9dOJV1N9uWB9lJiR_JAJIMg-- Received: from [76.255.18.237] by web162903.mail.bf1.yahoo.com via HTTP; Tue, 23 Apr 2013 13:46:33 PDT X-Rocket-MIMEInfo: 002.001, S2FuaXRjaGV0IFZhaWFzc2F2YSA8a2FuaWNoZXRAaG90bWFpbC5jb20.IHdyb3RlOgoKPiBbZGl2aXNpb24gYW5kIHNvbWUgbWF0aCBmdW5jdGlvbnMgdXNpbmcgdGhlIG51bWVyaWMgdHlwZSBjYW4KPiBzb21ldGltZXMgaGF2ZSBhIHJlc3VsdCB3aGljaCB0aGUgbnVtZXJpYyB0eXBlIGNhbm5vdCByZXByZXNlbnQKPiBleGFjdGx5XQoKWWVhaCwgeW91IGNhbiB1c2UgYSBzaW1wbGVyIGV4YW1wbGU6Cgp0ZXN0PSMgc2VsZWN0ICcxJzo6bnVtZXJpYyAvICczJzo6bnVtZXJpYzsKwqDCoMKgwqDCoMKgwqAgP2MBMAEBAQE- X-Mailer: YahooMailWebService/0.8.141.536 References: Message-ID: <1366749993.89747.YahooMailNeo@web162903.mail.bf1.yahoo.com> Date: Tue, 23 Apr 2013 13:46:33 -0700 (PDT) From: Kevin Grittner Reply-To: Kevin Grittner Subject: Re: Fw: [pgadmin-support] (Bug) Numeric fault calculation To: Kanitchet Vaiassava , "pgsql-bugs@postgresql.org" Cc: Kanitchet Vaiassava In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="-476738056-1763423821-1366749993=:89747" X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org ---476738056-1763423821-1366749993=:89747 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Kanitchet Vaiassava wrote:=0A=0A> [division and some= math functions using the numeric type can=0A> sometimes have a result whic= h the numeric type cannot represent=0A> exactly]=0A=0AYeah, you can use a s= impler example:=0A=0Atest=3D# select '1'::numeric / '3'::numeric;=0A=A0=A0= =A0=A0=A0=A0=A0 ?column?=A0=A0=A0=A0=A0=A0 =A0=0A------------------------= =0A=A00.33333333333333333333=0A(1 row)=0A=0Atest=3D# select '3'::numeric * = ('1'::numeric / '3'::numeric);=0A=A0=A0=A0=A0=A0=A0=A0 ?column?=A0=A0=A0=A0= =A0=A0 =A0=0A------------------------=0A=A00.99999999999999999999=0A(1 row)= =0A=0A> So I think this problem should be solve? or at least, it should=0A>= be note in document for other developer to be more careful.=0A=0AYeah, the= re should probably be something in the docs to indicate=0Athat not all rati= onal numbers (and certainly no irrational or=0Aimaginary numbers) can be st= ored as a single numeric value without=0Aloss of precision.=0A=0AIt might b= e interesting to create a "rational" type which would=0Ainternally hold two= numeric values, and which would be capable of=0Adoing what you want.=A0 I'= m not sure that the demand is sufficient to=0Aback the development of it, t= hough.=A0 (Is there a convention for how=0Ato indicate the repeating part o= f a decimal fraction when you can't=0Adraw a line over those digits?)=0A=0A= In the absence of such a type, you might want to arrange your=0Acalculation= s such that any division or square root calculations=0Aare done last.=A0 Th= at way the effect of the truncation of the=0Arepeating (or not) infinite de= cimal fraction won't be multiplied by=0Aa later phase of the calculation.= =0A=0A-- =0AKevin Grittner=0AEnterpriseDB: http://www.enterprisedb.com=0ATh= e Enterprise PostgreSQL Company ---476738056-1763423821-1366749993=:89747 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
Kanitchet Vaiassava &= lt;kanichet@hotmail.com> wrote:

> [division and some math func= tions using the numeric type can
> sometimes have a result which the = numeric type cannot represent
> exactly]

Yeah, you can use a s= impler example:

test=3D# select '1'::numeric / '3'::numeric;
&nbs= p;       ?column?    &nbs= p;   
------------------------
 0.33333333333333333333=
(1 row)

test=3D# select '3'::numeric * ('1'::numeric / '3'::nume= ric);
        ?column?  &nb= sp;     
------------------------
 0.9999999= 9999999999999
(1 row)

> So I think this problem should be solv= e? or at least, it should
> be note in document for other developer to be more careful.

Yeah, there should probably be something in the= docs to indicate
that not all rational numbers (and certainly no irrati= onal or
imaginary numbers) can be stored as a single numeric value witho= ut
loss of precision.

It might be interesting to create a "ration= al" type which would
internally hold two numeric values, and which would= be capable of
doing what you want.  I'm not sure that the demand i= s sufficient to
back the development of it, though.  (Is there a co= nvention for how
to indicate the repeating part of a decimal fraction wh= en you can't
draw a line over those digits?)

In the absence of su= ch a type, you might want to arrange your
calculations such that any div= ision or square root calculations
are done last.  That way the effe= ct of the truncation of the
repeating (or not) infinite decimal fraction= won't be multiplied by
a later phase of the calculation.

--
Kevin Grittner
EnterpriseDB: http://www.ente= rprisedb.com
The Enterprise PostgreSQL Company

---476738056-1763423821-1366749993=:89747--