note 26489 added to language.operators.arithmetic
| From: | marsman at rack1 dot php dot net | Date: | Fri, 01 Nov 2002 08:57:55 +0000 |
| Subject: | note 26489 added to language.operators.arithmetic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-38864@lists.php.net to get a copy of this message | ||
Here the guy that reacted on 17-Jul-2002 04:14.
As I said the algebra of my solution is simple, but why would a division like 10/2 give something
like 4.99999? In this case my function can return this too when you execute something like
div(11,2). It gives the correct answer because it represents the integer 5. But what if you give it
to a function that expects an integer?
I tried to write code that returns something like 4.9999999 and test it but I didn't succeed...
what kind of division will result in this behaviour?
Even when I litterally use the number 4.9999... with enough nines, it will actually be 5 (even with
an integer typecast or floor). So I don't know how many nines would be in a result with the
behaviour described, but couldn't it be that (int) and floor just works fine?
example: floor(4.9999999999999999) results in 5 on my computer.
I still think my solution is the most beautiful because it only uses integers (or floats that
represent integers) for the results in between, but I can't think of an example in which the
other solutions don't work.
--
http://www.php.net/manual/en/language.operators.arithmetic.php
http://master.php.net/manage/user-notes.php?action=edit+26489
http://master.php.net/manage/user-notes.php?action=delete+26489
http://master.php.net/manage/user-notes.php?action=reject+26489