Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UWztI-0007e0-H4 for pgsql-bugs@arkaria.postgresql.org; Tue, 30 Apr 2013 02:02:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UWztH-0006ed-Vv for pgsql-bugs@arkaria.postgresql.org; Tue, 30 Apr 2013 02:02:00 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UWztF-0006d0-Hq for pgsql-bugs@postgresql.org; Tue, 30 Apr 2013 02:01:57 +0000 Received: from bay0-omc4-s23.bay0.hotmail.com ([65.54.190.225]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UWztB-0006zr-Cs for pgsql-bugs@postgresql.org; Tue, 30 Apr 2013 02:01:56 +0000 Received: from BAY167-DS30 ([65.54.190.200]) by bay0-omc4-s23.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 29 Apr 2013 19:01:51 -0700 X-EIP: [J9g83Qxzni9UlF25rXdHPd7gzGvcI/wIFghuITno7Ok=] X-Originating-Email: [kanichet@hotmail.com] Message-ID: From: Kanitchet Vaiassava To: CC: "Kanitchet Vaiassava" Subject: Fw: [pgadmin-support] (Bug) Numeric fault calculation Date: Tue, 30 Apr 2013 09:01:46 +0700 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_00C2_01CE4581.580A2280" X-Priority: 3 X-MSMail-Priority: Normal Importance: Normal X-Mailer: Microsoft Windows Live Mail 16.4.3505.912 X-MimeOLE: Produced By Microsoft MimeOLE V16.4.3505.912 X-OriginalArrivalTime: 30 Apr 2013 02:01:51.0723 (UTC) FILETIME=[AE74A3B0:01CE4546] X-Pg-Spam-Score: -4.3 (----) 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 ------=_NextPart_000_00C2_01CE4581.580A2280 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable sent to pgsql-bugs list. Best Regards, Kanitchet Vaiassava 999 Nawamin Rd., Nuanjun, Buengkum, Bangkok 10230, Thailand Mobile +66 89 515 9955; Office +66 2 944 2000 Ext.1204; Fax +66 2 944 = 2020 -------------------------------------------------------------------------= -------------------------------------- From: Kevin Grittner=20 Sent: Wednesday, April 24, 2013 8:34 PM To: Kanitchet Vaiassava=20 Subject: Re: ***(Updated)*** Re: [BUGS] Fw: [pgadmin-support] (Bug) = Numeric fault calculation=20 Hi Kanitchet, It is best to keep the list copied so that everyone is aware of these = things. Could you please resend with a copy to the list? Thanks, -Kevin -------------------------------------------------------------------------= ----- From: Kanitchet Vaiassava To: kgrittn@ymail.com=20 Sent: Tuesday, April 23, 2013 9:46 PM Subject: ***(Updated)*** Re: [BUGS] Fw: [pgadmin-support] (Bug) = Numeric fault calculation=20 Dear Mr.Kevin Grittner First, sorry for another send on this. I=E2=80=99ve tried this on = MySQL server 1# SELECT CAST((3.00 * (1.00/3.00)) AS DECIMAL(15,10)) 2# SELECT CAST(3.00 AS DECIMAL) * (CAST(1.00 AS DECIMAL) / CAST(3.00 = AS DECIMAL)) Result is (same) : 1.0000000000 http://dev.mysql.com/doc/refman/5.5/en/precision-math.html > The MySQL library for fixed-point arithmetic.=20 These features have several implications for numeric operations and = provide a high degree of compliance with standard SQL:=20 PostgreSQL server for postgrsql may treat as numeric to numeric calculation 1/3 =3D 0.333333 0.33333 * 3 =3D 0.99999999 #1 PostgreSQL SELECT (3.00::numeric * (1.00::numeric /3.00::numeric)) Result is : 0.9999999999999999999900 #2 PostgreSQL (However, I don=E2=80=99t know if this should be = 1.0000000000 or maybe postgres auto cast 3.00 to 3.00::numeric) SELECT (3.00 * (1.00 /3.00))::numeric Result is : 0.9999999999999999999900 I knows the demand may not sufficient but if we=E2=80=99re using = library fixed-point arithmetic like MySQL and its not cause development = time so much,=20 please consider this. Thank you Best Regards, Kanitchet Vaiassava ThaiAce Capital Co., Ltd=20 999 Nawamin Rd., Nuanjun, Buengkum, Bangkok 10230, Thailand Mobile +66 89 515 9955; Office +66 2 944 2000 Ext.1204; Fax +66 2 944 = 2020 = -------------------------------------------------------------------------= -------------------------------------- From: Kanitchet Vaiassava=20 Sent: Wednesday, April 24, 2013 8:50 AM To: Kevin Grittner=20 Cc: Kanitchet Vaiassava ; Kanitchet Vaiassava=20 Subject: Re: [BUGS] Fw: [pgadmin-support] (Bug) Numeric fault = calculation Dear Mr.Kevin Grittner Thank you very much for your quick reply with clearly = explanation and useful suggestion. I hope this can be done someway in the future because I think it = affected when we use postgresql to do some calculation about monetary by using SQL or Stored Procedure (that I affected and more when the = money is lage) and maybe affected some critical scientific calculation = that needed to use many multiply & division or others math function that = may result to this problem. Sorry for bad English. Best Regards, Kanitchet Vaiassava ThaiAce Capital Co., Ltd=20 999 Nawamin Rd., Nuanjun, Buengkum, Bangkok 10230, Thailand Mobile +66 89 515 9955; Office +66 2 944 2000 Ext.1204; Fax +66 2 944 = 2020 = -------------------------------------------------------------------------= -------------------------------------- From: Kevin Grittner=20 Sent: Wednesday, April 24, 2013 3:46 AM To: Kanitchet Vaiassava ; pgsql-bugs@postgresql.org=20 Cc: Kanitchet Vaiassava=20 Subject: Re: [BUGS] Fw: [pgadmin-support] (Bug) Numeric fault = calculation Kanitchet Vaiassava wrote: > [division and some math functions using the numeric type can > sometimes have a result which the numeric type cannot represent > exactly] Yeah, you can use a simpler example: test=3D# select '1'::numeric / '3'::numeric; ?column? =20 ------------------------ 0.33333333333333333333 (1 row) test=3D# select '3'::numeric * ('1'::numeric / '3'::numeric); ?column? =20 ------------------------ 0.99999999999999999999 (1 row) > So I think this problem should be solve? 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 irrational or imaginary numbers) can be stored as a single numeric value without loss of precision. It might be interesting to create a "rational" 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 is sufficient to back the development of it, though. (Is there a convention for how to indicate the repeating part of a decimal fraction when you can't draw a line over those digits?) In the absence of such a type, you might want to arrange your calculations such that any division or square root calculations are done last. That way the effect of the truncation of the repeating (or not) infinite decimal fraction won't be multiplied by a later phase of the calculation. --=20 Kevin Grittner EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company ------=_NextPart_000_00C2_01CE4581.580A2280 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
sent to pgsql-bugs list.
 
Best=20 Regards,
Kanitchet Vaiassava

999 Nawamin Rd., Nuanjun, = Buengkum,=20 Bangkok 10230, Thailand
Mobile +66 89 515 9955; Office +66 2 944 2000 = Ext.1204; Fax +66 2 944=20 2020
-----------------------------------------------------------------= ----------------------------------------------
 
Sent: Wednesday, April 24, 2013 8:34 PM
Subject: Re: ***(Updated)*** Re: [BUGS] Fw: = [pgadmin-support] (Bug)=20 Numeric fault calculation
 
Hi=20 Kanitchet,

It is best to keep the list copied so that everyone is = aware=20 of these things.  Could you please resend with a copy to the=20 list?

Thanks,

-Kevin



From:=20 Kanitchet Vaiassava <kanichet@hotmail.com>
To: kgrittn@ymail.com =
Sent: Tuesday, April 23, 2013 = 9:46=20 PM
Subject: = ***(Updated)***=20 Re: [BUGS] Fw: [pgadmin-support] (Bug) Numeric fault calculation=20

Dear Mr.Kevin Grittner
 
     First, sorry for another = send on=20 this. I=E2=80=99ve tried this on
 
MySQL server
1# SELECT = CAST((3.00  *=20 (1.00/3.00)) AS DECIMAL(15,10))
2# SELECT CAST(3.00 AS = DECIMAL) *=20 (CAST(1.00 AS DECIMAL) / CAST(3.00 AS DECIMAL))
Result is = (same) :=20 1.0000000000
http://dev.mysql.com/doc/refman/5.5/en/precision-math.html
> The=20 MySQL library for fixed-point arithmetic.
These features=20 have several implications for numeric operations and provide a high = degree of=20 compliance with standard SQL:
 
PostgreSQL server
for postgrsql may treat as numeric to numeric=20 calculation
1/3 =3D 0.333333
0.33333 * 3 =3D 0.99999999
#1
PostgreSQL
SELECT (3.00::numeric * = (1.00::numeric /3.00::numeric))
Result is : = 0.9999999999999999999900
 
#2
PostgreSQL = (However, I=20 don=E2=80=99t know if this should be 1.0000000000 or maybe postgres = auto cast 3.00 to=20 3.00::numeric)
SELECT (3.00 * (1.00=20 /3.00))::numeric
Result is : = 0.9999999999999999999900
 
I = knows the=20 demand may not sufficient but if we=E2=80=99re using library = fixed-point=20 arithmetic like MySQL and its not cause development time so = much,=20
please=20 consider = this.
 
Thank you
 
 
Best=20 Regards,
Kanitchet Vaiassava

ThaiAce Capital Co., Ltd =
999=20 Nawamin Rd., Nuanjun, Buengkum, Bangkok 10230, Thailand
Mobile +66 = 89 515=20 9955; Office +66 2 944 2000 Ext.1204; Fax +66 2 944=20 = 2020
-----------------------------------------------------------------= ----------------------------------------------
 
Sent: Wednesday, April 24, 2013 8:50 AM
Cc: Kanitchet Vaiassava = ; Kanitchet = Vaiassava=20
Subject: Re: [BUGS] Fw: [pgadmin-support] (Bug) Numeric = fault=20 calculation
 
Dear Mr.Kevin Grittner
 
       Thank you = very much for=20 your quick reply with clearly explanation and useful = suggestion.
I hope this can be done someway in the future = because I=20 think it affected when we use postgresql to do some calculation about=20 monetary
by using SQL or Stored Procedure (that I affected = and more=20 when the money is lage) and maybe affected some critical scientific=20 calculation that needed to use many multiply & division or others = math=20 function that may result to this = problem.
 
Sorry for bad English.
 
Best=20 Regards,
Kanitchet Vaiassava

ThaiAce Capital Co., Ltd =
999=20 Nawamin Rd., Nuanjun, Buengkum, Bangkok 10230, Thailand
Mobile +66 = 89 515=20 9955; Office +66 2 944 2000 Ext.1204; Fax +66 2 944=20 = 2020
-----------------------------------------------------------------= ----------------------------------------------
 
Sent: Wednesday, April 24, 2013 3:46 AM
To: Kanitchet Vaiassava ; pgsql-bugs@postgresql.org=20
Subject: Re: [BUGS] Fw: [pgadmin-support] (Bug) Numeric = fault=20 calculation
 
Kanitchet=20 Vaiassava <kanichet@hotmail.com> wrote:

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

Yeah, = you can=20 use a simpler example:

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

test=3D# select '3'::numeric * ('1'::numeric /=20 '3'::numeric);
       =20 ?column?       =20
------------------------
0.99999999999999999999
(1 = row)

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

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

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

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

--
Kevin Grittner
EnterpriseDB:=20 http://www.enterprisedb.com
The Enterprise PostgreSQL=20 = Company



------=_NextPart_000_00C2_01CE4581.580A2280--