Re: Rounding/create C function question

From: wieck(at)debis(dot)com (Jan Wieck)
To: Robert <robert(at)robert(dot)cz>
Cc: pgsql-general(at)postgreSQL(dot)org
Subject: Re: Rounding/create C function question
Date: 2000-04-26 17:26:36
Message-ID: m12kVa8-0003knC@orion.SAPserv.Hamburg.dsh.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

[Charset iso-8859-2 unsupported, filtering to ASCII...]
> Hi,
>
> I need some custom rounding function (say 1 or two decimal points),
> what would be the simplest way to make one?
>
> - Robert
>
>
>
> P.S. I tried to create one in C like
>
> #include <string.h>
> #include "postgres.h"
>
> double tst5(double x) {
> return x; // ... whatever needed
> }
>
> and compiled it with (on RadHat 6.1, PG 6.5.3)
>
> gcc -I/usr/include/pgsql -fPIC -shared
> -o libeucto.so.0.0.2 -Wl,-soname,libeucto.so.0.0.2 eucto_round.c
>
> CREATE FUNCTION tst5(float8) RETURNS float8
> AS '/mnt/lotrando_c/projekty/eucto/bin/libeucto.so.0.0.2' LANGUAGE
> 'c';
>
> This works as long as the function is int4/int4, but for float8 'backend
> terminated abnormally'. Thanks for any help.

float8 is passed by reference (pointer), not by value. Look
into the existing functions mucking with float8 ...

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#========================================= wieck(at)debis(dot)com (Jan Wieck) #

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Luiz Antonio 2000-04-26 17:28:49 How to connect using pg_connect function from php3 ?
Previous Message Jim Mercer 2000-04-26 17:22:11 pgsql/php3/apache authentication