pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Grittner <kgrittn@ymail.com>
To: Kanitchet Vaiassava <kanichet@hotmail.com>
To: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Cc: Kanitchet Vaiassava <kanitchet.vai@thaiace.co.th>
Subject: Re: Fw: [pgadmin-support] (Bug) Numeric fault calculation
Date: Tue, 23 Apr 2013 13:46:33 -0700 (PDT)
Message-ID: <1366749993.89747.YahooMailNeo@web162903.mail.bf1.yahoo.com> (raw)
In-Reply-To: <BAY167-DS485F99836EA5CEAAC93F03D8B40@phx.gbl>
References: <BAY167-DS485F99836EA5CEAAC93F03D8B40@phx.gbl>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Kanitchet Vaiassava <kanichet@hotmail.com> 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=# select '1'::numeric / '3'::numeric;
        ?column?        
------------------------
 0.33333333333333333333
(1 row)

test=# select '3'::numeric * ('1'::numeric / '3'::numeric);
        ?column?        
------------------------
 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.

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

view thread (3+ messages)  latest in thread

Message-ID: <1366749993.89747.YahooMailNeo@web162903.mail.bf1.yahoo.com>
Permalink:  ../1366749993.89747.YahooMailNeo@web162903.mail.bf1.yahoo.com/
Also on:    postgresql.org/message-id/1366749993.89747.YahooMailNeo@web162903.mail.bf1.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: kgrittn@ymail.com, kanichet@hotmail.com, kanitchet.vai@thaiace.co.th
  Subject: Re: Fw: [pgadmin-support] (Bug) Numeric fault calculation
  In-Reply-To: <1366749993.89747.YahooMailNeo@web162903.mail.bf1.yahoo.com>
  References: <BAY167-DS485F99836EA5CEAAC93F03D8B40@phx.gbl> <1366749993.89747.YahooMailNeo@web162903.mail.bf1.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox