Re: [GENERAL] Linking in sin() as a C function

From: Sevo Stille <sevo(at)ip23(dot)net>
To: Karel Zak - Zakkr <zakkr(at)zf(dot)jcu(dot)cz>
Cc: mathprof(at)bigfoot(dot)com, pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] Linking in sin() as a C function
Date: 2000-02-01 12:06:37
Message-ID: 3896CC4D.1A3E393@ip23.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Karel Zak - Zakkr wrote:
>
> On Mon, 31 Jan 2000 mathprof(at)bigfoot(dot)com wrote:
>
> > I tried the following, one at a time, to create sin() for PostgreSQL:
> >
> > CREATE FUNCTION sin(float8) RETURNS float8 AS '/usr/lib/libm.so' LANGUAGE 'c';
> > CREATE FUNCTION sin(float4) RETURNS float4 AS '/usr/lib/libm.so' LANGUAGE 'c';
> > CREATE FUNCTION sin(float4) RETURNS float8 AS '/usr/lib/libm.so' LANGUAGE 'c';
> > CREATE FUNCTION sin(float8) RETURNS float4 AS '/usr/lib/libm.so' LANGUAGE 'c';
> >
> > Each of these gave different and odd results (and a 'segmentation fault'
> > at one point), but none of them gave the right answer. What am I doing
> > wrong?
>
> Yes, it is probably wrong. Very offen PG's buildin functions allocate memory
> for result and IMHO your trial wrong mixing pointers. See a backend/utils/atd
> in PG source as example.

More specifically, only 1,2 and 4 byte integer values may be passed by
call-by-value to userdefined C functions in PostgreSQL. That is, floats
are passed by reference (pointers) while the math lib passes them by
value - you have to write your own wrappers around the mathlib sin
function.

Sevo

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jose Soares 2000-02-01 13:21:46 Re: [GENERAL] Use of datepart() on TimeStamp.
Previous Message Nicolas Huillard 2000-02-01 12:02:04 Rebuilding 6.5.3 RPMs