note 69635 added to language.operators.arithmetic

From: Date: Wed, 13 Sep 2006 14:01:56 +0000
Subject: note 69635 added to language.operators.arithmetic
Groups: php.notes 
Request: Send a blank email to php-notes+get-117102@lists.php.net to get a copy of this message
Quote from TChan's post: "...But if you're dealing with ints anyway, (a-a%b)/b has no function calls and returns an int, while floor() always returns a float." It *explicitly* says in the documentation that the division operator *always* returns a float value *regardless* of the types of the operands. While you may get the "integer part" of the number that way you will technically not get an integer. PHP may not be too strongly typed for the most part, but it's important to make the distinction. "... if the 'fractional part' of $a/$b is close to 1, then it can round up, and floor($a/$b) will be larger than it should be." Actually I think you meant *smaller*, not larger... the reason floor($a/$b) isn't absolutely equatable with the integer division of $a and $b is explained mainly at http://us3.php.net/float . By the look of things, any number with a loss of precision will be truncated instead of rounded. This would at least make sense in the big picture since truncation is more consistant than rounding. ---- Server IP: 66.163.161.117 Probable Submitter: 12.47.22.190 ---- Manual Page -- http://www.php.net/manual/en/language.operators.arithmetic.php Edit -- https://master.php.net/note/edit/69635 Del: integrated -- https://master.php.net/note/delete/69635/integrated Del: useless -- https://master.php.net/note/delete/69635/useless Del: bad code -- https://master.php.net/note/delete/69635/bad+code Del: spam -- https://master.php.net/note/delete/69635/spam Del: non-english -- https://master.php.net/note/delete/69635/non-english Del: in docs -- https://master.php.net/note/delete/69635/in+docs Del: other reasons-- https://master.php.net/note/delete/69635 Reject -- https://master.php.net/note/reject/69635 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#117102) next »