source/text/sbasic/shared/03070600.xhp | 55 +++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 19 deletions(-)
New commits: commit 215eec55562243262f2549e2071d8298a659057d Author: Rafael Lima <rafael.palma.l...@gmail.com> AuthorDate: Thu Apr 1 21:24:21 2021 +0200 Commit: Olivier Hallot <olivier.hal...@libreoffice.org> CommitDate: Mon Apr 5 16:03:34 2021 +0200 tdf#141200 Improve Basic MOD operator help page The help page needs to clarify that non-integer operands are rounded to integers before the MOD operation. Change-Id: I96a13cd9381dea3f79606f4f8bf26af54763e76d Reviewed-on: https://gerrit.libreoffice.org/c/help/+/113475 Tested-by: Jenkins Reviewed-by: Olivier Hallot <olivier.hal...@libreoffice.org> diff --git a/source/text/sbasic/shared/03070600.xhp b/source/text/sbasic/shared/03070600.xhp index 42516188e..ed510a94c 100644 --- a/source/text/sbasic/shared/03070600.xhp +++ b/source/text/sbasic/shared/03070600.xhp @@ -27,40 +27,57 @@ <body> - <section id="mod"> <bookmark xml-lang="en-US" branch="index" id="bm_id3150669"> <bookmark_value>MOD operator (mathematical)</bookmark_value> </bookmark> - -<paragraph id="hd_id3150669" role="heading" level="1" xml-lang="en-US"><link href="text/sbasic/shared/03070600.xhp" name="Mod Operator">Mod Operator</link></paragraph> -<paragraph id="par_id3148686" role="paragraph" xml-lang="en-US">Returns the integer remainder of a division.</paragraph> +<h1 id="hd_id3150669"><variable id="MOD_h1"><link href="text/sbasic/shared/03070600.xhp" name="Mod Operator">Mod Operator</link></variable></h1> +<paragraph id="par_id3148686" role="paragraph" xml-lang="en-US">The <literal>MOD</literal> operator takes in two numeric expressions and returns the remainder of the division.</paragraph> </section> +<paragraph id="par_id3148004" role="paragraph" xml-lang="en-US">For example, the result of <literal>21 MOD 6</literal> is <literal>3</literal> because after dividing 21 by 6, the remainder of the division is 3.</paragraph> +<paragraph role="paragraph" id="par_id111617300964049">If the <literal>MOD</literal> operation involves non-integer values, both operands are rounded to the nearest integer values. Hence, the value returned by a <literal>MOD</literal> operation will always be an integer number.</paragraph> +<paragraph role="paragraph" id="par_id561617302820104">For example, the expression <literal>16.4 MOD 5.9</literal> is evaluated as follows:</paragraph> +<list type="ordered"> + <listitem> + <paragraph id="par_id151617302878527" role="listitem">The value 16.4 is rounded to 16.</paragraph> + </listitem> + <listitem> + <paragraph id="par_id351617303087259" role="listitem">The value 5.9 is rounded to 6.</paragraph> + </listitem> + <listitem> + <paragraph id="par_id91617303114774" role="listitem">The operation <literal>16 MOD 6</literal> returns 4, which is the remainder after dividing 16 by 6.</paragraph> + </listitem> +</list> +<note id="par_id921617302349290">Beware that Basic's <literal>MOD</literal> operator and Calc's <link href="text/scalc/01/04060106.xhp#bm_id3158247" name="MOD Function">MOD Function</link> behave differently. In Calc, both operands can be decimal values and they're not rounded before division, thus the resulting remainder may be a decimal value.</note> -<paragraph id="hd_id3146795" role="heading" level="2" xml-lang="en-US">Syntax:</paragraph> +<embed href="text/sbasic/shared/00000003.xhp#functsyntax"/> <bascode> <paragraph id="par_id3147560" role="bascode" xml-lang="en-US">Result = Expression1 MOD Expression2</paragraph> </bascode> -<paragraph id="hd_id3149657" role="heading" level="2" xml-lang="en-US">Return value:</paragraph> +<embed href="text/sbasic/shared/00000003.xhp#functvalue"/> <paragraph id="par_id3153380" role="paragraph" xml-lang="en-US">Integer</paragraph> -<paragraph id="hd_id3154365" role="heading" level="2" xml-lang="en-US">Parameters:</paragraph> -<paragraph id="par_id3145172" role="paragraph" xml-lang="en-US"> <emph>Result:</emph> Any numeric variable that contains the result of the MOD operation.</paragraph> -<paragraph id="par_id3151042" role="paragraph" xml-lang="en-US"> <emph>Expression1, Expression2:</emph> Any numeric expressions that you want to divide.</paragraph> +<embed href="text/sbasic/shared/00000003.xhp#functparameters"/> +<paragraph id="par_id3145172" role="paragraph" xml-lang="en-US"> <emph>Result:</emph> Any numeric variable that contains the result of the <literal>MOD</literal> operation.</paragraph> +<paragraph id="par_id3151042" role="paragraph" xml-lang="en-US"> <emph>Expression1, Expression2:</emph> Any numeric expressions for which you want to calculate the remainder after the division of <literal>Expression1</literal> by <literal>Expression2</literal>.</paragraph> -<paragraph id="hd_id3147287" role="heading" level="2" xml-lang="en-US">Example:</paragraph> +<embed href="text/sbasic/shared/00000003.xhp#functexample"/> <bascode> -<paragraph id="par_idm1340853360" role="bascode" localize="false" xml-lang="en-US">Sub ExampleMod</paragraph> -<paragraph id="par_id3161832" role="bascode" xml-lang="en-US"> Print 10 Mod 2.5 ' returns 0</paragraph> -<paragraph id="par_id3146922" role="bascode" xml-lang="en-US"> Print 10 / 2.5 ' returns 4</paragraph> -<paragraph id="par_id3145273" role="bascode" xml-lang="en-US"> Print 10 Mod 5 ' returns 0</paragraph> -<paragraph id="par_id3150011" role="bascode" xml-lang="en-US"> Print 10 / 5 ' returns 2</paragraph> -<paragraph id="par_id3149483" role="bascode" xml-lang="en-US"> Print 5 Mod 10 ' returns 5</paragraph> -<paragraph id="par_id3151114" role="bascode" xml-lang="en-US"> Print 5 / 10 ' returns 0.5</paragraph> -<paragraph id="par_idm1340841712" role="bascode" localize="false" xml-lang="en-US">End Sub</paragraph> +<paragraph id="par_idm1340853360" role="bascode" localize="false">Sub ExampleMod</paragraph> +<paragraph id="par_id3161832" role="bascode" localize="false"> Dim a As Double, b as Double</paragraph> +<paragraph id="par_id3150011" role="bascode" localize="false"> a = 10 : b = 4</paragraph> +<paragraph id="par_id3149483" role="bascode"> Print a Mod b 'Returns 2</paragraph> +<paragraph id="par_id3151114" role="bascode" localize="false"> a = 18 : b = 3.2</paragraph> +<paragraph id="par_id31494778" role="bascode"> Print a Mod b 'Returns 0</paragraph> +<paragraph id="par_id3146922" role="bascode" localize="false"> a = 16.4 : b = 5.9</paragraph> +<paragraph id="par_id3145273" role="bascode"> Print a Mod b 'Returns 4</paragraph> +<paragraph id="par_idm1340841712" role="bascode" localize="false">End Sub</paragraph> </bascode> -</body> +<section id="relatedtopics"> + <paragraph role="paragraph" id="par_id771617305550403"><link href="text/scalc/01/04060106.xhp#bm_id3158247" name="Calc MOD Function">MOD Function</link></paragraph> +</section> +</body> </helpdocument> _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits