Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > Re: rounding pr...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 10 of 36 Topic 15511 of 17437
Post > Topic >>

Re: rounding problems

by justin@[EMAIL PROTECTED] (Justin) May 12, 2008 at 06:37 PM

I guess i have not been very clear.

lets take this
    select (9/10), (9/10)::numeric, (9::numeric/10::numeric), (9./10),
(9*.1)

With the given select statement i  expected the results all to be same,
especially sense it cast 4 of the 5 to numeric either with explicit cast
or by containing a decimal.  Instead postgresql cast the  first 2
calculations to integer, it then uses integer math so the result is 0.

To Add further conversion to my small brain there is a specific type
cast to the second calculation but it still returned 0.  Not what i
would have expected.  After thinking about it for say 10 seconds, i see
that Postgresql is following the order of operation in the 2nd
calculation where it does integer math then cast the results to numeric.

I made the incorrect assumption Postgresql would have casted all the
arguments to numeric then done the math.  After thinking this through
for a short bit i see why postgresql is casting the arguments to integer
type as numeric/floating point math can be a pretty heavy hit
performance wise.

So this prompts the question how does postgresql decide what types to
cast arguments to.  It seems thus far if a decimal is found in the
argument its numeric and everything else is assumed to be integer if it
does not contain a decimal point.




Craig Ringer wrote:
> Justin wrote:
>> I tried casting them to numeric and it was still wrong
>
> How do the results differ from what you expect? You've posted a bunch 
> of code, but haven't explained what you think is wrong with the results.
>
> Can you post a couple of SMALL examples and explain how the results 
> are different from what you expect them to be?
>
> Try the example using the following formats for the literals in your 
> test:
>
>    2.0
>    '2.0'::numeric      (this is a BCD decimal)
>    '2.0'::float4         (this is a C++/IEEE "float")
>    '2.0'::float8         (this is a C++/IEEE "double")
>
> and see how the results differ.
>
> -- 
> Craig Riniger
>



-- 
Sent via pgsql-general mailing list (pgsql-general@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
 




 36 Posts in Topic:
rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 13:48:16 
Re: rounding problems
lyeoh@[EMAIL PROTECTED]   2008-05-13 02:07:09 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 14:54:47 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 15:08:11 
Re: rounding problems
craig@[EMAIL PROTECTED]   2008-05-13 04:29:06 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 17:02:30 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 17:09:57 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 17:23:15 
Re: rounding problems
craig@[EMAIL PROTECTED]   2008-05-13 05:50:16 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 18:37:02 
Re: rounding problems
aanderson@[EMAIL PROTECTE  2008-05-12 19:04:13 
Re: rounding problems
sam@[EMAIL PROTECTED] (S  2008-05-13 02:20:18 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 22:51:42 
Re: rounding problems
craig@[EMAIL PROTECTED]   2008-05-13 11:42:09 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-13 00:16:06 
Re: rounding problems
xof@[EMAIL PROTECTED] (C  2008-05-12 14:53:21 
Re: rounding problems
craig@[EMAIL PROTECTED]   2008-05-13 05:26:46 
Re: rounding problems
aanderson@[EMAIL PROTECTE  2008-05-12 14:18:57 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 14:49:48 
Re: rounding problems
tometzky@[EMAIL PROTECTED  2008-05-13 08:40:41 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-13 11:30:48 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-13 13:29:07 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-13 14:36:18 
Re: rounding problems
sam@[EMAIL PROTECTED] (S  2008-05-14 15:38:17 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-14 11:47:52 
Re: rounding problems
sam@[EMAIL PROTECTED] (S  2008-05-14 17:26:30 
Re: rounding problems
sam@[EMAIL PROTECTED] (S  2008-05-14 20:27:19 
Re: rounding problems
aanderson@[EMAIL PROTECTE  2008-05-14 16:02:32 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-14 16:08:54 
Re: rounding problems
aanderson@[EMAIL PROTECTE  2008-05-14 16:24:58 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-14 16:55:49 
Re: rounding problems
glene77is <glen.e77is@  2008-05-20 03:19:20 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-20 10:28:28 
Re: rounding problems
aanderson@[EMAIL PROTECTE  2008-05-12 15:56:30 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-13 13:01:11 
Re: rounding problems
doug@[EMAIL PROTECTED] (  2008-05-13 12:12:07 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 11:51:25 CST 2008.