7.10 Mathematical Functions and Operators


Functions and operators are essential for every application. You have already used some operators in this book but in this section you will find a complete list of mathematical functions. Operators related to geometric data types will not be discussed in this chapter.

Let's look at the mathematical operators first in Table 7.2.

Table 7.2. Mathematical Operators
Operator Description Example Result
+ Addition SELECT 1+1; 2
- Subtraction SELECT 14-3; 11
* Multiplication SELECT 3*4; 12
/ Division SELECT 18/3; 6
% Modulo SELECT 14%3; 2
^ Exponentiation SELECT 2^10; 1024
|/ Square root SELECT |/ 361; 19
||/ Cube root SELECT 5832; 18
! Factorial SELECT 23!; 862453760
!! Factorial (prefix operator) SELECT !! 23; 862453760
@ Absolute value SELECT @ -23; 23
& Binary AND SELECT 12 & 24; 8
| Binary OR SELECT 12 | 24; 28
# Binary XOR SELECT 12 # 24; 20
~ Binary NOR SELECT 12 ~ 24; f
<< Binary shift left SELECT 2 << 4; 32
>> Binary shift right SELECT 5 >> 2; 1

The mathematical functions are shown in Table 7.3.

Table 7.3. Mathematical Functions
Function Description
 abs(x) cbrt(double precision) ceil(numeric) 

Absolute value

Cube root

Next integer higher than the argument of the function

 degrees(double precision) exp(double precision) floor(numeric) 

Convert radians to degrees

Exponential function

Next integer lower than the argument of the function

 ln(double precision) log(double precision) 

Natural logarithm

Base 10 logarithm

 log(base numeric, x numeric) mod(y, x) pi() pow(double precision, double precision) radians(double precision) random() round(double precision) round(value numeric, scale integer) sqrt(double precision) trunc(double precision) trunc(value numeric, scale integer) 

Logarithm to specified base

Remainder (modulo) of the division y/x

The value of Pi

Raise a number to the specified exponent

Convert degrees to radians

Generates a random number between 0 and 1

Rounds to the nearest integer value

Rounds to a certain precision

Square root

Truncate (toward zero)

Truncate to specified number of decimal places

Finally, take a look at PostgreSQL's trigonometric functions in Table 7.4.

Table 7.4. Trigonometric Functions
Function Description
acos(x) inverse cosine
asin(x) inverse sine
atan(x) inverse tangent
atan2(x, y) inverse tangent of y/x
cos(x) cosine
cot(x) cotangent
sin(x) sine
tan(x) tangent



PHP and PostgreSQL. Advanced Web Programming2002
PHP and PostgreSQL. Advanced Web Programming2002
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 201

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net