From: | Daniel Vázquez <daniel2d2art(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Same double precision operations, different results |
Date: | 2014-02-25 13:00:20 |
Message-ID: | CA+KJVfycFi-VZAigzb+bj-XKccK4+97VHj-ouDz60TB4CeoFig@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Thx Tom!!
Yep, I focused on all trigonometric functions take arguments and return
values of type double precision. Looking for the error I lost focus on
numeric values directly on the select and diff inner calculations.
I think best approach will be maintain double precision on trigonometric
calculations for faster and cast to numeric before acos operation.
Thank you man!
2014-02-13 18:26 GMT+01:00 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> =?ISO-8859-1?Q?Daniel_V=E1zquez?= <daniel2d2art(at)gmail(dot)com> writes:
> > Please can someone tell me why this behavior? Thx!!
>
> You're confusing numeric and double precision; in particular this
> calculation is *not* being done in float8, but numeric:
>
> > # select (0.766238989559398 * 0.766238989559398 * 1 + 0.642555686986733 *
> > 0.642555686986733) calc;
>
> > (*) Why this calculation produces 1 and not
> 0.999999999999999633651488135693
>
> Actually, it's not producing 1, but a smidgen more:
>
> regression=# set extra_float_digits TO 3;
> SET
> regression=# select ( cast (
> cos(radians(39.9826557))
> * cos(radians(39.9826557))
> * cos(radians(-0.04773120000004383) - radians(-0.04773120000004383))
> + sin(radians(39.9826557))
> * sin(radians(39.9826557)) as double precision )
> );
> float8
> ---------------------
> 1.00000000000000022
> (1 row)
>
> You've got roundoff error either way, but this way happens to be in the
> direction that makes acos() complain.
>
> regards, tom lane
>
From | Date | Subject | |
---|---|---|---|
Next Message | Andreas 'ads' Scherbaum | 2014-02-25 13:28:52 | Re: GSoC 2014 - mentors, students and admins |
Previous Message | Greg Stark | 2014-02-25 12:59:50 | Re: typemode for variable types |