dbTalk Databases Forums  

[BUGS] BUG #1888: bug in cast from float4 to float8

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] BUG #1888: bug in cast from float4 to float8 in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Pablo Oses
 
Posts: n/a

Default [BUGS] BUG #1888: bug in cast from float4 to float8 - 09-17-2005 , 06:49 AM







The following bug has been logged online:

Bug reference: 1888
Logged by: Pablo Oses
Email address: opablo (AT) gmail (DOT) com
PostgreSQL version: 8.0.x and 7.2.x
Operating system: redhat, slackware and win32
Description: bug in cast from float4 to float8
Details:

this is *really* simple

execute something like this:
select cast(123.456::float4 as float8)

what do you think its the answer ? 123.456 ?

well pgsql 7.2.2, 8.0.0, 8.0.1 and 8.0.3 (all i have used) answers this:
123.456001281738 which is WRONG

bye and thanks for a wonderfull contribution for the free software comunity

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] BUG #1888: bug in cast from float4 to float8 - 09-17-2005 , 08:48 AM






"Pablo Oses" <opablo (AT) gmail (DOT) com> writes:
Quote:
select cast(123.456::float4 as float8)

what do you think its the answer ? 123.456 ?

well pgsql 7.2.2, 8.0.0, 8.0.1 and 8.0.3 (all i have used) answers this:
123.456001281738 which is WRONG
This is not a bug. Please go learn something about floating-point
arithmetic (or if you don't care to, use type numeric instead).

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq


Reply With Quote
  #3  
Old   
Michael Fuhr
 
Posts: n/a

Default Re: [BUGS] BUG #1888: bug in cast from float4 to float8 - 09-17-2005 , 08:54 AM



On Sat, Sep 17, 2005 at 04:00:50AM +0100, Pablo Oses wrote:
Quote:
select cast(123.456::float4 as float8)

what do you think its the answer ? 123.456 ?

well pgsql 7.2.2, 8.0.0, 8.0.1 and 8.0.3 (all i have used) answers this:
123.456001281738 which is WRONG
Float4 has a precision of only about 6 digits, so you can't assume
much about the digits beyond that. See the documentation for
floating-point types:

http://www.postgresql.org/docs/8.0/i...DATATYPE-FLOAT

This is hardly a behavior unique to PostgreSQL; use a search engine
to find explanations of the problems of using binary floating-point
numbers.

If you need exact results then use the numeric type.

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.