Re: [GENERAL] Linking in sin() as a C function - Mailing list pgsql-general

From Sevo Stille
Subject Re: [GENERAL] Linking in sin() as a C function
Date
Msg-id 38981237.91256F11@ip23.net
Whole thread Raw
In response to Re: [GENERAL] Linking in sin() as a C function  (mathprof@bigfoot.com)
List pgsql-general
mathprof@bigfoot.com wrote:
>
> Thanks! Based on this, I created a file called "test.c" as follows:
>
> #include <math.h>
> float pg_sin(float *x) {return(sin(*x));}
>
> and compiled it using: "gcc test.c -lm -shared" to create a shared object
> file. I then tried the same steps as below (substituting
> "/usr/lib/libm.so" with the path to my "a.out" file created by gcc), but
> this still didn't work? I'm getting different wrong values, but they're
> still wrong nonetheless?


The return has to be a pointer too. Try:

#include <math.h>
#include "postgres.h"
#include "utils/palloc.h"

float *pg_sin(float *x){
    float *f = (float *)palloc(sizeof(float));
     *f = sin(*x);
    return f;
}


Sevo

--
Sevo Stille
sevo@ip23.net

pgsql-general by date:

Previous
From: Adriaan Joubert
Date:
Subject: Re: [GENERAL] PL/pgSQL syntax/usage question
Next
From: Patrick Welche
Date:
Subject: Re: [GENERAL] VACUUM ANALYSE