Re: [HACKERS] Fixing geometic calculation

2009-08-08 Thread marcin mank
On Sat, Aug 8, 2009 at 3:07 AM, Paul Matthewsp...@netspace.net.au wrote: IEEE754 does not allow two number X and Y, such that X!=Y and (X-Y)==0. And since IEEE754 has been around since the 70's or 80's I think we can start relying on its existence and behavior by now. You are correct, I

Re: [HACKERS] Fixing geometic calculation

2009-08-08 Thread Paul Matthews
marcin mank wrote: You are correct, I think, though this does not solve the division problem: As a first goal I'm just attempting to reduce the EPSILON from 1.0E-6 down to 1.0E-015 (give or take). The current regression test suite works fine down to 1.0E-09. At 1.0E-10 errors appear, not in

Re: [HACKERS] Fixing geometic calculation

2009-08-07 Thread Kenneth Marshall
On Fri, Aug 07, 2009 at 11:29:47PM +1000, Paul Matthews wrote: Let us consider the ordering of real numbers in postgres. As you can see from the results below it has clearly returned the correct results. select( 1. = 1.0002 ); = f select( 1.

Re: [HACKERS] Fixing geometic calculation

2009-08-07 Thread Kenneth Marshall
On Fri, Aug 07, 2009 at 09:12:34AM -0500, Kenneth Marshall wrote: On Fri, Aug 07, 2009 at 11:29:47PM +1000, Paul Matthews wrote: Let us consider the ordering of real numbers in postgres. As you can see from the results below it has clearly returned the correct results. select(

Re: [HACKERS] Fixing geometic calculation

2009-08-07 Thread Sam Mason
On Fri, Aug 07, 2009 at 09:49:41AM -0500, Kenneth Marshall wrote: On Fri, Aug 07, 2009 at 09:12:34AM -0500, Kenneth Marshall wrote: On Fri, Aug 07, 2009 at 11:29:47PM +1000, Paul Matthews wrote: We have two points with a finite separation in the x axis. Postgres thinks they are not the

Re: [HACKERS] Fixing geometic calculation

2009-08-07 Thread Kenneth Marshall
On Fri, Aug 07, 2009 at 04:16:56PM +0100, Sam Mason wrote: On Fri, Aug 07, 2009 at 09:49:41AM -0500, Kenneth Marshall wrote: On Fri, Aug 07, 2009 at 09:12:34AM -0500, Kenneth Marshall wrote: On Fri, Aug 07, 2009 at 11:29:47PM +1000, Paul Matthews wrote: We have two points with a finite

Re: [HACKERS] Fixing geometic calculation

2009-08-07 Thread Tom Lane
Sam Mason s...@samason.me.uk writes: I would agree with Paul that EPSILON is a hack and probably should be removed. It's a hack but it's dealing with an extremely real problem, namely the built-in inaccuracy of floating-point arithmetic. You can't just close your eyes to that and hope that

Re: [HACKERS] Fixing geometic calculation

2009-08-07 Thread Sam Mason
On Fri, Aug 07, 2009 at 10:29:27AM -0500, Kenneth Marshall wrote: On Fri, Aug 07, 2009 at 04:16:56PM +0100, Sam Mason wrote: points in PG [..] don't arbitrarily go jumping off millions of miles away or being annihilated by their anti-particle just because it's possible. It was definitely

Re: [HACKERS] Fixing geometic calculation

2009-08-07 Thread Sam Mason
On Fri, Aug 07, 2009 at 11:40:58AM -0400, Tom Lane wrote: Sam Mason s...@samason.me.uk writes: I would agree with Paul that EPSILON is a hack and probably should be removed. It's a hack but it's dealing with an extremely real problem, namely the built-in inaccuracy of floating-point

Re: [HACKERS] Fixing geometic calculation

2009-08-07 Thread Tom Lane
Sam Mason s...@samason.me.uk writes: Sorry, I'm struggling to parse that. I think it's all the double negatives. Are you saying that HYPOT() should really return zero when it's currently giving back would be FPzero? No, I'm worried about code that supposes that it can divide by (x - y) after

Re: [HACKERS] Fixing geometic calculation

2009-08-07 Thread Sam Mason
On Fri, Aug 07, 2009 at 12:50:39PM -0400, Tom Lane wrote: Sam Mason s...@samason.me.uk writes: Sorry, I'm struggling to parse that. I think it's all the double negatives. Are you saying that HYPOT() should really return zero when it's currently giving back would be FPzero? No, I'm

Re: [HACKERS] Fixing geometic calculation

2009-08-07 Thread Tom Lane
Sam Mason s...@samason.me.uk writes: On Fri, Aug 07, 2009 at 12:50:39PM -0400, Tom Lane wrote: No, I'm worried about code that supposes that it can divide by (x - y) after testing that FPeq(x,y) is not true. point_sl() for instance. OK, but I'm still not sure what you're getting at.

Re: [HACKERS] Fixing geometic calculation

2009-08-07 Thread Sam Mason
On Fri, Aug 07, 2009 at 02:13:26PM -0400, Tom Lane wrote: Sam Mason s...@samason.me.uk writes: On Fri, Aug 07, 2009 at 12:50:39PM -0400, Tom Lane wrote: No, I'm worried about code that supposes that it can divide by (x - y) after testing that FPeq(x,y) is not true. point_sl() for instance.

Re: [HACKERS] Fixing geometic calculation

2009-08-07 Thread Greg Stark
On Fri, Aug 7, 2009 at 7:13 PM, Tom Lanet...@sss.pgh.pa.us wrote: Sam Mason s...@samason.me.uk writes: On Fri, Aug 07, 2009 at 12:50:39PM -0400, Tom Lane wrote: No, I'm worried about code that supposes that it can divide by (x - y) after testing that FPeq(x,y) is not true.  point_sl() for

Re: [HACKERS] Fixing geometic calculation

2009-08-07 Thread Sam Mason
On Fri, Aug 07, 2009 at 07:48:15PM +0100, Greg Stark wrote: On Fri, Aug 7, 2009 at 7:13 PM, Tom Lanet...@sss.pgh.pa.us wrote: Underflow. x!=y does not imply (x-y) != 0, if x and y are sufficiently small and close together. The difference could underflow to zero. Actually I don't think

Re: [HACKERS] Fixing geometic calculation

2009-08-07 Thread Paul Matthews
Tom Lane wrote: It's a hack but it's dealing with an extremely real problem, namely the built-in inaccuracy of floating-point arithmetic. You can't just close your eyes to that and hope that everything will be okay. If the above statement was true, then the FP* macros should be extended to

Re: [HACKERS] Fixing geometic calculation

2009-08-07 Thread Paul Matthews
Tom Lane wrote: No, I'm worried about code that supposes that it can divide by (x - y) after testing that FPeq(x,y) is not true. point_sl() for instance. We could perhaps fix those specific issues by testing the difference explicitly instead of doing it like that. But there's still the

Re: [HACKERS] Fixing geometic calculation

2009-08-07 Thread Paul Matthews
Paul Matthews wrote: EPSILON in postgres is 1.0E-06 EPSILON for floats is 1.19209e-07 EPSILON for doubles is 2.22045E-016 Bad form to reply to my own post and all. If EPSILON for double represented 1mm, then postgres is rounding to the nearest 10,000,000 km. Since its only about