-
Notifications
You must be signed in to change notification settings - Fork 164
Document clamp function #2237
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
Open
kylekatarnls
wants to merge
4
commits into
php:master
Choose a base branch
from
kylekatarnls:clamp-function
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+157
−0
Open
Document clamp function #2237
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- EN-Revision: 761d72245071f89a626903c9bcdc6aaff1252d54 Maintainer: yannick Status: ready --> | ||
| <!-- Reviewed: no --> | ||
| <refentry xml:id="function.clamp" xmlns="http://docbook.org/ns/docbook"> | ||
| <refnamediv> | ||
| <refname>clamp</refname> | ||
| <refpurpose>Retourne la valeur d'entrée si elle est comprise entre 2 bornes, sinon retourne la borne la plus proche</refpurpose> | ||
| </refnamediv> | ||
| <refsect1 role="description"> | ||
| &reftitle.description; | ||
| <methodsynopsis> | ||
| <type>mixed</type><methodname>clamp</methodname> | ||
| <methodparam><type>mixed</type><parameter>value</parameter></methodparam> | ||
| <methodparam><type>mixed</type><parameter>min</parameter></methodparam> | ||
| <methodparam><type>mixed</type><parameter>max</parameter></methodparam> | ||
| </methodsynopsis> | ||
| <para> | ||
| Retourne la valeur d'entrée si elle est comprise entre <parameter>min</parameter> et <parameter>max</parameter>. | ||
| Si elle est inférieur à <parameter>min</parameter>, retourne <parameter>min</parameter>. | ||
kylekatarnls marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Sinon retourne <parameter>max</parameter>. | ||
| </para> | ||
| <note> | ||
| <para> | ||
| Les valeurs de différents types seront comparées en utilisant | ||
| les <link linkend="language.operators.comparison">règles de | ||
| comparaison standard</link>. Actuellement, une chaîne non numérique | ||
| sera comparée à un &integer;, comme s'il s'agissait de la valeur | ||
| <literal>0</literal>, mais plusieurs &string; non-numérique seront comparées de façon | ||
| alphanumérique. La valeur actuelle retournée sera du même type que | ||
| l'original et aucune conversion de type ne sera appliquée. | ||
| </para> | ||
| </note> | ||
| <caution> | ||
| <simpara> | ||
| Soyez prudent lorsque vous passez des arguments avec des types différents, | ||
| car <function>clamp</function> peut produire des résultats imprévisibles. | ||
| </simpara> | ||
| </caution> | ||
| </refsect1> | ||
| <refsect1 role="parameters"> | ||
| &reftitle.parameters; | ||
| <para> | ||
| <variablelist> | ||
| <varlistentry> | ||
| <term><parameter>value</parameter></term> | ||
| <listitem> | ||
| <para> | ||
| Toute valeur <link linkend="language.operators.comparison">comparable</link> à resserrer entre | ||
| <parameter>min</parameter> et <parameter>max</parameter>. | ||
| </para> | ||
| </listitem> | ||
| </varlistentry> | ||
| <varlistentry> | ||
| <term><parameter>min</parameter></term> | ||
| <listitem> | ||
| <para> | ||
| Une valeur minimum <link linkend="language.operators.comparison">comparable</link> | ||
| à laquelle contraindre <parameter>value</parameter>. | ||
| </para> | ||
| </listitem> | ||
| </varlistentry> | ||
| <varlistentry> | ||
| <term><parameter>max</parameter></term> | ||
| <listitem> | ||
| <para> | ||
| Une valeur maximum <link linkend="language.operators.comparison">comparable</link> | ||
| à laquelle contraindre <parameter>value</parameter>. | ||
| </para> | ||
| </listitem> | ||
| </varlistentry> | ||
| </variablelist> | ||
| </para> | ||
| </refsect1> | ||
| <refsect1 role="returnvalues"> | ||
| &reftitle.returnvalues; | ||
| <para> | ||
| La fonction <function>clamp</function> retourne le paramètre <parameter>value</parameter> | ||
| s'il est considéré comme "entre" <parameter>min</parameter> et <parameter>max</parameter> | ||
| suivant la comparaison standard. | ||
| Si plusieurs valeurs de types différents sont évaluées comme étant égales | ||
| (i.e. <literal>0</literal> et <literal>'abc'</literal>), la première fournie | ||
| à la fonction sera retournée. | ||
| </para> | ||
| <para> | ||
| Si <parameter>value</parameter> est <constant>NAN</constant>, alors la valeur de retour | ||
| est également <constant>NAN</constant>. | ||
| </para> | ||
| </refsect1> | ||
|
|
||
| <refsect1 role="errors"> | ||
| &reftitle.errors; | ||
| <para> | ||
| Si <parameter>min</parameter> est supérieur à <parameter>max</parameter>, | ||
| la fonction <function>clamp</function> lance une <classname>ValueError</classname>. | ||
| </para> | ||
| <para> | ||
| Si <parameter>min</parameter> ou <parameter>max</parameter> est <constant>NAN</constant>, | ||
| la fonction <function>clamp</function> lance une <classname>ValueError</classname>. | ||
| </para> | ||
| </refsect1> | ||
|
|
||
| <refsect1 role="examples"> | ||
| &reftitle.examples; | ||
| <para> | ||
| <example> | ||
| <title>Exemple avec <function>clamp</function></title> | ||
| <programlisting role="php"> | ||
| <![CDATA[ | ||
| <?php | ||
| echo clamp(-5, min: 0, max: 100), PHP_EOL; // 0 | ||
| echo clamp(55, min: 0, max: 100), PHP_EOL; // 55 | ||
| echo clamp(103, min: 0, max: 100), PHP_EOL; // 100 | ||
|
|
||
| echo clamp("J", min: "A", max: "F"), PHP_EOL; // "F" | ||
|
|
||
| clamp( | ||
| new \DateTimeImmutable('2025-08-01'), | ||
| min: new \DateTimeImmutable('2025-08-15'), | ||
| max: new \DateTimeImmutable('2025-09-15'), | ||
| )->format('Y-m-d'), PHP_EOL; // 2025-08-15 | ||
| ?> | ||
| ]]> | ||
| </programlisting> | ||
| </example> | ||
| </para> | ||
| </refsect1> | ||
|
|
||
| <refsect1 role="seealso"> | ||
| &reftitle.seealso; | ||
| <para> | ||
| <simplelist> | ||
| <member><function>min</function></member> | ||
| <member><function>max</function></member> | ||
| </simplelist> | ||
| </para> | ||
| </refsect1> | ||
| </refentry> | ||
| <!-- 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 | ||
| indent-tabs-mode:nil | ||
| sgml-parent-document:nil | ||
| sgml-default-dtd-file:"~/.phpdoc/manual.ced" | ||
| sgml-exposed-tags:nil | ||
| sgml-local-catalogs:nil | ||
| sgml-local-ecat-files:nil | ||
| End: | ||
| vim600: syn=xml fen fdm=syntax fdl=2 si | ||
| vim: et tw=78 syn=sgml | ||
| vi: ts=1 sw=1 | ||
| --> | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.