Re: somebody could explain this?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Cristian Prieto" <cristian(at)clickdiario(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: somebody could explain this?
Date: 2005-11-04 16:49:51
Message-ID: 14460.1131122991@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Cristian Prieto" <cristian(at)clickdiario(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Chris Browne 2005-11-04 17:19:31 Re: PG 8.1 supported platforms list
Previous Message Martijn van Oosterhout 2005-11-04 16:45:43 Re: somebody could explain this?