1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-07 00:36:50 +03:00

Add support for hyperbolic functions, as well as log10().

The SQL:2016 standard adds support for the hyperbolic functions
sinh(), cosh(), and tanh().  POSIX has long required libm to
provide those functions as well as their inverses asinh(),
acosh(), atanh().  Hence, let's just expose the libm functions
to the SQL level.  As with the trig functions, we only implement
versions for float8, not numeric.

For the moment, we'll assume that all platforms actually do have
these functions; if experience teaches otherwise, some autoconf
effort may be needed.

SQL:2016 also adds support for base-10 logarithm, but with the
function name log10(), whereas the name we've long used is log().
Add aliases named log10() for the float8 and numeric versions.

Lætitia Avrot

Discussion: https://postgr.es/m/CAB_COdguG22LO=rnxDQ2DW1uzv8aQoUzyDQNJjrR4k00XSgm5w@mail.gmail.com
This commit is contained in:
Tom Lane
2019-03-12 15:55:09 -04:00
parent 3aa0395d4e
commit f1d85aa98e
6 changed files with 333 additions and 6 deletions

View File

@ -454,6 +454,43 @@ SELECT '' AS five, * FROM FLOAT8_TBL;
| -1.2345678901234e-200
(5 rows)
-- hyperbolic functions
SELECT sinh(float8 '0');
sinh
------
0
(1 row)
SELECT cosh(float8 '0');
cosh
------
1
(1 row)
SELECT tanh(float8 '0');
tanh
------
0
(1 row)
SELECT asinh(float8 '0');
asinh
-------
0
(1 row)
SELECT acosh(float8 '1');
acosh
-------
0
(1 row)
SELECT atanh(float8 '0');
atanh
-------
0
(1 row)
RESET extra_float_digits;
-- test for over- and underflow
INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400');

View File

@ -154,6 +154,14 @@ SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
SELECT '' AS five, * FROM FLOAT8_TBL;
-- hyperbolic functions
SELECT sinh(float8 '0');
SELECT cosh(float8 '0');
SELECT tanh(float8 '0');
SELECT asinh(float8 '0');
SELECT acosh(float8 '1');
SELECT atanh(float8 '0');
RESET extra_float_digits;
-- test for over- and underflow