php-doc-en/functions/math.xml

1143 lines
33 KiB
XML
Raw Normal View History

<reference id="ref.math">
<title>Mathematical Functions</title>
<titleabbrev>Math.</titleabbrev>
<partintro>
<sect1>
<title>Introduction</title>
<para>
These math functions will only handle values within the range of
the long and double types on your computer. If you need to
handle bigger numbers, take a look at the <link
linkend="ref.bc">arbitrary precision math functions</link>.
</para>
<sect2>
<title>Math constants</title>
<para>
The following values are defined as constants in PHP by the math
extension:
<table>
<title>Math constants</title>
<tgroup cols="3">
<thead>
<row>
<entry>Constant</entry>
<entry>Value</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>M_PI</entry>
<entry>3.14159265358979323846</entry>
<entry>Der Wert &pi; (Pi)</entry>
</row>
<row>
<entry>M_E</entry>
<entry>2.7182818284590452354</entry>
<entry>e</entry>
</row>
<row>
<entry>M_LOG2E</entry>
<entry>1.4426950408889634074</entry>
<entry>log_2 e</entry>
</row>
<row>
<entry>M_LOG10E</entry>
<entry>0.43429448190325182765</entry>
<entry>log_10 e</entry>
</row>
<row>
<entry>M_LN2</entry>
<entry>0.69314718055994530942</entry>
<entry>log_e 2</entry>
</row>
<row>
<entry>M_LN10</entry>
<entry>2.30258509299404568402</entry>
<entry>log_e 10</entry>
</row>
<row>
<entry>M_PI_2</entry>
<entry>1.57079632679489661923</entry>
<entry>pi/2</entry>
</row>
<row>
<entry>M_PI_4</entry>
<entry>0.78539816339744830962</entry>
<entry>pi/4</entry>
</row>
<row>
<entry>M_1_PI</entry>
<entry>0.31830988618379067154</entry>
<entry>1/pi</entry>
</row>
<row>
<entry>M_2_PI</entry>
<entry>0.63661977236758134308</entry>
<entry>2/pi</entry>
</row>
<row>
<entry>M_SQRTPI</entry>
<entry>1.77245385090551602729</entry>
<entry>sqrt(pi) [4.0.2]</entry>
</row>
<row>
<entry>M_2_SQRTPI</entry>
<entry>1.12837916709551257390</entry>
<entry>2/sqrt(pi)</entry>
</row>
<row>
<entry>M_SQRT2</entry>
<entry>1.41421356237309504880</entry>
<entry>sqrt(2)</entry>
</row>
<row>
<entry>M_SQRT3</entry>
<entry>1.73205080756887729352</entry>
<entry>sqrt(3) [4.0.2]</entry>
</row>
<row>
<entry>M_SQRT1_2</entry>
<entry>0.70710678118654752440</entry>
<entry>1/sqrt(2)</entry>
</row>
<row>
<entry>M_LNPI</entry>
<entry>1.14472988584940017414</entry>
<entry>log_e(pi) [4.0.2]</entry>
</row>
<row>
<entry>M_EULER</entry>
<entry>0.57721566490153286061</entry>
<entry>Euler constant [4.0.2]</entry>
</row>
</tbody>
</tgroup>
</table>
Only M_PI is available in PHP versions up to and including PHP4RC1.
All other constants are available starting with PHP4.0. Constants
labelled [4.0.2] were added in PHP 4.0.2.
</para>
</sect2>
</sect1>
</partintro>
<refentry id="function.abs">
<refnamediv>
<refname>abs</refname>
<refpurpose>Absolute value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>abs</function></funcdef>
<paramdef>mixed <parameter>number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the absolute value of number. If the argument number is
float, return type is also float, otherwise it is int.
</para>
</refsect1>
</refentry>
<refentry id="function.acos">
<refnamediv>
<refname>acos</refname>
<refpurpose>Arc cosine</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>acos</function></funcdef>
<paramdef>float <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the arc cosine of arg in radians.
</para>
<para>
See also <function>asin</function> and <function>atan</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.asin">
<refnamediv>
<refname>asin</refname>
<refpurpose>Arc sine</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>asin</function></funcdef>
<paramdef>float <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the arc sine of arg in radians.
</para>
<para>
See also <function>acos</function> and <function>atan</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.atan">
<refnamediv>
<refname>atan</refname>
<refpurpose>Arc tangent</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>atan</function></funcdef>
<paramdef>float <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the arc tangent of arg in radians.
</para>
<para>
See also <function>asin</function> and <function>acos</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.atan2">
<refnamediv>
<refname>atan2</refname>
<refpurpose>arc tangent of two variables</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>atan2</function></funcdef>
<paramdef>float <parameter>y</parameter></paramdef>
<paramdef>float <parameter>x</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
This function calculates the arc tangent of the two variables
<parameter>x</parameter> and <parameter>y</parameter>. It is
similar to calculating the arc tangent of
<parameter>y</parameter> / <parameter>x</parameter>, except that
the signs of both arguments are used to determine the quadrant of
the result.
</simpara>
<simpara>
The function returns the result in radians, which is between -PI
and PI (inclusive).
</simpara>
<para>
See also <function>acos</function> and <function>atan</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.base-convert">
<refnamediv>
<refname>base_convert</refname>
<refpurpose>Convert a number between arbitrary bases</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>base_convert</function></funcdef>
<paramdef>string <parameter>number</parameter></paramdef>
<paramdef>int <parameter>frombase</parameter></paramdef>
<paramdef>int <parameter>tobase</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string containing <parameter>number</parameter>
represented in base <parameter>tobase</parameter>. The base in
which <parameter>number</parameter> is given is specified in
<parameter>frombase</parameter>. Both
<parameter>frombase</parameter> and <parameter>tobase</parameter>
have to be between 2 and 36, inclusive. Digits in numbers with a
base higher than 10 will be represented with the letters a-z,
with a meaning 10, b meaning 11 and z meaning 36.
<example>
<title><function>Base_convert</function></title>
<programlisting role="php">
$binary = base_convert ($hexadecimal, 16, 2);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.bindec">
<refnamediv>
<refname>bindec</refname>
<refpurpose>Binary to decimal</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>bindec</function></funcdef>
<paramdef>string <parameter>binary_string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the decimal equivalent of the binary number represented by
the binary_string argument.
</para>
<para>
Octdec converts a binary number to a decimal number. The largest
number that can be converted is 31 bits of 1's or 2147483647 in
decimal.
</para>
<para>
See also the <function>decbin</function>
function.
</para>
</refsect1>
</refentry>
<refentry id="function.ceil">
<refnamediv>
<refname>ceil</refname>
<refpurpose>Round fractions up</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ceil</function></funcdef>
<paramdef>float <parameter>number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the next highest integer value from
<parameter>number</parameter>. Using <function>ceil</function>
on integers is absolutely a waste of time.
</simpara>
<simpara>
NOTE: PHP/FI 2's <function>ceil</function> returned a
float. Use: <literal>$new = (double)ceil($number);</literal> to
get the old behaviour.
</simpara>
<simpara>
See also <function>floor</function> and
<function>round</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.cos">
<refnamediv>
<refname>cos</refname>
<refpurpose>Cosine</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>cos</function></funcdef>
<paramdef>float <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the cosine of arg in radians.
</para>
<para>
See also <function>sin</function> and <function>tan</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.decbin">
<refnamediv>
<refname>decbin</refname>
<refpurpose>Decimal to binary</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>decbin</function></funcdef>
<paramdef>int <parameter>number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string containing a binary representation of the given
number argument. The largest number that can be converted is
2147483647 in decimal resulting to a string of 31 1's.
</para>
<para>
See also the <function>bindec</function> function.
</para>
</refsect1>
</refentry>
<refentry id="function.dechex">
<refnamediv>
<refname>dechex</refname>
<refpurpose>Decimal to hexadecimal</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>dechex</function></funcdef>
<paramdef>int <parameter>number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string containing a hexadecimal representation of the
given number argument. The largest number that can
be converted is 2147483647 in decimal resulting to "7fffffff".
</para>
<para>
See also the <function>hexdec</function> function.
</para>
</refsect1>
</refentry>
<refentry id="function.decoct">
<refnamediv>
<refname>decoct</refname>
<refpurpose>Decimal to octal</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>decoct</function></funcdef>
<paramdef>int <parameter>number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string containing an octal representation of the given
number argument. The largest number that can be converted is
2147483647 in decimal resulting to "17777777777".
</para>
<para>
See also <function>octdec</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.deg2rad">
<refnamediv>
<refname>deg2rad</refname>
<refpurpose>
Converts the number in degrees to the radian equivalent
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>double <function>deg2rad</function></funcdef>
<paramdef>double <parameter>number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function converts <parameter>number</parameter> from degrees
to the radian equivalent.
</para>
<para>
See also <function>rad2deg</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.exp">
<refnamediv>
<refname>exp</refname>
<refpurpose>e to the power of ...</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>exp</function></funcdef>
<paramdef>float <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns e raised to the power of <parameter>arg</parameter>.
</para>
<para>
See also <function>pow</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.floor">
<refnamediv>
<refname>floor</refname>
<refpurpose>Round fractions down</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>floor</function></funcdef>
<paramdef>float <parameter>number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the next lowest integer value from
<parameter>number</parameter>. Using <function>floor</function>
on integers is absolutely a waste of time.
</simpara>
<simpara>
NOTE: PHP/FI 2's <function>floor</function> returned a
float. Use: <literal>$new = (double)floor($number);</literal> to
get the old behaviour.
</simpara>
<simpara>
See also <function>ceil</function> and
<function>round</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.getrandmax">
<refnamediv>
<refname>getrandmax</refname>
<refpurpose>Show largest possible random value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>getrandmax</function></funcdef>
<paramdef>void </paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the maximum value that can be returned by a call to
<function>rand</function>.
</simpara>
<simpara>
See also <function>rand</function>, <function>srand</function>,
<function>mt_rand</function>, <function>mt_srand</function>, and
<function>mt_getrandmax</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.hexdec">
<refnamediv>
<refname>hexdec</refname>
<refpurpose>Hexadecimal to decimal</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hexdec</function></funcdef>
<paramdef>string <parameter>hex_string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the decimal equivalent of the hexadecimal number
represented by the hex_string argument. HexDec converts a
hexadecimal string to a decimal number. The largest number that
can be converted is 7fffffff or 2147483647 in decimal.
</para>
<para>
See also the <function>dechex</function> function.
</para>
</refsect1>
</refentry>
<refentry id="function.lcg-value">
<refnamediv>
<refname>lcg_value</refname>
<refpurpose>Combined linear congruential generator</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>double <function>lcg_value</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
<function>lcg_value</function> returns a pseudo random number in
the range of (0, 1). The function combines two CGs with periods
of 2^31 - 85 and 2^31 - 249. The period of this function is equal
to the product of both primes.
</para>
</refsect1>
</refentry>
<refentry id="function.log">
<refnamediv>
<refname>log</refname>
<refpurpose>Natural logarithm</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>log</function></funcdef>
<paramdef>float <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the natural logarithm of arg.
</para>
</refsect1>
</refentry>
<refentry id="function.log10">
<refnamediv>
<refname>log10</refname>
<refpurpose>Base-10 logarithm</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>log10</function></funcdef>
<paramdef>float <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the base-10 logarithm of <parameter>arg</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.max">
<refnamediv>
<refname>max</refname>
<refpurpose>Find highest value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>max</function></funcdef>
<paramdef>mixed <parameter>arg1</parameter></paramdef>
<paramdef>mixed <parameter>arg2</parameter></paramdef>
<paramdef>mixed <parameter>argn</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>max</function> returns the numerically highest of the
parameter values.
</para>
<para>
If the first parameter is an array, <function>max</function>
returns the highest value in that array. If the first parameter
is an integer, string or double, you need at least two parameters
and <function>max</function> returns the biggest of these values.
You can compare an unlimited number of values.
</para>
<para>
If one or more of the values is a double, all the values will be
treated as doubles, and a double is returned. If none of the
values is a double, all of them will be treated as integers, and
an integer is returned.
</para>
</refsect1>
</refentry>
<refentry id="function.min">
<refnamediv>
<refname>min</refname>
<refpurpose>Find lowest value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>min</function></funcdef>
<paramdef>mixed <parameter>arg1</parameter></paramdef>
<paramdef>mixed <parameter>arg2</parameter></paramdef>
<paramdef>mixed <parameter>argn</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Min</function> returns the numerically lowest of the
parameter values.
</para>
<para>
If the first parameter is an array, <function>min</function>
returns the lowest value in that array. If the first parameter
is an integer, string or double, you need at least two parameters
and <function>min</function> returns the lowest of these values.
You can compare an unlimited number of values.
</para>
<para>
If one or more of the values is a double, all the values will be
treated as doubles, and a double is returned. If none of the
values is a double, all of them will be treated as integers, and
an integer is returned.
</para>
</refsect1>
</refentry>
<refentry id="function.mt-rand">
<refnamediv>
<refname>mt_rand</refname>
<refpurpose>Generate a better random value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mt_rand</function></funcdef>
<paramdef>int
<parameter><optional>min</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>max</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Many random number generators of older libcs have dubious or
unknown characteristics and are slow. By default, PHP uses the
libc random number generator with the <function>rand</function>
function. <function>mt_rand</function> function is a drop-in
replacement for this. It uses a random number generator with
known characteristics, the Mersenne Twister, which will produce
random numbers that should be suitable for seeding some kinds
of cryptography (see the home pages for details) and is four
times faster than what the average libc provides. The Homepage
of the Mersenne Twister can be found at
<ulink url="&url.mersenne;">&url.mersenne;</ulink>, and an
optimized version of the MT source is available from
<ulink url="&url.mersenne.twister;">&url.mersenne.twister;
</ulink>.
</simpara>
<simpara>
If called without the optional <parameter>min</parameter>,
<parameter>max</parameter> arguments <function>mt_rand</function>
returns a pseudo-random value between 0 and
<constant>RAND_MAX</constant>. If you want a random number
between 5 and 15 (inclusive), for example, use <literal>mt_rand
(5, 15)</literal>.
</simpara>
<simpara>
Remember to seed the random number generator before use with
<function>mt_srand</function>.
</simpara>
<note>
<para>
In versions before 3.0.7 the meaning of
<parameter>max</parameter> was <parameter>range</parameter>. To
get the same results in these versions the short example should
be <literal>mt_rand (5, 11)</literal> to get a random number
between 5 and 15.
</para>
</note>
<simpara>
See also <function>mt_srand</function>,
<function>mt_getrandmax</function>, <function>srand</function>,
<function>rand</function> and <function>getrandmax</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.mt-srand">
<refnamediv>
<refname>mt_srand</refname>
<refpurpose>Seed the better random number generator</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>mt_srand</function></funcdef>
<paramdef>int <parameter>seed</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Seeds the random number generator with
<parameter>seed</parameter>.
<informalexample>
<programlisting role="php">
// seed with microseconds since last "whole" second
mt_srand ((double) microtime() * 1000000);
$randval = mt_rand();
</programlisting>
</informalexample>
</para>
<simpara>
See also <function>mt_rand</function>,
<function>mt_getrandmax</function>, <function>srand</function>,
<function>rand</function>, and
<function>getrandmax</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.mt-getrandmax">
<refnamediv>
<refname>mt_getrandmax</refname>
<refpurpose>Show largest possible random value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mt_getrandmax</function></funcdef>
<paramdef>void </paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the maximum value that can be returned by a call to
<function>mt_rand</function>.
</simpara>
<simpara>
See also <function>mt_rand</function>,
<function>mt_srand</function> <function>rand</function>,
<function>srand</function>, and
<function>getrandmax</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.number-format">
<refnamediv>
<refname>number_format</refname>
<refpurpose>Format a number with grouped thousands</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>number_format</function></funcdef>
<paramdef>float <parameter>number</parameter></paramdef>
<paramdef>int <parameter>decimals</parameter></paramdef>
<paramdef>string <parameter>dec_point</parameter></paramdef>
<paramdef>string <parameter>thousands_sep</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Number_format</function> returns a formatted version of
<parameter>number</parameter>. This function accepts either one,
two or four parameters (not three):
</para>
<para>If only one parameter is given,
<parameter>Number</parameter> will be formatted without decimals,
but with a comma (",") between every group of thousands.
</para>
<para>
If two parameters are given, <parameter>number</parameter> will
be formatted with <parameter>decimals</parameter> decimals with a
dot (".") in front, and a comma (",") between every group of
thousands.
</para>
<para>
If all four parameters are given, <parameter>number</parameter>
will be formatted with <parameter>decimals</parameter> decimals,
<parameter>dec_point</parameter> instead of a dot (".") before
the decimals and <parameter>thousands_sep</parameter> instead of
a comma (",") between every group of thousands.
</para>
</refsect1>
</refentry>
<refentry id="function.octdec">
<refnamediv>
<refname>octdec</refname>
<refpurpose>Octal to decimal</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>octdec</function></funcdef>
<paramdef>string <parameter>octal_string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the decimal equivalent of the octal number
represented by the octal_string argument.
OctDec converts an octal string to a decimal number. The largest
number that can be converted is 17777777777 or 2147483647 in
decimal.
</para>
<para>
See also <function>decoct</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.pi">
<refnamediv>
<refname>pi</refname>
<refpurpose>Get value of pi</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>double <function>pi</function></funcdef>
<paramdef>void </paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns an approximation of pi.
</simpara>
</refsect1>
</refentry>
<refentry id="function.pow">
<refnamediv>
<refname>pow</refname>
<refpurpose>Exponential expression</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>pow</function></funcdef>
<paramdef>float <parameter>base</parameter></paramdef>
<paramdef>float <parameter>exp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns base raised to the power of exp.
</para>
<para>
See also <function>exp</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.rad2deg">
<refnamediv>
<refname>rad2deg</refname>
<refpurpose>
Converts the radian number to the equivalent number in degrees
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>double <function>rad2deg</function></funcdef>
<paramdef>double <parameter>number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function converts <parameter>number</parameter> from radian
to degrees.
</para>
<para>
See also <function>deg2rad</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.rand">
<refnamediv>
<refname>rand</refname>
<refpurpose>Generate a random value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>rand</function></funcdef>
<paramdef>
<parameter><optional>int min</optional></parameter>
</paramdef>
<paramdef>
<parameter><optional>int max</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
If called without the optional <parameter>min</parameter>,
<parameter>max</parameter> arguments <function>rand</function>
returns a pseudo-random value between 0 and
<constant>RAND_MAX</constant>. If you want a random number
between 5 and 15 (inclusive), for example, use <literal>rand (5,
15)</literal>.
</simpara>
<simpara>
Remember to seed the random number generator before use with
<function>srand</function>.
</simpara>
<note>
<para>
In versions before 3.0.7 the meaning of
<parameter>max</parameter> was <parameter>range</parameter>. To
get the same results in these versions the short example should
be <literal>rand (5, 11)</literal> to get a random number
between 5 and 15.
</para>
</note>
<simpara>
See also <function>srand</function>,
<function>getrandmax</function>, <function>mt_rand</function>,
<function>mt_srand</function>, and
<function>mt_getrandmax</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.round">
<refnamediv>
<refname>round</refname>
<refpurpose>Rounds a float</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>double <function>round</function></funcdef>
<paramdef>double <parameter>val</parameter></paramdef>
<paramdef>int
<parameter><optional>precision</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the rounded value of <parameter>val</parameter> to
specified precision.
<informalexample>
<programlisting role="php">
$foo = round (3.4); // $foo == 3.0
$foo = round (3.5); // $foo == 4.0
$foo = round (3.6); // $foo == 4.0
$foo = round (1.95583, 2); // $foo == 1.96
</programlisting>
</informalexample>
</para>
<simpara>
See also <function>ceil</function> and
<function>floor</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.sin">
<refnamediv>
<refname>sin</refname>
<refpurpose>Sine</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>sin</function></funcdef>
<paramdef>float <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the sine of arg in radians.
</para>
<para>
See also <function>cos</function> and <function>tan</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.sqrt">
<refnamediv>
<refname>sqrt</refname>
<refpurpose>Square root</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>sqrt</function></funcdef>
<paramdef>float <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the square root of <parameter>arg</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.srand">
<refnamediv>
<refname>srand</refname>
<refpurpose>Seed the random number generator</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>srand</function></funcdef>
<paramdef>int <parameter>seed</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Seeds the random number generator with
<parameter>seed</parameter>.
<informalexample>
<programlisting role="php">
// seed with microseconds since last "whole" second
srand ((double) microtime() * 1000000);
$randval = rand();
</programlisting>
</informalexample>
</para>
<simpara>
See also <function>rand</function>,
<function>getrandmax</function>, <function>mt_rand</function>,
<function>mt_srand</function>, and
<function>mt_getrandmax</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.tan">
<refnamediv>
<refname>tan</refname>
<refpurpose>Tangent</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>tan</function></funcdef>
<paramdef>float <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the tangent of arg in radians.
</para>
<para>
See also <function>sin</function> and <function>cos</function>.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->