<!--
-$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.134 2002/12/06 05:20:12 momjian Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.135 2003/01/23 01:22:59 tgl Exp $
PostgreSQL documentation
-->
<para>
<xref linkend="functions-math-func-table"> shows the available
mathematical functions. In the table, <literal>dp</literal>
- indicates <type>double precision</type>. The functions
- <function>exp</function>, <function>ln</function>,
- <function>log</function>, <function>pow</function>,
- <function>round</function> (1 argument), <function>sqrt</function>,
- and <function>trunc</function> (1 argument) are also available for
- the type <type>numeric</type> in place of <type>double
- precision</type>. Functions returning a <type>numeric</type>
- result take <type>numeric</type> input arguments, unless otherwise
- specified. Many of these functions are implemented on top of the
- host system's C library; accuracy and behavior in boundary cases
- could therefore vary depending on the host system.
+ indicates <type>double precision</type>. Many of these functions
+ are provided in multiple forms with different argument types.
+ Except where noted, any given form of a function returns the same
+ datatype as its argument.
+ The functions working with <type>double precision</type> data are mostly
+ implemented on top of the host system's C library; accuracy and behavior in
+ boundary cases may therefore vary depending on the host system.
</para>
<table id="functions-math-func-table">
</row>
<row>
- <entry><function>ceil</function>(<type>numeric</type>)</entry>
- <entry><type>numeric</type></entry>
+ <entry><function>ceil</function>(<type>dp</type> or <type>numeric</type>)</entry>
+ <entry>(same as input)</entry>
<entry>smallest integer not less than argument</entry>
<entry><literal>ceil(-42.8)</literal></entry>
<entry>-42</entry>
</row>
<row>
- <entry><function>exp</function>(<type>dp</type>)</entry>
- <entry><type>dp</type></entry>
+ <entry><function>exp</function>(<type>dp</type> or <type>numeric</type>)</entry>
+ <entry>(same as input)</entry>
<entry>exponential</entry>
<entry><literal>exp(1.0)</literal></entry>
<entry>2.71828182845905</entry>
</row>
<row>
- <entry><function>floor</function>(<type>numeric</type>)</entry>
- <entry><type>numeric</type></entry>
+ <entry><function>floor</function>(<type>dp</type> or <type>numeric</type>)</entry>
+ <entry>(same as input)</entry>
<entry>largest integer not greater than argument</entry>
<entry><literal>floor(-42.8)</literal></entry>
<entry>-43</entry>
</row>
<row>
- <entry><function>ln</function>(<type>dp</type>)</entry>
- <entry><type>dp</type></entry>
+ <entry><function>ln</function>(<type>dp</type> or <type>numeric</type>)</entry>
+ <entry>(same as input)</entry>
<entry>natural logarithm</entry>
<entry><literal>ln(2.0)</literal></entry>
<entry>0.693147180559945</entry>
</row>
<row>
- <entry><function>log</function>(<type>dp</type>)</entry>
- <entry><type>dp</type></entry>
+ <entry><function>log</function>(<type>dp</type> or <type>numeric</type>)</entry>
+ <entry>(same as input)</entry>
<entry>base 10 logarithm</entry>
<entry><literal>log(100.0)</literal></entry>
<entry>2</entry>
</row>
<row>
- <entry><function>pow</function>(<parameter>e</parameter> <type>dp</type>,
- <parameter>n</parameter> <type>dp</type>)</entry>
+ <entry><function>pow</function>(<parameter>x</parameter> <type>dp</type>,
+ <parameter>e</parameter> <type>dp</type>)</entry>
<entry><type>dp</type></entry>
<entry>raise a number to exponent <parameter>e</parameter></entry>
<entry><literal>pow(9.0, 3.0)</literal></entry>
</row>
<row>
+ <entry><function>pow</function>(<parameter>x</parameter> <type>numeric</type>,
+ <parameter>e</parameter> <type>numeric</type>)</entry>
+ <entry><type>numeric</type></entry>
+ <entry>raise a number to exponent <parameter>e</parameter></entry>
+ <entry><literal>pow(9.0, 3.0)</literal></entry>
+ <entry>729</entry>
+ </row>
+
+ <row>
<entry><function>radians</function>(<type>dp</type>)</entry>
<entry><type>dp</type></entry>
<entry>degrees to radians</entry>
<row>
<entry><function>random</function>()</entry>
<entry><type>dp</type></entry>
- <entry>value between 0.0 to 1.0</entry>
+ <entry>random value between 0.0 and 1.0</entry>
<entry><literal>random()</literal></entry>
<entry></entry>
</row>
<row>
- <entry><function>round</function>(<type>dp</type>)</entry>
- <entry><type>dp</type></entry>
+ <entry><function>round</function>(<type>dp</type> or <type>numeric</type>)</entry>
+ <entry>(same as input)</entry>
<entry>round to nearest integer</entry>
<entry><literal>round(42.4)</literal></entry>
<entry>42</entry>
</row>
-->
<row>
- <entry><function>sign</function>(<type>numeric</type>)</entry>
- <entry><type>numeric</type></entry>
+ <entry><function>sign</function>(<type>dp</type> or <type>numeric</type>)</entry>
+ <entry>(same as input)</entry>
<entry>sign of the argument (-1, 0, +1)</entry>
<entry><literal>sign(-8.4)</literal></entry>
<entry>-1</entry>
</row>
<row>
- <entry><function>sqrt</function>(<type>dp</type>)</entry>
- <entry><type>dp</type></entry>
+ <entry><function>sqrt</function>(<type>dp</type> or <type>numeric</type>)</entry>
+ <entry>(same as input)</entry>
<entry>square root</entry>
<entry><literal>sqrt(2.0)</literal></entry>
<entry>1.4142135623731</entry>
</row>
<row>
- <entry><function>trunc</function>(<type>dp</type>)</entry>
- <entry><type>dp</type></entry>
+ <entry><function>trunc</function>(<type>dp</type> or <type>numeric</type>)</entry>
+ <entry>(same as input)</entry>
<entry>truncate toward zero</entry>
<entry><literal>trunc(42.8)</literal></entry>
<entry>42</entry>
</row>
<row>
- <entry><function>trunc</function>(<type>numeric</type>,
- <parameter>r</parameter> <type>integer</type>)</entry>
+ <entry><function>trunc</function>(<parameter>v</parameter> <type>numeric</type>, <parameter>s</parameter> <type>integer</type>)</entry>
<entry><type>numeric</type></entry>
<entry>truncate to <parameter>s</parameter> decimal places</entry>
<entry><literal>trunc(42.4382, 2)</literal></entry>
<para>
Finally, <xref linkend="functions-math-trig-table"> shows the
available trigonometric functions. All trigonometric functions
- have arguments and return values of type <type>double
+ take arguments and return values of type <type>double
precision</type>.
</para>
<para>
This section describes functions and operators for examining and
- manipulating binary string values. Strings in this context include
+ manipulating binary string values. Strings in this context mean
values of the type <type>BYTEA</type>.
</para>
</row>
<row>
- <entry><function>set_byte</function>(<parameter>string</parameter>, <parameter>offset</parameter>)</entry>
+ <entry><function>set_byte</function>(<parameter>string</parameter>,
+ <parameter>offset</parameter>, <parameter>newvalue</>)</entry>
<entry><type>bytea</type></entry>
<entry>
Set byte in string.
</row>
<row>
- <entry><function>set_bit</function>(<parameter>string</parameter>, <parameter>offset</parameter>)</entry>
+ <entry><function>set_bit</function>(<parameter>string</parameter>,
+ <parameter>offset</parameter>, <parameter>newvalue</>)</entry>
<entry><type>bytea</type></entry>
<entry>
Set bit in string.