BUG #2356: sqrt and cbrt return different types

Started by Philip Crotwellabout 20 years ago2 messagesbugs
Jump to latest
#1Philip Crotwell
crotwell@seis.sc.edu

The following bug has been logged online:

Bug reference: 2356
Logged by: Philip Crotwell
Email address: crotwell@seis.sc.edu
PostgreSQL version: 8.1
Operating system: linux
Description: sqrt and cbrt return different types
Details:

The return of sqrt() is numeric but the return type of cbrt is double, which
is confusing. So, for example this works:
select mod(sqrt(4.1), 4);
but this
select mod(cbrt(4.1), 4);
fails with
ERROR: function mod(double precision, integer) does not exist
and you have to do this instead:
select mod(CAST (cbrt(4.1) AS NUMERIC), 4);

It seems to me that square root and cube root should be the same in return
type.

The docs should be updated if this change is made:
http://www.postgresql.org/docs/8.1/interactive/functions-math.html

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Philip Crotwell (#1)
Re: BUG #2356: sqrt and cbrt return different types

"Philip Crotwell" <crotwell@seis.sc.edu> writes:

It seems to me that square root and cube root should be the same in return
type.

They are, or at least one form of them matches:

regression=# \df sqrt
List of functions
Schema | Name | Result data type | Argument data types
------------+------+------------------+---------------------
pg_catalog | sqrt | double precision | double precision
pg_catalog | sqrt | numeric | numeric
(2 rows)

regression=# \df cbrt
List of functions
Schema | Name | Result data type | Argument data types
------------+------+------------------+---------------------
pg_catalog | cbrt | double precision | double precision
(1 row)

I think your request really amounts to "we should require every numeric
function to have a float8 counterpart and vice versa". Life's a bit too
short for that, though.

regards, tom lane