Skip to content

Commit 15b9383

Browse files
Update round() for PHP-8.4 and Minor fixes for BCMath's round (#4425)
1 parent 3b2503b commit 15b9383

File tree

4 files changed

+68
-13
lines changed

4 files changed

+68
-13
lines changed

reference/bc/bcmath/number/round.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
<variablelist>
2626
<!-- precision parameter -->
2727
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('function.round')/db:refsect1[@role='parameters']/descendant::db:varlistentry[2])" />
28-
<varlistentry>
28+
<varlistentry xml:id="bcmath-number.round..parameters.mode">
2929
<term><parameter>mode</parameter></term>
3030
<listitem>
3131
<simpara>
32-
Specifies the rounding mode.
32+
Specifies the rounding mode. For more information about modes, see <enumname>RoundingMode</enumname>.
3333
</simpara>
3434
</listitem>
3535
</varlistentry>

reference/bc/functions/bcround.xml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,7 @@
2727
<variablelist>
2828
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('function.round')/db:refsect1[@role='parameters']/descendant::db:varlistentry[1])" />
2929
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('function.round')/db:refsect1[@role='parameters']/descendant::db:varlistentry[2])" />
30-
<varlistentry>
31-
<term><parameter>mode</parameter></term>
32-
<listitem>
33-
<simpara>
34-
Specifies the rounding mode.
35-
</simpara>
36-
</listitem>
37-
</varlistentry>
30+
<xi:include xpointer="bcmath-number.round..parameters.mode" />
3831
</variablelist>
3932
</refsect1>
4033

reference/math/functions/round.xml

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<type>float</type><methodname>round</methodname>
1212
<methodparam><type class="union"><type>int</type><type>float</type></type><parameter>num</parameter></methodparam>
1313
<methodparam choice="opt"><type>int</type><parameter>precision</parameter><initializer>0</initializer></methodparam>
14-
<methodparam choice="opt"><type>int</type><parameter>mode</parameter><initializer><constant>PHP_ROUND_HALF_UP</constant></initializer></methodparam>
14+
<methodparam choice="opt"><type class="union"><type>int</type><type>RoundingMode</type></type><parameter>mode</parameter><initializer>RoundingMode::HalfAwayFromZero</initializer></methodparam>
1515
</methodsynopsis>
1616
<para>
1717
Returns the rounded value of <parameter>num</parameter> to
@@ -71,7 +71,7 @@
7171
<term><parameter>mode</parameter></term>
7272
<listitem>
7373
<para>
74-
Use one of the following constants to specify the mode in which rounding occurs.
74+
Use <enumname>RoundingMode</enumname> or one of the following constants to specify the mode in which rounding occurs.
7575
<informaltable>
7676
<tgroup cols="2">
7777
<thead>
@@ -112,6 +112,7 @@
112112
</tbody>
113113
</tgroup>
114114
</informaltable>
115+
However, please note that some newly added modes only exist in <link linkend="enum.roundingmode">RoundingMode</link>.
115116
</para>
116117
</listitem>
117118
</varlistentry>
@@ -145,6 +146,12 @@
145146
</row>
146147
</thead>
147148
<tbody>
149+
<row>
150+
<entry>8.4.0</entry>
151+
<entry>
152+
Four new rounding modes have been added.
153+
</entry>
154+
</row>
148155
<row>
149156
<entry>8.4.0</entry>
150157
<entry>
@@ -321,6 +328,61 @@ float(-1.5)
321328
]]>
322329
</screen>
323330
</example>
331+
<example>
332+
<title>Example of using <enumname>RoundingMode</enumname></title>
333+
<programlisting role="php">
334+
<![CDATA[
335+
<?php
336+
foreach (RoundingMode::cases() as $mode) {
337+
foreach ([
338+
8.5,
339+
9.5,
340+
-3.5,
341+
] as $number) {
342+
printf("%-17s: %+.17g -> %+.17g\n", $mode->name, $number, round($number, 0, $mode));
343+
}
344+
echo "\n";
345+
}
346+
?>
347+
]]>
348+
</programlisting>
349+
&example.outputs;
350+
<screen role="php">
351+
<![CDATA[
352+
HalfAwayFromZero : +8.5 -> +9
353+
HalfAwayFromZero : +9.5 -> +10
354+
HalfAwayFromZero : -3.5 -> -4
355+
356+
HalfTowardsZero : +8.5 -> +8
357+
HalfTowardsZero : +9.5 -> +9
358+
HalfTowardsZero : -3.5 -> -3
359+
360+
HalfEven : +8.5 -> +8
361+
HalfEven : +9.5 -> +10
362+
HalfEven : -3.5 -> -4
363+
364+
HalfOdd : +8.5 -> +9
365+
HalfOdd : +9.5 -> +9
366+
HalfOdd : -3.5 -> -3
367+
368+
TowardsZero : +8.5 -> +8
369+
TowardsZero : +9.5 -> +9
370+
TowardsZero : -3.5 -> -3
371+
372+
AwayFromZero : +8.5 -> +9
373+
AwayFromZero : +9.5 -> +10
374+
AwayFromZero : -3.5 -> -4
375+
376+
NegativeInfinity : +8.5 -> +8
377+
NegativeInfinity : +9.5 -> +9
378+
NegativeInfinity : -3.5 -> -4
379+
380+
PositiveInfinity : +8.5 -> +9
381+
PositiveInfinity : +9.5 -> +10
382+
PositiveInfinity : -3.5 -> -3
383+
]]>
384+
</screen>
385+
</example>
324386
</para>
325387
</refsect1>
326388

reference/math/roundingmode.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<simpara>
1010
The <enumname>RoundingMode</enumname> enum is used to specify how rounding
1111
should be performed for <function>round</function>,
12-
<function>bcround</function>, and <methodname>BCMath::round</methodname>.
12+
<function>bcround</function>, and <methodname>BcMath\Number::round</methodname>.
1313
</simpara>
1414
</section>
1515

0 commit comments

Comments
 (0)