Received: from ipfu2.bau-verm.uni-karlsruhe.de (ipfu2.bau-verm.uni-karlsruhe.de [129.13.144.84]) by hub.org (8.9.3/8.9.3) with SMTP id EAA15979 for ; Fri, 12 Nov 1999 04:47:56 -0500 (EST) (envelope-from weindorf@ipf.uni-karlsruhe.de) Received: from ipf.uni-karlsruhe.de(ipfu2.bau-verm.uni-karlsruhe.de[129.13.144.84]) (2235 bytes) by ipfu2.bau-verm.uni-karlsruhe.de via sendmail with P:esmtp/R:inet_hosts/T:smtp (sender: ) id for ; Fri, 12 Nov 1999 10:47:55 +0100 (MET) (Smail-3.2.0.101 1997-Dec-17 #3 built DST-Jun-8) Sender: weindorf Message-ID: <382BE24B.C370A0ED@ipf.uni-karlsruhe.de> Date: Fri, 12 Nov 1999 10:47:55 +0100 From: Manuel Weindorf Organization: IPF, Karlsruhe University X-Mailer: Mozilla 4.5 [en] (X11; I; SunOS 5.6 sun4u) X-Accept-Language: en MIME-Version: 1.0 To: pgsql-interfaces@postgresql.org Subject: Problem with C functions ? Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 #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 ); } then use: create function lseg_azimuth(lseg) returns float8 as ' ... path to the shared lib you just created ...' language 'c'; create table xxx (geometry lseg); insert into xxx (geometry) values ('[(4148.675,5414.255),(4151.405,5414.255)]'); select lseg_azimuth(geometry) from xxx; will return: NOTICE: ori = 100.000 lseg_azimuth ------------ 4148.675 (1 row) But that's obviously not what it should be ... Maybe you have any suggestions ? many thanks Manuel -- Manuel Weindorf (weindorf@ipf.bau-verm.uni-karlsruhe.de) Institut fuer Photogrammetrie und Fernerkundung, Universitaet Karlsruhe Postfach 6980 D-76128 Karlsruhe Tel. +49721 6086010 Fax +49721 694568 http://www-ipf.bau-verm.uni-karlsruhe.de