Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update reference math round doc en #2040

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 69 additions & 7 deletions reference/math/functions/round.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: f721489eaeb79ff096971fe5a5b101c2ebab8eeb Maintainer: girgias Status: ready -->
<!-- EN-Revision: 15b93836d93f01ea6d90a68cacf04ce0d9fb8eff Maintainer: girgias Status: ready -->
<!-- Reviewed: no -->
<refentry xml:id="function.round" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
Expand All @@ -13,7 +13,7 @@
<type>float</type><methodname>round</methodname>
<methodparam><type class="union"><type>int</type><type>float</type></type><parameter>num</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>precision</parameter><initializer>0</initializer></methodparam>
<methodparam choice="opt"><type>int</type><parameter>mode</parameter><initializer><constant>PHP_ROUND_HALF_UP</constant></initializer></methodparam>
<methodparam choice="opt"><type class="union"><type>int</type><type>RoundingMode</type></type><parameter>mode</parameter><initializer>RoundingMode::HalfAwayFromZero</initializer></methodparam>
</methodsynopsis>
<para>
Retourne la valeur arrondie de <parameter>num</parameter>
Expand Down Expand Up @@ -78,7 +78,7 @@
<term><parameter>mode</parameter></term>
<listitem>
<para>
Utilisez une des constantes suivantes pour spécifier le mode d'arrondi.
Utilisez <enumname>RoundingMode</enumname> ou l'une des constantes suivantes pour spécifier la méthode d'arrondi.
<informaltable>
<tgroup cols="2">
<thead>
Expand Down Expand Up @@ -119,6 +119,7 @@
</tbody>
</tgroup>
</informaltable>
Toutefois, noter que certaines méthodes nouvellement ajoutés n'existent que dans <link linkend="enum.roundingmode">RoundingMode</link>.
</para>
</listitem>
</varlistentry>
Expand Down Expand Up @@ -152,6 +153,12 @@
</row>
</thead>
<tbody>
<row>
<entry>8.4.0</entry>
<entry>
Quatre nouvelles méthodes d'arrondi ont été ajoutés.
</entry>
</row>
<row>
<entry>8.4.0</entry>
<entry>
Expand Down Expand Up @@ -247,14 +254,14 @@ float(0)
<programlisting role="php">
<![CDATA[
<?php
echo "Mode d'arrondi avec 9.5" . PHP_EOL;
echo "Méthode d'arrondi avec 9.5" . PHP_EOL;
var_dump(round(9.5, 0, PHP_ROUND_HALF_UP));
var_dump(round(9.5, 0, PHP_ROUND_HALF_DOWN));
var_dump(round(9.5, 0, PHP_ROUND_HALF_EVEN));
var_dump(round(9.5, 0, PHP_ROUND_HALF_ODD));
echo PHP_EOL;
echo "Mode d'arrondi avec 8.5" . PHP_EOL;
echo "Méthode d'arrondi avec 8.5" . PHP_EOL;
var_dump(round(8.5, 0, PHP_ROUND_HALF_UP));
var_dump(round(8.5, 0, PHP_ROUND_HALF_DOWN));
var_dump(round(8.5, 0, PHP_ROUND_HALF_EVEN));
Expand All @@ -265,13 +272,13 @@ var_dump(round(8.5, 0, PHP_ROUND_HALF_ODD));
&example.outputs;
<screen role="php">
<![CDATA[
Mode d'arrondi avec 9.5
Méthode d'arrondi avec 9.5
float(10)
float(9)
float(10)
float(9)
Mode d'arrondi avec 8.5
Méthode d'arrondi avec 8.5
float(9)
float(8)
float(8)
Expand Down Expand Up @@ -328,6 +335,61 @@ float(-1.5)
]]>
</screen>
</example>
<example>
<title>Exemple d'utilisation de <enumname>RoundingMode</enumname></title>
<programlisting role="php">
<![CDATA[
<?php
foreach (RoundingMode::cases() as $mode) {
foreach ([
8.5,
9.5,
-3.5,
] as $number) {
printf("%-17s: %+.17g -> %+.17g\n", $mode->name, $number, round($number, 0, $mode));
}
echo "\n";
}
?>
]]>
</programlisting>
&example.outputs;
<screen role="php">
<![CDATA[
HalfAwayFromZero : +8.5 -> +9
HalfAwayFromZero : +9.5 -> +10
HalfAwayFromZero : -3.5 -> -4
HalfTowardsZero : +8.5 -> +8
HalfTowardsZero : +9.5 -> +9
HalfTowardsZero : -3.5 -> -3
HalfEven : +8.5 -> +8
HalfEven : +9.5 -> +10
HalfEven : -3.5 -> -4
HalfOdd : +8.5 -> +9
HalfOdd : +9.5 -> +9
HalfOdd : -3.5 -> -3
TowardsZero : +8.5 -> +8
TowardsZero : +9.5 -> +9
TowardsZero : -3.5 -> -3
AwayFromZero : +8.5 -> +9
AwayFromZero : +9.5 -> +10
AwayFromZero : -3.5 -> -4
NegativeInfinity : +8.5 -> +8
NegativeInfinity : +9.5 -> +9
NegativeInfinity : -3.5 -> -4
PositiveInfinity : +8.5 -> +9
PositiveInfinity : +9.5 -> +10
PositiveInfinity : -3.5 -> -3
]]>
</screen>
</example>
</para>
</refsect1>

Expand Down