reference/math/functions/pow.xml
761d72245071f89a626903c9bcdc6aaff1252d54
761d72245071f89a626903c9bcdc6aaff1252d54
...
...
@@ -8,18 +8,17 @@
8
8
<refsect1 role="description">
9
9
&reftitle.description;
10
10
<methodsynopsis>
11
-
<type>number</type><methodname>pow</methodname>
12
-
<methodparam><type>number</type><parameter>base</parameter></methodparam>
13
-
<methodparam><type>number</type><parameter>exp</parameter></methodparam>
14
-
</methodsynopsis>
11
+
<type class="union"><type>int</type><type>float</type><type>object</type></type><methodname>pow</methodname>
12
+
<methodparam><type>mixed</type><parameter>num</parameter></methodparam>
13
+
<methodparam><type>mixed</type><parameter>exponent</parameter></methodparam>
14
+
</methodsynopsis>
15
15
<para>
16
-
Returns <parameter>base</parameter> raised to the power of
17
-
<parameter>exp</parameter>.
16
+
Returns <parameter>num</parameter> raised to the power of
17
+
<parameter>exponent</parameter>.
18
18
</para>
19
19
<note>
20
20
<para>
21
-
In PHP 5.6 onwards, you may prefer to use the
22
-
<link linkend="language.operators.arithmetic">**</link> operator.
21
+
It is possible to use the <link linkend="language.operators.arithmetic">**</link> operator instead.
23
22
</para>
24
23
</note>
25
24
</refsect1>
...
...
@@ -28,7 +27,7 @@
28
27
<para>
29
28
<variablelist>
30
29
<varlistentry>
31
-
<term><parameter>base</parameter></term>
30
+
<term><parameter>num</parameter></term>
32
31
<listitem>
33
32
<para>
34
33
The base to use
...
...
@@ -36,7 +35,7 @@
36
35
</listitem>
37
36
</varlistentry>
38
37
<varlistentry>
39
-
<term><parameter>exp</parameter></term>
38
+
<term><parameter>exponent</parameter></term>
40
39
<listitem>
41
40
<para>
42
41
The exponent
...
...
@@ -49,12 +48,39 @@
49
48
<refsect1 role="returnvalues">
50
49
&reftitle.returnvalues;
51
50
<para>
52
-
<parameter>base</parameter> raised to the power of <parameter>exp</parameter>.
51
+
<parameter>num</parameter> raised to the power of <parameter>exponent</parameter>.
53
52
If both arguments are non-negative integers and the result can be represented
54
-
as an integer, the result will be returned with <type>integer</type> type,
53
+
as an integer, the result will be returned with <type>int</type> type,
55
54
otherwise it will be returned as a <type>float</type>.
56
55
</para>
56
+
<para>
57
+
PHP-Extensions may override the behaviour of this operation and make it return an object.
58
+
</para>
59
+
</refsect1>
60
+
61
+
<refsect1 role="changelog">
62
+
&reftitle.changelog;
63
+
<informaltable>
64
+
<tgroup cols="2">
65
+
<thead>
66
+
<row>
67
+
<entry>&Version;</entry>
68
+
<entry>&Description;</entry>
69
+
</row>
70
+
</thead>
71
+
<tbody>
72
+
<row>
73
+
<entry>8.4.0</entry>
74
+
<entry>
75
+
Raising <literal>0</literal> to a negative
76
+
<parameter>exponent</parameter> is now deprecated.
77
+
</entry>
78
+
</row>
79
+
</tbody>
80
+
</tgroup>
81
+
</informaltable>
57
82
</refsect1>
83
+
58
84
<refsect1 role="examples">
59
85
&reftitle.examples;
60
86
<para>
...
...
@@ -65,12 +91,23 @@
65
91
<?php
66
92
67
93
var_dump(pow(2, 8)); // int(256)
68
-
echo pow(-1, 20); // 1
69
-
echo pow(0, 0); // 1
70
-
echo pow(10, -1); // 0.1
94
+
echo pow(-1, 20), PHP_EOL; // 1
95
+
echo pow(0, 0), PHP_EOL; // 1
96
+
echo pow(10, -1), PHP_EOL; // 0.1
71
97
72
-
echo pow(-1, 5.5); // PHP >=5.2.2: NAN
73
-
echo pow(-1, 5.5); // PHP <5.2.2: -NAN
98
+
echo pow(-1, 5.5), PHP_EOL; // NAN
99
+
?>
100
+
]]>
101
+
</programlisting>
102
+
</example>
103
+
</para>
104
+
<para>
105
+
<example>
106
+
<title>Examples of <function>pow</function> With GMP Extension Object</title>
107
+
<programlisting role="php" annotations="non-interactive">
108
+
<![CDATA[
109
+
<?php
110
+
var_dump(pow(new GMP("3"), new GMP("2"))); // object(GMP)
74
111
?>
75
112
]]>
76
113
</programlisting>
...
...
@@ -83,7 +120,7 @@ echo pow(-1, 5.5); // PHP <5.2.2: -NAN
83
120
<note>
84
121
<para>
85
122
This function will convert all input to a number, even non-scalar values,
86
-
which could lead to <literal>weird</literal> results.
123
+
which could lead to <emphasis>weird</emphasis> results.
87
124
</para>
88
125
</note>
89
126
</refsect1>
...
...
@@ -92,6 +129,11 @@ echo pow(-1, 5.5); // PHP <5.2.2: -NAN
92
129
&reftitle.seealso;
93
130
<para>
94
131
<simplelist>
132
+
<member>
133
+
Exponentiation operator
134
+
<link linkend="language.operators.arithmetic"><literal>**</literal></link>
135
+
</member>
136
+
<member><function>fpow</function></member>
95
137
<member><function>exp</function></member>
96
138
<member><function>sqrt</function></member>
97
139
<member><function>bcpow</function></member>
...
...
@@ -100,7 +142,6 @@ echo pow(-1, 5.5); // PHP <5.2.2: -NAN
100
142
</para>
101
143
</refsect1>
102
144
</refentry>
103
-
104
145
<!-- Keep this comment at the end of the file
105
146
Local variables:
106
147
mode: sgml
107
148