X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 81EA7DBF3D for ; Tue, 22 Nov 2005 20:13:28 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 16638-10 for ; Wed, 23 Nov 2005 00:13:30 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id 1576DDBF3B for ; Tue, 22 Nov 2005 20:13:25 -0400 (AST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 2B2633565C; Tue, 22 Nov 2005 16:13:28 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 2980435648; Tue, 22 Nov 2005 16:13:28 -0800 (PST) Date: Tue, 22 Nov 2005 16:13:28 -0800 (PST) From: Stephan Szabo To: Luca Pireddu Cc: pgsql-sql@postgresql.org Subject: Re: argument type problem with plpgsql function In-Reply-To: <200511221708.10563.luca@cs.ualberta.ca> Message-ID: <20051122161059.H87037@megazone.bigpanda.com> References: <200511221708.10563.luca@cs.ualberta.ca> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200511/213 X-Sequence-Number: 23464 On Tue, 22 Nov 2005, Luca Pireddu wrote: > I wrote a little function that has to work with big numbers > > CREATE OR REPLACE FUNCTION blast_evalue(seq_len bigint, db_size bigint, > bit_score double precision) > RETURNS double precision AS $$ > BEGIN > RETURN 2^(bit_score) * db_size * seq_len; > END; > $$ > LANGUAGE 'plpgsql' > IMMUTABLE > RETURNS NULL ON NULL INPUT; > > but it doesn't work properly unless I cast the db_size parameter when I call > the function: > > select blast_evalue(273, 8903836, -55.4546); > blast_evalue > -------------- > 2430747228 <- wrong number. This is 273 * 8903836 > (1 row) > > select blast_evalue(273, 8903836::bigint, -55.4546); > blast_evalue > --------------------- > 4.9231356421437e-08 <- that's correct > (1 row) > > I don't understand why the cast is necessary. Is there a way to make this > work without it? I got the same answer (the second) for both calls from my 8.0 and 8.1 setups, what version were you trying on?