From: | Karel Zak - Zakkr <zakkr(at)zf(dot)jcu(dot)cz> |
---|---|
To: | Manuel Weindorf <weindorf(at)ipf(dot)uni-karlsruhe(dot)de> |
Cc: | pgsql-interfaces(at)postgreSQL(dot)org |
Subject: | Re: [INTERFACES] Problem with C functions ? |
Date: | 1999-11-12 10:16:33 |
Message-ID: | Pine.LNX.3.96.991112110926.19414A-100000@ara.zf.jcu.cz |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-interfaces |
On Fri, 12 Nov 1999, Manuel Weindorf wrote:
> Hi there,
>
> I compiled a C-funtion to compute the azimuth of a LSEG but the function
> never
> returns the correct value, but elog( ... ) report the correct value.
> So there seems to be a problem returning doubles or floats ??
>
> compile the folling function with
> gcc -fPIC -O2 -shared -o lseg_azimuth.o -c lseg_azimuth.c
> -I/opt/local/postgres/include -L/opt/local/postgres/lib
> ld -G -Bdynamic -o libgeom.so lseg_azimuth.o
>
> #include <math.h>
>
> #include "postgres.h"
> #include "utils/geo_decls.h"
>
> double lseg_azimuth( LSEG* lseg );
> float add_one( float arg );
>
> double lseg_azimuth( LSEG* lseg )
> {
> double x1, y1;
> double x2, y2;
> double ori;
>
> x1 = lseg->p[0].x;
> y1 = lseg->p[0].y;
>
> x2 = lseg->p[1].x;
> y2 = lseg->p[1].y;
>
> ori = atan2( (x2-x1), (y2-y1));
> ori = (ori / M_PI) * 200.0;
>
> if ( ori < 0.0 )
> ori += 400.0;
>
> elog( NOTICE, "ori = %8.3lf", ori );
>
> return( ori );
> }
(See in PgSQL source code src/backend/utils/adt/ and geo routines).
Try this:
double*
lseg_azimuth( LSEG* lseg )
{
double *result = (double) palloc(sizeof(double));
......
*result = any_value;
......
return result;
}
Karel
------------------------------------------------------------------------------
Karel Zak <zakkr(at)zf(dot)jcu(dot)cz> http://home.zf.jcu.cz/~zakkr/
Docs: http://docs.linux.cz (big docs archive)
Kim Project: http://home.zf.jcu.cz/~zakkr/kim/ (process manager)
FTP: ftp://ftp2.zf.jcu.cz/users/zakkr/ (C/ncurses/PgSQL)
------------------------------------------------------------------------------
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Meskes | 1999-11-12 13:10:51 | Re: [INTERFACES] my problems with ecpg and arrays |
Previous Message | Rolf Lüttecke | 1999-11-12 10:06:14 | Re: [INTERFACES] RE: THE Postgres WEB SITE |