mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
put overflow examples together, and division example on its own. fix typo and another dash.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@61232 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
df70f43a81
commit
4e18a599b0
1 changed files with 23 additions and 23 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.57 $ -->
|
||||
<!-- $Revision: 1.58 $ -->
|
||||
<chapter id="language.types">
|
||||
<title>Types</title>
|
||||
|
||||
|
@ -312,38 +312,26 @@ $a = 0x1A; # hexadecimal number (equivalent to 26 decimal)
|
|||
<sect2 id="language.types.integer.overflow">
|
||||
<title>Integer overflow</title>
|
||||
<para>
|
||||
If you specify a number beyond the bounds of the <type>integer</type> type,
|
||||
it will be interpreted as a <type>float</type> instead.
|
||||
</para>
|
||||
<para>
|
||||
In PHP there is also no such thing as integer division.
|
||||
<literal>1/2</literal> yields the <type>float</type>
|
||||
<literal>0.5</literal>. <!-- See ??? for more information. (with the
|
||||
operators, or with type-jug) -->
|
||||
If you specify a number beyond the bounds of the <type>integer</type>
|
||||
type, it will be interpreted as a <type>float</type> instead. Also, if
|
||||
you perform an operation that results in a number beyond the bounds of
|
||||
the <type>integer</type> type, a <type>float</type> will be returned
|
||||
instead.
|
||||
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
$large_number = 2147483647;
|
||||
var_dump($large_number);
|
||||
// output: int(2147483647)
|
||||
|
||||
$large_number = 2147483648;
|
||||
var_dump($large_number);
|
||||
// output: float(2147483648)
|
||||
|
||||
// this goes also for hexadecimal specified integers:
|
||||
|
||||
var_dump( 0x80000000 );
|
||||
// output: float(2147483648)
|
||||
|
||||
var_dump( 25/7 );
|
||||
// output: float(3.5714285714286)
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
Furthermore, if some function or operator yields a number that is beyond
|
||||
the boundaries of <type>integer</type>, it will also
|
||||
be automatically converted to
|
||||
<type>float</type>.
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
$million = 1000000;
|
||||
$large_number = 50000 * $million;
|
||||
var_dump($large_number);
|
||||
|
@ -360,10 +348,22 @@ var_dump($large_number);
|
|||
positive there is no problem.
|
||||
</simpara>
|
||||
<simpara>
|
||||
This is solved in PHP 4.1.0
|
||||
This is solved in PHP 4.1.0.
|
||||
</simpara>
|
||||
</warning>
|
||||
</para>
|
||||
<para>
|
||||
There is no integer division operator in PHP.
|
||||
<literal>1/2</literal> yields the <type>float</type>
|
||||
<literal>0.5</literal>. <!-- See ??? for more information. (with the
|
||||
operators, or with type-jug) -->
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
var_dump( 25/7 );
|
||||
// output: float(3.5714285714286)
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
</para>
|
||||
</sect2>
|
||||
|
||||
|
||||
|
@ -373,8 +373,8 @@ var_dump($large_number);
|
|||
To explicitly convert a value to <type>integer</type>, use either
|
||||
the <literal>(int)</literal> or the <literal>(integer)</literal> cast.
|
||||
However, in most cases you do not need to use the cast, since a value
|
||||
will be autmatically converted if an operator, function or
|
||||
control structure requires a <type>integer</type>-argument.
|
||||
will be automatically converted if an operator, function or
|
||||
control structure requires a <type>integer</type> argument.
|
||||
</simpara>
|
||||
<simpara>
|
||||
See also <link linkend="language.types.type-juggling">type-juggling</link>.
|
||||
|
|
Loading…
Reference in a new issue