|
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<refentry xml:id="bcmath-number.sub" 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::sub</refname> |
| 5 | + <refpurpose>Subtracts 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::sub</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 | + Subtracts <parameter>num</parameter> from this object. |
| 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 value to subtract. |
| 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 subtraction 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 | + <!-- error --> |
| 45 | + <xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('bcmath-number.add')/db:refsect1[@role='errors'])" /> |
| 46 | + |
| 47 | + <refsect1 role="bc.autoscale"> |
| 48 | + <!-- auto scale title --> |
| 49 | + <xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('bcmath-number.add')/db:refsect1[@role='bc.autoscale']/db:title)" /> |
| 50 | + <simpara> |
| 51 | + When the <property>BcMath\Number::scale</property> of the result object is automatically set, |
| 52 | + the larger <property>BcMath\Number::scale</property> of the two numbers used for subtraction is used. |
| 53 | + </simpara> |
| 54 | + <!-- Auto scale example --> |
| 55 | + <xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('bcmath-number.add')/db:refsect1[@role='bc.autoscale']/db:simpara[2])" /> |
| 56 | + <!-- Regarding the handling of scale when calculating with string value --> |
| 57 | + <xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('bcmath-number.add')/db:refsect1[@role='bc.autoscale']/db:simpara[3])" /> |
| 58 | + </refsect1> |
| 59 | + |
| 60 | + <refsect1 role="examples"> |
| 61 | + &reftitle.examples; |
| 62 | + <example> |
| 63 | + <title><methodname>BcMath\Number::sub</methodname> example when <parameter>scale</parameter> is not specified</title> |
| 64 | + <programlisting role="php"> |
| 65 | +<![CDATA[ |
| 66 | +<?php |
| 67 | +$number = new BcMath\Number('1.234'); |
| 68 | +
|
| 69 | +$ret1 = $number->sub(new BcMath\Number('2.34567')); |
| 70 | +$ret2 = $number->sub('-3.456'); |
| 71 | +$ret3 = $number->sub(7); |
| 72 | +
|
| 73 | +var_dump($number, $ret1, $ret2, $ret3); |
| 74 | +?> |
| 75 | +]]> |
| 76 | + </programlisting> |
| 77 | + &example.outputs; |
| 78 | + <screen> |
| 79 | +<![CDATA[ |
| 80 | +object(BcMath\Number)#1 (2) { |
| 81 | + ["value"]=> |
| 82 | + string(5) "1.234" |
| 83 | + ["scale"]=> |
| 84 | + int(3) |
| 85 | +} |
| 86 | +object(BcMath\Number)#3 (2) { |
| 87 | + ["value"]=> |
| 88 | + string(8) "-1.11167" |
| 89 | + ["scale"]=> |
| 90 | + int(5) |
| 91 | +} |
| 92 | +object(BcMath\Number)#2 (2) { |
| 93 | + ["value"]=> |
| 94 | + string(5) "4.690" |
| 95 | + ["scale"]=> |
| 96 | + int(3) |
| 97 | +} |
| 98 | +object(BcMath\Number)#4 (2) { |
| 99 | + ["value"]=> |
| 100 | + string(6) "-5.766" |
| 101 | + ["scale"]=> |
| 102 | + int(3) |
| 103 | +} |
| 104 | +]]> |
| 105 | + </screen> |
| 106 | + </example> |
| 107 | + |
| 108 | + <example> |
| 109 | + <title><methodname>BcMath\Number::sub</methodname> example of explicitly specifying <parameter>scale</parameter></title> |
| 110 | + <programlisting role="php"> |
| 111 | +<![CDATA[ |
| 112 | +<?php |
| 113 | +$number = new BcMath\Number('1.234'); |
| 114 | +
|
| 115 | +$ret1 = $number->sub(new BcMath\Number('2.34567'), 1); |
| 116 | +$ret2 = $number->sub('-3.456', 10); |
| 117 | +$ret3 = $number->sub(7, 0); |
| 118 | +
|
| 119 | +var_dump($number, $ret1, $ret2, $ret3); |
| 120 | +?> |
| 121 | +]]> |
| 122 | + </programlisting> |
| 123 | + &example.outputs; |
| 124 | + <screen> |
| 125 | +<![CDATA[ |
| 126 | +object(BcMath\Number)#1 (2) { |
| 127 | + ["value"]=> |
| 128 | + string(5) "1.234" |
| 129 | + ["scale"]=> |
| 130 | + int(3) |
| 131 | +} |
| 132 | +object(BcMath\Number)#3 (2) { |
| 133 | + ["value"]=> |
| 134 | + string(4) "-1.1" |
| 135 | + ["scale"]=> |
| 136 | + int(1) |
| 137 | +} |
| 138 | +object(BcMath\Number)#2 (2) { |
| 139 | + ["value"]=> |
| 140 | + string(12) "4.6900000000" |
| 141 | + ["scale"]=> |
| 142 | + int(10) |
| 143 | +} |
| 144 | +object(BcMath\Number)#4 (2) { |
| 145 | + ["value"]=> |
| 146 | + string(2) "-5" |
| 147 | + ["scale"]=> |
| 148 | + int(0) |
| 149 | +} |
| 150 | +]]> |
| 151 | + </screen> |
| 152 | + </example> |
| 153 | + </refsect1> |
| 154 | + |
| 155 | + <refsect1 role="bc.operatoroverload"> |
| 156 | + <!-- operator overload title --> |
| 157 | + <xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('bcmath-number.add')/db:refsect1[@role='bc.operatoroverload']/db:title)" /> |
| 158 | + <simpara> |
| 159 | + <classname>BcMath\Number</classname> can perform subtraction using operators. The calculation with |
| 160 | + the operator behaves the same as when the method argument <parameter>scale</parameter> is &null;. |
| 161 | + </simpara> |
| 162 | + <example> |
| 163 | + <title>Example of subtraction using operators</title> |
| 164 | + <programlisting role="php"> |
| 165 | +<![CDATA[ |
| 166 | +<?php |
| 167 | +$number = new BcMath\Number('1.234'); |
| 168 | +
|
| 169 | +$ret1 = $number - new BcMath\Number('2.34567'); |
| 170 | +$ret2 = $number - '-3.45678'; |
| 171 | +$ret3 = $number - 7; |
| 172 | +
|
| 173 | +var_dump($number, $ret1, $ret2, $ret3); |
| 174 | +?> |
| 175 | +]]> |
| 176 | + </programlisting> |
| 177 | + &example.outputs; |
| 178 | + <screen> |
| 179 | +<![CDATA[ |
| 180 | +object(BcMath\Number)#1 (2) { |
| 181 | + ["value"]=> |
| 182 | + string(5) "1.234" |
| 183 | + ["scale"]=> |
| 184 | + int(3) |
| 185 | +} |
| 186 | +object(BcMath\Number)#3 (2) { |
| 187 | + ["value"]=> |
| 188 | + string(8) "-1.11167" |
| 189 | + ["scale"]=> |
| 190 | + int(5) |
| 191 | +} |
| 192 | +object(BcMath\Number)#2 (2) { |
| 193 | + ["value"]=> |
| 194 | + string(7) "4.69078" |
| 195 | + ["scale"]=> |
| 196 | + int(5) |
| 197 | +} |
| 198 | +object(BcMath\Number)#4 (2) { |
| 199 | + ["value"]=> |
| 200 | + string(6) "-5.766" |
| 201 | + ["scale"]=> |
| 202 | + int(3) |
| 203 | +} |
| 204 | +]]> |
| 205 | + </screen> |
| 206 | + </example> |
| 207 | + |
| 208 | + <example> |
| 209 | + <title>Examples of decrement and shorthand subtraction using operators</title> |
| 210 | + <programlisting role="php"> |
| 211 | +<![CDATA[ |
| 212 | +<?php |
| 213 | +$number = new BcMath\Number('1.234'); |
| 214 | +$num1 = $number; |
| 215 | +$num2 = $number; |
| 216 | +
|
| 217 | +$num1 -= new BcMath\Number('2.345'); |
| 218 | +$num2--; |
| 219 | +
|
| 220 | +var_dump($number, $num1, $num2); |
| 221 | +?> |
| 222 | +]]> |
| 223 | + </programlisting> |
| 224 | + &example.outputs; |
| 225 | + <screen> |
| 226 | +<![CDATA[ |
| 227 | +object(BcMath\Number)#1 (2) { |
| 228 | + ["value"]=> |
| 229 | + string(5) "1.234" |
| 230 | + ["scale"]=> |
| 231 | + int(3) |
| 232 | +} |
| 233 | +object(BcMath\Number)#3 (2) { |
| 234 | + ["value"]=> |
| 235 | + string(6) "-1.111" |
| 236 | + ["scale"]=> |
| 237 | + int(3) |
| 238 | +} |
| 239 | +object(BcMath\Number)#2 (2) { |
| 240 | + ["value"]=> |
| 241 | + string(5) "0.234" |
| 242 | + ["scale"]=> |
| 243 | + int(3) |
| 244 | +} |
| 245 | +]]> |
| 246 | + </screen> |
| 247 | + </example> |
| 248 | + </refsect1> |
| 249 | + |
| 250 | + <refsect1 role="seealso"> |
| 251 | + &reftitle.seealso; |
| 252 | + <simplelist> |
| 253 | + <member><function>bcsub</function></member> |
| 254 | + <member><methodname>BcMath\Number::add</methodname></member> |
| 255 | + </simplelist> |
| 256 | + </refsect1> |
| 257 | + |
| 258 | +</refentry> |
| 259 | +<!-- Keep this comment at the end of the file |
| 260 | +Local variables: |
| 261 | +mode: sgml |
| 262 | +sgml-omittag:t |
| 263 | +sgml-shorttag:t |
| 264 | +sgml-minimize-attributes:nil |
| 265 | +sgml-always-quote-attributes:t |
| 266 | +sgml-indent-step:1 |
| 267 | +sgml-indent-data:t |
| 268 | +indent-tabs-mode:nil |
| 269 | +sgml-parent-document:nil |
| 270 | +sgml-default-dtd-file:"~/.phpdoc/manual.ced" |
| 271 | +sgml-exposed-tags:nil |
| 272 | +sgml-local-catalogs:nil |
| 273 | +sgml-local-ecat-files:nil |
| 274 | +End: |
| 275 | +vim600: syn=xml fen fdm=syntax fdl=2 si |
| 276 | +vim: et tw=78 syn=sgml |
| 277 | +vi: ts=1 sw=1 |
| 278 | +--> |
0 commit comments