|
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<refentry xml:id="bcmath-number.mul" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 3 | + <refnamediv> |
| 4 | + <refname>BcMath\Number::mul</refname> |
| 5 | + <refpurpose>Multiplies an arbitrary precision number</refpurpose> |
| 6 | + </refnamediv> |
| 7 | + |
| 8 | + <refsect1 role="description"> |
| 9 | + &reftitle.description; |
| 10 | + <methodsynopsis role="BcMath\\Number"> |
| 11 | + <modifier>public</modifier> <type>BcMath\Number</type><methodname>BcMath\Number::mul</methodname> |
| 12 | + <methodparam><type class="union"><type>BcMath\Number</type><type>string</type><type>int</type></type><parameter>num</parameter></methodparam> |
| 13 | + <methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>scale</parameter><initializer>&null;</initializer></methodparam> |
| 14 | + </methodsynopsis> |
| 15 | + <simpara> |
| 16 | + Multiplies this object by <parameter>num</parameter>. |
| 17 | + </simpara> |
| 18 | + </refsect1> |
| 19 | + |
| 20 | + <refsect1 role="parameters"> |
| 21 | + &reftitle.parameters; |
| 22 | + <variablelist> |
| 23 | + <varlistentry> |
| 24 | + <term><parameter>num</parameter></term> |
| 25 | + <listitem> |
| 26 | + <simpara> |
| 27 | + The multiplier. |
| 28 | + </simpara> |
| 29 | + </listitem> |
| 30 | + </varlistentry> |
| 31 | + &bc.number.scale.description; |
| 32 | + </variablelist> |
| 33 | + </refsect1> |
| 34 | + |
| 35 | + <refsect1 role="returnvalues"> |
| 36 | + &reftitle.returnvalues; |
| 37 | + <simpara> |
| 38 | + Returns the result of multiplication as a new <classname>BcMath\Number</classname> object. |
| 39 | + </simpara> |
| 40 | + <!-- About the operator return value --> |
| 41 | + <xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('bcmath-number.add')/db:refsect1[@role='returnvalues']/db:simpara[2])" /> |
| 42 | + </refsect1> |
| 43 | + |
| 44 | + <refsect1 role="errors"> |
| 45 | + &reftitle.errors; |
| 46 | + <!-- ValueError cases of using the method --> |
| 47 | + <xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('bcmath-number.div')/db:refsect1[@role='errors']/db:para[1])" /> |
| 48 | + <!-- ValueError cases of using the operator --> |
| 49 | + <xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('bcmath-number.div')/db:refsect1[@role='errors']/db:para[2])" /> |
| 50 | + </refsect1> |
| 51 | + |
| 52 | + <refsect1 role="bc.autoscale"> |
| 53 | + <!-- auto scale title --> |
| 54 | + <xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('bcmath-number.add')/db:refsect1[@role='bc.autoscale']/db:title)" /> |
| 55 | + <simpara> |
| 56 | + When the <property>BcMath\Number::scale</property> of the result object is automatically set, |
| 57 | + the sum of the <property>BcMath\Number::scale</property>s of the two values used for multiplication is used. |
| 58 | + </simpara> |
| 59 | + <simpara> |
| 60 | + That is, if the <property>BcMath\Number::scale</property>s of two values are <literal>2</literal> |
| 61 | + and <literal>5</literal> respectively, the <property>BcMath\Number::scale</property> of the result |
| 62 | + will be <literal>7</literal>. |
| 63 | + </simpara> |
| 64 | + <!-- Regarding the handling of scale when calculating with string value --> |
| 65 | + <xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('bcmath-number.add')/db:refsect1[@role='bc.autoscale']/db:simpara[3])" /> |
| 66 | + </refsect1> |
| 67 | + |
| 68 | + <refsect1 role="examples"> |
| 69 | + &reftitle.examples; |
| 70 | + <example> |
| 71 | + <title><methodname>BcMath\Number::mul</methodname> example when <parameter>scale</parameter> is not specified</title> |
| 72 | + <programlisting role="php"> |
| 73 | +<![CDATA[ |
| 74 | +<?php |
| 75 | +$number = new BcMath\Number('1.234'); |
| 76 | +
|
| 77 | +$ret1 = $number->mul(new BcMath\Number('2.3456')); |
| 78 | +$ret2 = $number->mul('-3.4'); |
| 79 | +$ret3 = $number->mul(7); |
| 80 | +
|
| 81 | +var_dump($number, $ret1, $ret2, $ret3); |
| 82 | +?> |
| 83 | +]]> |
| 84 | + </programlisting> |
| 85 | + &example.outputs; |
| 86 | + <screen> |
| 87 | +<![CDATA[ |
| 88 | +object(BcMath\Number)#1 (2) { |
| 89 | + ["value"]=> |
| 90 | + string(5) "1.234" |
| 91 | + ["scale"]=> |
| 92 | + int(3) |
| 93 | +} |
| 94 | +object(BcMath\Number)#3 (2) { |
| 95 | + ["value"]=> |
| 96 | + string(9) "2.8944704" |
| 97 | + ["scale"]=> |
| 98 | + int(7) |
| 99 | +} |
| 100 | +object(BcMath\Number)#2 (2) { |
| 101 | + ["value"]=> |
| 102 | + string(7) "-4.1956" |
| 103 | + ["scale"]=> |
| 104 | + int(4) |
| 105 | +} |
| 106 | +object(BcMath\Number)#4 (2) { |
| 107 | + ["value"]=> |
| 108 | + string(5) "8.638" |
| 109 | + ["scale"]=> |
| 110 | + int(3) |
| 111 | +} |
| 112 | +]]> |
| 113 | + </screen> |
| 114 | + </example> |
| 115 | + |
| 116 | + <example> |
| 117 | + <title><methodname>BcMath\Number::mul</methodname> example of explicitly specifying <parameter>scale</parameter></title> |
| 118 | + <programlisting role="php"> |
| 119 | +<![CDATA[ |
| 120 | +<?php |
| 121 | +$number = new BcMath\Number('1.234'); |
| 122 | +
|
| 123 | +$ret1 = $number->mul(new BcMath\Number('2.3456'), 1); |
| 124 | +$ret2 = $number->mul('-3.4', 10); |
| 125 | +$ret3 = $number->mul(7, 0); |
| 126 | +
|
| 127 | +var_dump($number, $ret1, $ret2, $ret3); |
| 128 | +?> |
| 129 | +]]> |
| 130 | + </programlisting> |
| 131 | + &example.outputs; |
| 132 | + <screen> |
| 133 | +<![CDATA[ |
| 134 | +object(BcMath\Number)#1 (2) { |
| 135 | + ["value"]=> |
| 136 | + string(5) "1.234" |
| 137 | + ["scale"]=> |
| 138 | + int(3) |
| 139 | +} |
| 140 | +object(BcMath\Number)#3 (2) { |
| 141 | + ["value"]=> |
| 142 | + string(3) "2.8" |
| 143 | + ["scale"]=> |
| 144 | + int(1) |
| 145 | +} |
| 146 | +object(BcMath\Number)#2 (2) { |
| 147 | + ["value"]=> |
| 148 | + string(13) "-4.1956000000" |
| 149 | + ["scale"]=> |
| 150 | + int(10) |
| 151 | +} |
| 152 | +object(BcMath\Number)#4 (2) { |
| 153 | + ["value"]=> |
| 154 | + string(1) "8" |
| 155 | + ["scale"]=> |
| 156 | + int(0) |
| 157 | +} |
| 158 | +]]> |
| 159 | + </screen> |
| 160 | + </example> |
| 161 | + </refsect1> |
| 162 | + |
| 163 | + <refsect1 role="bc.operatoroverload"> |
| 164 | + <!-- operator overload title --> |
| 165 | + <xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('bcmath-number.add')/db:refsect1[@role='bc.operatoroverload']/db:title)" /> |
| 166 | + <simpara> |
| 167 | + <classname>BcMath\Number</classname> can perform multiplication using operators. The calculation with |
| 168 | + the operator behaves the same as when the method argument <parameter>scale</parameter> is &null;. |
| 169 | + </simpara> |
| 170 | + <example> |
| 171 | + <title>Example of multiplication using operators</title> |
| 172 | + <programlisting role="php"> |
| 173 | +<![CDATA[ |
| 174 | +<?php |
| 175 | +$number = new BcMath\Number('1.234'); |
| 176 | +
|
| 177 | +$ret1 = $number * new BcMath\Number('2.3456'); |
| 178 | +$ret2 = $number * '-3.4'; |
| 179 | +$ret3 = $number * 7; |
| 180 | +
|
| 181 | +var_dump($number, $ret1, $ret2, $ret3); |
| 182 | +?> |
| 183 | +]]> |
| 184 | + </programlisting> |
| 185 | + &example.outputs; |
| 186 | + <screen> |
| 187 | +<![CDATA[ |
| 188 | +object(BcMath\Number)#1 (2) { |
| 189 | + ["value"]=> |
| 190 | + string(5) "1.234" |
| 191 | + ["scale"]=> |
| 192 | + int(3) |
| 193 | +} |
| 194 | +object(BcMath\Number)#3 (2) { |
| 195 | + ["value"]=> |
| 196 | + string(9) "2.8944704" |
| 197 | + ["scale"]=> |
| 198 | + int(7) |
| 199 | +} |
| 200 | +object(BcMath\Number)#2 (2) { |
| 201 | + ["value"]=> |
| 202 | + string(7) "-4.1956" |
| 203 | + ["scale"]=> |
| 204 | + int(4) |
| 205 | +} |
| 206 | +object(BcMath\Number)#4 (2) { |
| 207 | + ["value"]=> |
| 208 | + string(5) "8.638" |
| 209 | + ["scale"]=> |
| 210 | + int(3) |
| 211 | +} |
| 212 | +]]> |
| 213 | + </screen> |
| 214 | + </example> |
| 215 | + |
| 216 | + <example> |
| 217 | + <title>Examples of shorthand multiplication using operators</title> |
| 218 | + <programlisting role="php"> |
| 219 | +<![CDATA[ |
| 220 | +<?php |
| 221 | +$number = new BcMath\Number('1.234'); |
| 222 | +$num1 = $number; |
| 223 | +
|
| 224 | +$num1 *= new BcMath\Number('2.345'); |
| 225 | +
|
| 226 | +var_dump($number, $num1); |
| 227 | +?> |
| 228 | +]]> |
| 229 | + </programlisting> |
| 230 | + &example.outputs; |
| 231 | + <screen> |
| 232 | +<![CDATA[ |
| 233 | +object(BcMath\Number)#1 (2) { |
| 234 | + ["value"]=> |
| 235 | + string(5) "1.234" |
| 236 | + ["scale"]=> |
| 237 | + int(3) |
| 238 | +} |
| 239 | +object(BcMath\Number)#3 (2) { |
| 240 | + ["value"]=> |
| 241 | + string(8) "2.893730" |
| 242 | + ["scale"]=> |
| 243 | + int(6) |
| 244 | +} |
| 245 | +]]> |
| 246 | + </screen> |
| 247 | + </example> |
| 248 | + </refsect1> |
| 249 | + |
| 250 | + <refsect1 role="seealso"> |
| 251 | + &reftitle.seealso; |
| 252 | + <simplelist> |
| 253 | + <member><function>bcmul</function></member> |
| 254 | + <member><methodname>BcMath\Number::div</methodname></member> |
| 255 | + <member><methodname>BcMath\Number::pow</methodname></member> |
| 256 | + <member><methodname>BcMath\Number::powmod</methodname></member> |
| 257 | + </simplelist> |
| 258 | + </refsect1> |
| 259 | + |
| 260 | +</refentry> |
| 261 | +<!-- Keep this comment at the end of the file |
| 262 | +Local variables: |
| 263 | +mode: sgml |
| 264 | +sgml-omittag:t |
| 265 | +sgml-shorttag:t |
| 266 | +sgml-minimize-attributes:nil |
| 267 | +sgml-always-quote-attributes:t |
| 268 | +sgml-indent-step:1 |
| 269 | +sgml-indent-data:t |
| 270 | +indent-tabs-mode:nil |
| 271 | +sgml-parent-document:nil |
| 272 | +sgml-default-dtd-file:"~/.phpdoc/manual.ced" |
| 273 | +sgml-exposed-tags:nil |
| 274 | +sgml-local-catalogs:nil |
| 275 | +sgml-local-ecat-files:nil |
| 276 | +End: |
| 277 | +vim600: syn=xml fen fdm=syntax fdl=2 si |
| 278 | +vim: et tw=78 syn=sgml |
| 279 | +vi: ts=1 sw=1 |
| 280 | +--> |
0 commit comments