Re: somebody could explain this? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: somebody could explain this?
Date
Msg-id 14460.1131122991@sss.pgh.pa.us
Whole thread Raw
In response to somebody could explain this?  ("Cristian Prieto" <cristian@clickdiario.com>)
List pgsql-hackers
"Cristian Prieto" <cristian@clickdiario.com> writes:
> Datum
> repeat_item(PG_FUNCTION_ARGS)
> {
>     int num_times;
>     num_times = PG_GETARG_FLOAT8(0) * 100;
>     PG_RETURN_INT32(num_times);
> }

> # Create or replace function test(float) returns integer as 'test.so'
> language 'c' stable;

"float" is FLOAT4 not FLOAT8 ... your function is picking up some
garbage data.

There might also be some roundoff issues to think about --- I'd be
inclined to add an rint() call, or at least add 0.5 before truncating to
integer.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: somebody could explain this?
Next
From: mark@mark.mielke.cc
Date:
Subject: Re: Reducing the overhead of NUMERIC data