reference/bc/functions/bcmod.xml
c7e83fbbbcde9f54affc09424d032c38492a3ff4
c7e83fbbbcde9f54affc09424d032c38492a3ff4
...
...
@@ -1,6 +1,6 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-
<refentry xml:id="function.bcmod" xmlns="http://docbook.org/ns/docbook">
3
+
<refentry xml:id="function.bcmod" xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude">
4
4
<refnamediv>
5
5
<refname>bcmod</refname>
6
6
<refpurpose>Get modulus of an arbitrary precision number</refpurpose>
...
...
@@ -10,47 +10,73 @@
10
10
&reftitle.description;
11
11
<methodsynopsis>
12
12
<type>string</type><methodname>bcmod</methodname>
13
-
<methodparam><type>string</type><parameter>left_operand</parameter></methodparam>
14
-
<methodparam><type>string</type><parameter>modulus</parameter></methodparam>
13
+
<methodparam><type>string</type><parameter>num1</parameter></methodparam>
14
+
<methodparam><type>string</type><parameter>num2</parameter></methodparam>
15
+
<methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>scale</parameter><initializer>&null;</initializer></methodparam>
15
16
</methodsynopsis>
16
17
<para>
17
-
Get the modulus of the <parameter>left_operand</parameter> using
18
-
<parameter>modulus</parameter>.
18
+
Get the remainder of dividing <parameter>num1</parameter> by
19
+
<parameter>num2</parameter>.
20
+
The result has the same sign as <parameter>num1</parameter>.
19
21
</para>
20
22
</refsect1>
21
23
22
24
<refsect1 role="parameters">
23
-
&reftitle.parameters;
24
-
<para>
25
-
<variablelist>
26
-
<varlistentry>
27
-
<term><parameter>left_operand</parameter></term>
28
-
<listitem>
29
-
<para>
30
-
The left operand, as a string.
31
-
</para>
32
-
</listitem>
33
-
</varlistentry>
34
-
<varlistentry>
35
-
<term><parameter>modulus</parameter></term>
36
-
<listitem>
37
-
<para>
38
-
The modulus, as a string.
39
-
</para>
40
-
</listitem>
41
-
</varlistentry>
42
-
</variablelist>
43
-
</para>
25
+
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('function.bcadd')/db:refsect1[@role='parameters']/*)" />
44
26
</refsect1>
45
27
46
28
<refsect1 role="returnvalues">
47
29
&reftitle.returnvalues;
48
30
<para>
49
-
Returns the modulus as a string, or &null; if
50
-
<parameter>modulus</parameter> is 0.
31
+
Returns the modulus as a string.
51
32
</para>
52
33
</refsect1>
53
34
35
+
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('function.bcdiv')/db:refsect1[@role='errors'])" />
36
+
37
+
<refsect1 role="changelog"><!-- {{{ -->
38
+
&reftitle.changelog;
39
+
<informaltable>
40
+
<tgroup cols="2">
41
+
<thead>
42
+
<row>
43
+
<entry>&Version;</entry>
44
+
<entry>&Description;</entry>
45
+
</row>
46
+
</thead>
47
+
<tbody>
48
+
<row>
49
+
<entry>8.0.0</entry>
50
+
<entry>
51
+
<parameter>scale</parameter> is now nullable.
52
+
</entry>
53
+
</row>
54
+
<row>
55
+
<entry>8.0.0</entry>
56
+
<entry>
57
+
Dividing by <literal>0</literal> now throws a <exceptionname>DivisionByZeroError</exceptionname> exception instead of returning null.
58
+
</entry>
59
+
</row>
60
+
<row>
61
+
<entry>7.2.0</entry>
62
+
<entry>
63
+
<parameter>num1</parameter> and <parameter>num2</parameter> are no
64
+
longer truncated to integer, so now the behavior of
65
+
<function>bcmod</function> follows <function>fmod</function> rather than
66
+
the <literal>%</literal> operator.
67
+
</entry>
68
+
</row>
69
+
<row>
70
+
<entry>7.2.0</entry>
71
+
<entry>
72
+
The <parameter>scale</parameter> parameter was added.
73
+
</entry>
74
+
</row>
75
+
</tbody>
76
+
</tgroup>
77
+
</informaltable>
78
+
</refsect1><!-- }}} -->
79
+
54
80
<refsect1 role="examples">
55
81
&reftitle.examples;
56
82
<example>
...
...
@@ -58,8 +84,22 @@
58
84
<programlisting role="php">
59
85
<![CDATA[
60
86
<?php
61
-
echo bcmod('4', '2'); // 0
62
-
echo bcmod('2', '4'); // 2
87
+
bcscale(0);
88
+
echo bcmod( '5', '3'); // 2
89
+
echo bcmod( '5', '-3'); // 2
90
+
echo bcmod('-5', '3'); // -2
91
+
echo bcmod('-5', '-3'); // -2
92
+
?>
93
+
]]>
94
+
</programlisting>
95
+
</example>
96
+
<example>
97
+
<title><function>bcmod</function> with decimals</title>
98
+
<programlisting role="php">
99
+
<![CDATA[
100
+
<?php
101
+
bcscale(1);
102
+
echo bcmod('5.7', '1.3'); // 0.5 as of PHP 7.2.0; 0 previously
63
103
?>
64
104
]]>
65
105
</programlisting>
...
...
@@ -71,11 +111,12 @@ echo bcmod('2', '4'); // 2
71
111
<para>
72
112
<simplelist>
73
113
<member><function>bcdiv</function></member>
114
+
<member><function>bcdivmod</function></member>
115
+
<member><methodname>BcMath\Number::mod</methodname></member>
74
116
</simplelist>
75
117
</para>
76
118
</refsect1>
77
119
</refentry>
78
-
79
120
<!-- Keep this comment at the end of the file
80
121
Local variables:
81
122
mode: sgml
82
123