|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
BUG #5150: math bugThe following bug has been logged online: Bug reference: 5150 Logged by: Gray Email address: gray@... PostgreSQL version: 8.2.6 Operating system: i686-pc-linux-gnu Description: math bug Details: select 1/3*3,(1.0/3.0)*3.0,floor((1.0/3.0)*3.0); returns 0, 1, 0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@...) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs |
|
|
Re: BUG #5150: math bugOn Fri, Oct 30, 2009 at 1:39 AM, Gray <gray@...> wrote:
> > The following bug has been logged online: > > Bug reference: 5150 > Logged by: Gray > Email address: gray@... > PostgreSQL version: 8.2.6 > Operating system: i686-pc-linux-gnu > Description: math bug > Details: > > select 1/3*3,(1.0/3.0)*3.0,floor((1.0/3.0)*3.0); > > returns > 0, 1, 0 Well, the first answer is correct, because 1/3 is a request for integer division, so you get 0, and 0 * 3 is still zero. I don't believe the second answer is really what you got, because surely if you requested floating-point division the answer would be a floating point number, not just 1. On pg 8.3.8, I get 0.999999999999999999990, which explains why the third answer comes out to zero. In general, floating point arithmetic is inaccurate and sucky. That has nothing to do with PostgreSQL; it's just life. http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems ...Robert -- Sent via pgsql-bugs mailing list (pgsql-bugs@...) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs |
|
|
Re: BUG #5150: math bugRobert Haas <robertmhaas@...> writes:
> In general, floating point arithmetic is inaccurate and sucky. That > has nothing to do with PostgreSQL; it's just life. Actually, I think these examples are being done in "numeric" not float8. Your comment stands though --- 1.0/3.0 does not give the exact rational number 1/3, but some finite decimal approximation to it, which when multiplied by 3 will not produce exactly 1.0. There is special-purpose software out there that can compute exactly with rational numbers, but you aren't likely to find it embedded in any general-purpose tools like databases --- the use-case just isn't wide enough. One reason why not is that it'll still fall down on irrational numbers. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@...) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs |
|
|
Re: BUG #5150: math bugTom Lane wrote:
> There is special-purpose software out there that can compute exactly > with rational numbers, but you aren't likely to find it embedded in any > general-purpose tools like databases --- the use-case just isn't wide > enough. One reason why not is that it'll still fall down on irrational > numbers. > <nit> 1/3 is a rational number. however, it is a repeating fraction when expressed in decimal. </nit> -- Sent via pgsql-bugs mailing list (pgsql-bugs@...) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs |
|
|
Re: BUG #5150: math bugOn Fri, Oct 30, 2009 at 08:51:57PM -0700, John R Pierce wrote:
> Tom Lane wrote: >> There is special-purpose software out there that can compute >> exactly with rational numbers, but you aren't likely to find it >> embedded in any general-purpose tools like databases --- the >> use-case just isn't wide enough. One reason why not is that it'll >> still fall down on irrational numbers. >> > > > <nit> > > 1/3 is a rational number. however, it is a repeating fraction when > expressed in decimal. > > </nit> <nit level="2"> The set of algebraic numbers, of which rational numbers are a proper subset, is countable and hence has Lebesgue measure zero on the real line. </nit> ;) Cheers, David. -- David Fetter <david@...> http://fetter.org/ Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter Skype: davidfetter XMPP: david.fetter@... iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate -- Sent via pgsql-bugs mailing list (pgsql-bugs@...) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs |
|
|
Re: BUG #5150: math bugOn Fri, Oct 30, 2009 at 11:51 PM, John R Pierce <pierce@...> wrote:
> Tom Lane wrote: >> >> There is special-purpose software out there that can compute exactly >> with rational numbers, but you aren't likely to find it embedded in any >> general-purpose tools like databases --- the use-case just isn't wide >> enough. One reason why not is that it'll still fall down on irrational >> numbers. >> > > > <nit> > > 1/3 is a rational number. however, it is a repeating fraction when > expressed in decimal. > > </nit> That's true. Nobody said otherwise. ...Robert -- Sent via pgsql-bugs mailing list (pgsql-bugs@...) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs |
|
|
Re: BUG #5150: math bugDavid Fetter wrote:
> On Fri, Oct 30, 2009 at 08:51:57PM -0700, John R Pierce wrote: > >> Tom Lane wrote: >> >>> There is special-purpose software out there that can compute >>> exactly with rational numbers, but you aren't likely to find it >>> embedded in any general-purpose tools like databases --- the >>> use-case just isn't wide enough. One reason why not is that it'll >>> still fall down on irrational numbers. >>> >>> >> <nit> >> >> 1/3 is a rational number. however, it is a repeating fraction when >> expressed in decimal. >> >> </nit> >> > > <nit level="2"> > The set of algebraic numbers, of which rational numbers are a proper > subset, is countable and hence has Lebesgue measure zero on the real > line. > </nit> ;) > > LOL - fortunately (going by the bug) he is not trying to compute a measure (i.e integrate) from a set of 'em. Mark -- Sent via pgsql-bugs mailing list (pgsql-bugs@...) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs |
| Free embeddable forum powered by Nabble | Forum Help |