Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdc192a5

Browse files
committed
Convert earthdistance's only C function to v1 call convention,
to future-proof it against pass-by-value float8.
1 parent7c81d79 commitdc192a5

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

‎contrib/earthdistance/earthdistance.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/* $PostgreSQL: pgsql/contrib/earthdistance/earthdistance.c,v 1.13 2006/10/19 20:08:03 tgl Exp $ */
1+
/* $PostgreSQL: pgsql/contrib/earthdistance/earthdistance.c,v 1.14 2008/04/20 01:05:52 tgl Exp $ */
22

33
#include"postgres.h"
44

55
#include<math.h>
66

7-
#include"utils/geo_decls.h"/* forPt */
7+
#include"utils/geo_decls.h"/* forPoint */
88

99
#ifndefM_PI
1010
#defineM_PI 3.14159265358979323846
@@ -14,10 +14,12 @@
1414
PG_MODULE_MAGIC;
1515

1616
/* Earth's radius is in statute miles. */
17-
constdoubleEARTH_RADIUS=3958.747716;
18-
constdoubleTWO_PI=2.0*M_PI;
17+
staticconstdoubleEARTH_RADIUS=3958.747716;
18+
staticconstdoubleTWO_PI=2.0*M_PI;
1919

20-
double*geo_distance(Point*pt1,Point*pt2);
20+
PG_FUNCTION_INFO_V1(geo_distance);
21+
22+
Datumgeo_distance(PG_FUNCTION_ARGS);
2123

2224

2325
/******************************************************
@@ -45,21 +47,22 @@ degtorad(double degrees)
4547
* x-coordinate is longitude in degrees west of Greenwich
4648
* y-coordinate is latitude in degrees above equator
4749
*
48-
* returns:double
50+
* returns:float8
4951
* distance between the points in miles on earth's surface
5052
******************************************************/
5153

52-
double*
53-
geo_distance(Point*pt1,Point*pt2)
54+
Datum
55+
geo_distance(PG_FUNCTION_ARGS)
5456
{
55-
57+
Point*pt1=PG_GETARG_POINT_P(0);
58+
Point*pt2=PG_GETARG_POINT_P(1);
59+
float8result;
5660
doublelong1,
5761
lat1,
5862
long2,
5963
lat2;
6064
doublelongdiff;
6165
doublesino;
62-
double*resultp=palloc(sizeof(double));
6366

6467
/* convert degrees to radians */
6568

@@ -78,7 +81,7 @@ geo_distance(Point *pt1, Point *pt2)
7881
cos(lat1)*cos(lat2)*sin(longdiff /2.)*sin(longdiff /2.));
7982
if (sino>1.)
8083
sino=1.;
81-
*resultp=2.*EARTH_RADIUS*asin(sino);
84+
result=2.*EARTH_RADIUS*asin(sino);
8285

83-
returnresultp;
86+
PG_RETURN_FLOAT8(result);
8487
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp