|
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<refentry xml:id="bcmath-number.sqrt" 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::sqrt</refname> |
| 5 | + <refpurpose>Gets the square root of 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::sqrt</methodname> |
| 12 | + <methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>scale</parameter><initializer>&null;</initializer></methodparam> |
| 13 | + </methodsynopsis> |
| 14 | + <simpara> |
| 15 | + Return the square root of this object. |
| 16 | + </simpara> |
| 17 | + </refsect1> |
| 18 | + |
| 19 | + <refsect1 role="parameters"> |
| 20 | + &reftitle.parameters; |
| 21 | + <variablelist> |
| 22 | + &bc.number.scale.description; |
| 23 | + </variablelist> |
| 24 | + </refsect1> |
| 25 | + |
| 26 | + <refsect1 role="returnvalues"> |
| 27 | + &reftitle.returnvalues; |
| 28 | + <simpara> |
| 29 | + Returns the square root as a new <classname>BcMath\Number</classname> object. |
| 30 | + </simpara> |
| 31 | + </refsect1> |
| 32 | + |
| 33 | + <refsect1 role="errors"> |
| 34 | + &reftitle.errors; |
| 35 | + <para> |
| 36 | + This method throws a <exceptionname>ValueError</exceptionname> in the following cases: |
| 37 | + <simplelist> |
| 38 | + <member>This object is a negative value</member> |
| 39 | + <member><parameter>scale</parameter> is outside the valid range</member> |
| 40 | + <member><property>BcMath\Number::scale</property> of the result object is outside the valid range</member> |
| 41 | + </simplelist> |
| 42 | + </para> |
| 43 | + </refsect1> |
| 44 | + |
| 45 | + <refsect1 role="bc.autoscale"> |
| 46 | + <!-- auto scale title --> |
| 47 | + <xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('bcmath-number.add')/db:refsect1[@role='bc.autoscale']/db:title)" /> |
| 48 | + <simpara> |
| 49 | + When the <property>BcMath\Number::scale</property> of the result object is automatically set, |
| 50 | + the <property>BcMath\Number::scale</property> of this object is used. However, in cases such |
| 51 | + as indivisible division, the <property>BcMath\Number::scale</property> of the result is expanded. |
| 52 | + Expansion is done only as needed, up to a maximum of +<literal>10</literal>. |
| 53 | + </simpara> |
| 54 | + <simpara> |
| 55 | + That is, if the <property>BcMath\Number::scale</property> of this object is <literal>5</literal>, |
| 56 | + the <property>BcMath\Number::scale</property> of the result is between <literal>5</literal> and |
| 57 | + <literal>15</literal>. |
| 58 | + </simpara> |
| 59 | + <simpara> |
| 60 | + This behavior is the same as <methodname>BcMath\Number::div</methodname>, so please see that for details. |
| 61 | + </simpara> |
| 62 | + </refsect1> |
| 63 | + |
| 64 | + <refsect1 role="examples"> |
| 65 | + &reftitle.examples; |
| 66 | + <example> |
| 67 | + <title><methodname>BcMath\Number::sqrt</methodname> example</title> |
| 68 | + <programlisting role="php"> |
| 69 | +<![CDATA[ |
| 70 | +<?php |
| 71 | +var_dump( |
| 72 | + new BcMath\Number('2')->sqrt(), |
| 73 | + new BcMath\Number('2')->sqrt(3), |
| 74 | + new BcMath\Number('4')->sqrt(), |
| 75 | + new BcMath\Number('4')->sqrt(3), |
| 76 | +); |
| 77 | +?> |
| 78 | +]]> |
| 79 | + </programlisting> |
| 80 | + &example.outputs; |
| 81 | + <screen> |
| 82 | +<![CDATA[ |
| 83 | +object(BcMath\Number)#2 (2) { |
| 84 | + ["value"]=> |
| 85 | + string(12) "1.4142135623" |
| 86 | + ["scale"]=> |
| 87 | + int(10) |
| 88 | +} |
| 89 | +object(BcMath\Number)#3 (2) { |
| 90 | + ["value"]=> |
| 91 | + string(5) "1.414" |
| 92 | + ["scale"]=> |
| 93 | + int(3) |
| 94 | +} |
| 95 | +object(BcMath\Number)#4 (2) { |
| 96 | + ["value"]=> |
| 97 | + string(1) "2" |
| 98 | + ["scale"]=> |
| 99 | + int(0) |
| 100 | +} |
| 101 | +object(BcMath\Number)#5 (2) { |
| 102 | + ["value"]=> |
| 103 | + string(5) "2.000" |
| 104 | + ["scale"]=> |
| 105 | + int(3) |
| 106 | +} |
| 107 | +]]> |
| 108 | + </screen> |
| 109 | + </example> |
| 110 | + </refsect1> |
| 111 | + |
| 112 | + <refsect1 role="seealso"> |
| 113 | + &reftitle.seealso; |
| 114 | + <simplelist> |
| 115 | + <member><function>bcsqrt</function></member> |
| 116 | + <member><methodname>BcMath\Number::div</methodname></member> |
| 117 | + <member><methodname>BcMath\Number::pow</methodname></member> |
| 118 | + </simplelist> |
| 119 | + </refsect1> |
| 120 | + |
| 121 | +</refentry> |
| 122 | +<!-- Keep this comment at the end of the file |
| 123 | +Local variables: |
| 124 | +mode: sgml |
| 125 | +sgml-omittag:t |
| 126 | +sgml-shorttag:t |
| 127 | +sgml-minimize-attributes:nil |
| 128 | +sgml-always-quote-attributes:t |
| 129 | +sgml-indent-step:1 |
| 130 | +sgml-indent-data:t |
| 131 | +indent-tabs-mode:nil |
| 132 | +sgml-parent-document:nil |
| 133 | +sgml-default-dtd-file:"~/.phpdoc/manual.ced" |
| 134 | +sgml-exposed-tags:nil |
| 135 | +sgml-local-catalogs:nil |
| 136 | +sgml-local-ecat-files:nil |
| 137 | +End: |
| 138 | +vim600: syn=xml fen fdm=syntax fdl=2 si |
| 139 | +vim: et tw=78 syn=sgml |
| 140 | +vi: ts=1 sw=1 |
| 141 | +--> |
0 commit comments