From 4e18a599b0d737086ecaed10f73751862324b30a Mon Sep 17 00:00:00 2001 From: jim winstead Date: Wed, 31 Oct 2001 02:02:20 +0000 Subject: [PATCH] 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 --- language/types.xml | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/language/types.xml b/language/types.xml index 007557d18f..17d8f3c92e 100644 --- a/language/types.xml +++ b/language/types.xml @@ -1,5 +1,5 @@ - + Types @@ -312,38 +312,26 @@ $a = 0x1A; # hexadecimal number (equivalent to 26 decimal) Integer overflow - If you specify a number beyond the bounds of the integer type, - it will be interpreted as a float instead. - - - In PHP there is also no such thing as integer division. - 1/2 yields the float - 0.5. + If you specify a number beyond the bounds of the integer + type, it will be interpreted as a float instead. Also, if + you perform an operation that results in a number beyond the bounds of + the integer type, a float will be returned + instead. + $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) - - - Furthermore, if some function or operator yields a number that is beyond - the boundaries of integer, it will also - be automatically converted to - float. - - $million = 1000000; $large_number = 50000 * $million; var_dump($large_number); @@ -360,10 +348,22 @@ var_dump($large_number); positive there is no problem. - This is solved in PHP 4.1.0 + This is solved in PHP 4.1.0. + + There is no integer division operator in PHP. + 1/2 yields the float + 0.5. + + +var_dump( 25/7 ); +// output: float(3.5714285714286) + + + @@ -373,8 +373,8 @@ var_dump($large_number); To explicitly convert a value to integer, use either the (int) or the (integer) 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 integer-argument. + will be automatically converted if an operator, function or + control structure requires a integer argument. See also type-juggling.